Skip to content

Commit

Permalink
Add additional scan guards
Browse files Browse the repository at this point in the history
  • Loading branch information
chriso committed Nov 8, 2023
1 parent e13c0c0 commit ea7678c
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions types/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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
Expand All @@ -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
}
Expand All @@ -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:
Expand Down

0 comments on commit ea7678c

Please sign in to comment.