Browse Source

codec: arrays are decodeable iff they are addressable

Thanks @ruz for finding the bug, the test implementation,
and the initial attempt at the fix.

Fixes #267
Closes #267
Ugorji Nwoke 7 years ago
parent
commit
587a7e6ca2
2 changed files with 5 additions and 1 deletions
  1. 1 1
      codec/decode.go
  2. 4 0
      codec/values_flex_test.go

+ 1 - 1
codec/decode.go

@@ -2379,7 +2379,7 @@ func (d *Decoder) arrayCannotExpand(sliceLen, streamLen int) {
 func isDecodeable(rv reflect.Value) (rv2 reflect.Value, canDecode bool) {
 	switch rv.Kind() {
 	case reflect.Array:
-		return rv, true
+		return rv, rv.CanAddr()
 	case reflect.Ptr:
 		if !rv.IsNil() {
 			return rv.Elem(), true

+ 4 - 0
codec/values_flex_test.go

@@ -19,6 +19,7 @@ const teststrucflexChanCap = 64
 
 // Some unused types just stored here
 type Bbool bool
+type Aarray [1]string
 type Sstring string
 type Sstructsmall struct {
 	A int
@@ -100,6 +101,8 @@ type TestStrucFlex struct {
 	Ui64array      [4]uint64
 	Ui64slicearray []*[4]uint64
 
+	SintfAarray []interface{}
+
 	// make this a ptr, so that it could be set or not.
 	// for comparison (e.g. with msgp), give it a struct tag (so it is not inlined),
 	// make this one omitempty (so it is excluded if nil).
@@ -171,6 +174,7 @@ func newTestStrucFlex(depth, n int, bench, useInterface, useStringKeyOnly bool)
 		},
 		Ui64array:   [4]uint64{4, 16, 64, 256},
 		ArrStrUi64T: [4]stringUint64T{{"4", 4}, {"3", 3}, {"2", 2}, {"1", 1}},
+		SintfAarray: []interface{}{Aarray{"s"}},
 	}
 
 	numChanSend := cap(ts.Chstr) / 4 // 8