diff options
author | Felix Lange <fjl@twurst.com> | 2014-11-17 19:02:08 +0800 |
---|---|---|
committer | Felix Lange <fjl@twurst.com> | 2014-11-17 19:02:08 +0800 |
commit | bd0a50fdc3550eba979b132a92960f1e08110033 (patch) | |
tree | 316b21e90b4c2a1745c50a368529ffdc6d3be879 | |
parent | 74266d5bbd95ac07882b09230aec876bf7704f69 (diff) | |
download | go-tangerine-bd0a50fdc3550eba979b132a92960f1e08110033.tar.gz go-tangerine-bd0a50fdc3550eba979b132a92960f1e08110033.tar.zst go-tangerine-bd0a50fdc3550eba979b132a92960f1e08110033.zip |
rlp: fix pointer reuse
-rw-r--r-- | rlp/decode.go | 1 | ||||
-rw-r--r-- | rlp/decode_test.go | 11 |
2 files changed, 10 insertions, 2 deletions
diff --git a/rlp/decode.go b/rlp/decode.go index 1a51e7130..96d912f56 100644 --- a/rlp/decode.go +++ b/rlp/decode.go @@ -309,6 +309,7 @@ func makePtrDecoder(typ reflect.Type) (decoder, error) { dec := func(s *Stream, val reflect.Value) (err error) { _, size, err := s.Kind() if err != nil || size == 0 && s.byteval == 0 { + val.Set(reflect.Zero(typ)) // set to nil return err } newval := val diff --git a/rlp/decode_test.go b/rlp/decode_test.go index 5cb42b870..eb1618299 100644 --- a/rlp/decode_test.go +++ b/rlp/decode_test.go @@ -176,8 +176,6 @@ type recstruct struct { Child *recstruct } -var sharedByteArray [5]byte - var ( veryBigInt = big.NewInt(0).Add( big.NewInt(0).Lsh(big.NewInt(0xFFFFFFFFFFFFFF), 16), @@ -185,6 +183,11 @@ var ( ) ) +var ( + sharedByteArray [5]byte + sharedPtr = new(*int) +) + var decodeTests = []decodeTest{ // integers {input: "05", ptr: new(uint32), value: uint32(5)}, @@ -268,6 +271,10 @@ var decodeTests = []decodeTest{ {input: "C109", ptr: new(*[]int), value: &[]int{9}}, {input: "C58403030303", ptr: new(*[][]byte), value: &[][]byte{{3, 3, 3, 3}}}, + // pointer should be reset to nil + {input: "05", ptr: sharedPtr, value: intp(5)}, + {input: "80", ptr: sharedPtr, value: (*int)(nil)}, + // interface{} {input: "00", ptr: new(interface{}), value: []byte{0}}, {input: "01", ptr: new(interface{}), value: []byte{1}}, |