Преглед изворни кода

marshal: prevent calling IsNil on non nullable types (#1256)

Vincent Rischmann пре 6 година
родитељ
комит
49a367be4d
1 измењених фајлова са 4 додато и 3 уклоњено
  1. 4 3
      marshal.go

+ 4 - 3
marshal.go

@@ -1478,15 +1478,16 @@ func marshalMap(info TypeInfo, value interface{}) ([]byte, error) {
 	}
 
 	rv := reflect.ValueOf(value)
-	if rv.IsNil() {
-		return nil, nil
-	}
 
 	t := rv.Type()
 	if t.Kind() != reflect.Map {
 		return nil, marshalErrorf("can not marshal %T into %s", value, info)
 	}
 
+	if rv.IsNil() {
+		return nil, nil
+	}
+
 	buf := &bytes.Buffer{}
 	n := rv.Len()