Fixes #11127.
Change-Id: Ibcfc3a05e91fa4260d70b04bee2bbba2376bd313
Reviewed-on: https://go-review.googlesource.com/13923
Reviewed-by: Adam Langley <agl@golang.org>
t.Fatalf("Expected error to mention %q but error was %q", expectedSubstring, err.Error())
}
}
+
+func TestMarshalNilValue(t *testing.T) {
+ nilValueTestData := []interface{}{
+ nil,
+ struct{ v interface{} }{},
+ }
+ for i, test := range nilValueTestData {
+ if _, err := Marshal(test); err == nil {
+ t.Fatal("#%d: successfully marshaled nil value", i)
+ }
+ }
+}
}
func marshalField(out *forkableWriter, v reflect.Value, params fieldParameters) (err error) {
+ if !v.IsValid() {
+ return fmt.Errorf("asn1: cannot marshal nil value")
+ }
// If the field is an interface{} then recurse into it.
if v.Kind() == reflect.Interface && v.Type().NumMethod() == 0 {
return marshalField(out, v.Elem(), params)