From a9fe6f30fcb8a4b4b619d98edc00bae11a5ecfdc Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Wed, 23 Oct 2024 22:22:41 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Protect=20from=20nil=20pointers?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- convids/methods.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/convids/methods.go b/convids/methods.go index 71689a9..c79c873 100644 --- a/convids/methods.go +++ b/convids/methods.go @@ -10,11 +10,15 @@ import ( ) var ErrNoName = errors.New("missing name") +var ErrNilPointer = errors.New("nil pointer") var animePattern = `^\[.+\] ` var animeRegexp = regexp.MustCompile(animePattern) func (s *Show) Match(path string) (bool, error) { + if s == nil { + return false, ErrNilPointer + } if s.Pattern != "" { return s.matchRegexp(path) } @@ -50,12 +54,15 @@ func (s *Show) matchRegexp(path string) (f bool, err error) { } func (ss *Shows) All() iter.Seq[*Show] { + if ss == nil { + return func(func(*Show) bool) {} + } return slices.Values(*ss) } func (d *Data) AllShows(silent bool) iter.Seq[*Show] { return func(yield func(*Show) bool) { - if d.Config == nil { + if d == nil || d.Config == nil { return } for _, show := range d.Config.Shows {