From ea7678c809c5d61b5b784ab4b2a2edea24b6390d Mon Sep 17 00:00:00 2001 From: Chris O'Hara Date: Wed, 8 Nov 2023 12:05:31 +1000 Subject: [PATCH] Add additional scan guards --- types/scan.go | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/types/scan.go b/types/scan.go index 1c4a25c..7db0353 100644 --- a/types/scan.go +++ b/types/scan.go @@ -249,6 +249,10 @@ func scan(s *Serializer, t reflect.Type, p unsafe.Pointer) { } s.scanptrs[r] = struct{}{} + if r.IsNil() { + return + } + switch t.Kind() { case reflect.Invalid: panic("handling invalid reflect.Type") @@ -262,6 +266,9 @@ func scan(s *Serializer, t reflect.Type, p unsafe.Pointer) { } case reflect.Slice: sr := r.Elem() + if sr.IsNil() { + return + } ep := sr.UnsafePointer() if ep == nil { return @@ -278,9 +285,15 @@ func scan(s *Serializer, t reflect.Type, p unsafe.Pointer) { scan(s, et, ep) } case reflect.Interface: - et := reflect.TypeOf(r.Elem().Interface()) + if r.Elem().IsNil() { + return + } + it := r.Elem().Interface() + if it == nil { + return + } + et := reflect.TypeOf(it) eptr := (*iface)(p).ptr - if eptr == nil { return } @@ -300,6 +313,9 @@ func scan(s *Serializer, t reflect.Type, p unsafe.Pointer) { scan(s, ft, fp) } case reflect.Pointer: + if r.Elem().IsNil() { + return + } ep := r.Elem().UnsafePointer() scan(s, t.Elem(), ep) case reflect.String: