diff options
author | Rob Pike <r@golang.org> | 2010-07-20 19:53:28 -0700 |
---|---|---|
committer | Rob Pike <r@golang.org> | 2010-07-20 19:53:28 -0700 |
commit | 2e314f7736b8d61733b8934fb121ad90e67ffa31 (patch) | |
tree | adcca16aa931a917ed5060fe2013df0cb8fc100c | |
parent | e2dd5928ad6f92a37d002976324cffeea01c286c (diff) | |
download | go-2e314f7736b8d61733b8934fb121ad90e67ffa31.tar.gz |
gobs: fix bug in singleton arrays
Fixes issue 934.
R=rsc
CC=golang-dev
http://codereview.appspot.com/1869043
-rw-r--r-- | src/pkg/gob/encode.go | 4 | ||||
-rw-r--r-- | src/pkg/gob/encoder_test.go | 5 |
2 files changed, 4 insertions, 5 deletions
diff --git a/src/pkg/gob/encode.go b/src/pkg/gob/encode.go index 00548868b..55abeaf65 100644 --- a/src/pkg/gob/encode.go +++ b/src/pkg/gob/encode.go @@ -722,10 +722,6 @@ func encOpFor(rt reflect.Type) (encOp, int, os.Error) { return nil, 0, err } op = func(i *encInstr, state *encoderState, p unsafe.Pointer) { - slice := (*reflect.SliceHeader)(p) - if slice.Len == 0 { - return - } state.update(i) state.err = encodeArray(state.b, uintptr(p), elemOp, t.Elem().Size(), indir, t.Len()) } diff --git a/src/pkg/gob/encoder_test.go b/src/pkg/gob/encoder_test.go index b578cd0f8..f5b68113e 100644 --- a/src/pkg/gob/encoder_test.go +++ b/src/pkg/gob/encoder_test.go @@ -274,6 +274,7 @@ var testFloat32 float32 var testString string var testSlice []string var testMap map[string]int +var testArray [7]int type SingleTest struct { in interface{} @@ -287,6 +288,8 @@ var singleTests = []SingleTest{ SingleTest{"bike shed", &testString, ""}, SingleTest{[]string{"bike", "shed", "paint", "color"}, &testSlice, ""}, SingleTest{map[string]int{"seven": 7, "twelve": 12}, &testMap, ""}, + SingleTest{[7]int{4, 55, 0, 0, 0, 0, 0}, &testArray, ""}, // case that once triggered a bug + SingleTest{[7]int{4, 55, 1, 44, 22, 66, 1234}, &testArray, ""}, // Decode errors SingleTest{172, &testFloat32, "wrong type"}, @@ -320,7 +323,7 @@ func TestSingletons(t *testing.T) { // Get rid of the pointer in the rhs val := reflect.NewValue(test.out).(*reflect.PtrValue).Elem().Interface() if !reflect.DeepEqual(test.in, val) { - t.Errorf("decoding int: expected %v got %v", test.in, val) + t.Errorf("decoding singleton: expected %v got %v", test.in, val) } } } |