Skip to content

Commit 6c2ca30

Browse files
committed
Check value validity before use value methods.
1 parent b7c48f5 commit 6c2ca30

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

bson/bsoncodec/struct_codec.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,12 @@ func (sc *StructCodec) DecodeValue(r DecodeContext, vr ValueReader, i interface{
220220

221221
func (sc *StructCodec) isZero(i interface{}) bool {
222222
v := reflect.ValueOf(i)
223+
224+
// check the value validity
225+
if !v.IsValid() {
226+
return true
227+
}
228+
223229
if z, ok := v.Interface().(bson.Zeroer); ok {
224230
return z.IsZero()
225231
}

0 commit comments

Comments
 (0)