From 29ff95e43e00bc945770e61bb35436390464165f Mon Sep 17 00:00:00 2001 From: Steve Date: Sat, 12 Nov 2022 12:55:14 -0500 Subject: [PATCH] oob check --- reddit.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/reddit.go b/reddit.go index 7741c2b..2cb5938 100644 --- a/reddit.go +++ b/reddit.go @@ -3,6 +3,7 @@ package main import ( "crypto/tls" "encoding/json" + "errors" "fmt" "io/ioutil" "net/http" @@ -47,6 +48,9 @@ func getNewestPost(subreddit string) (post, error) { if err != nil { return post{}, err } + if len(resp.Data.Children) < 1 { + return post{}, errors.New("bad data from reddit") + } numS := re.FindStringSubmatch(resp.Data.Children[0].Data.Title)[0] num, err := strconv.Atoi(numS) if err != nil || numS == "" {