aboutsummaryrefslogtreecommitdiffstats
path: root/rlp/decode.go
diff options
context:
space:
mode:
authorFelix Lange <fjl@twurst.com>2015-04-14 18:28:19 +0800
committerFelix Lange <fjl@twurst.com>2015-04-17 20:45:09 +0800
commit6788f955c2414b025a4ea44efaf51caf50aa97f0 (patch)
tree8f72f8a9d9da95e3874cec926c693b6a1b9d87a7 /rlp/decode.go
parent509d0a8d78236562d9444a6fe851aec3cee5bb5e (diff)
downloadgo-tangerine-6788f955c2414b025a4ea44efaf51caf50aa97f0.tar
go-tangerine-6788f955c2414b025a4ea44efaf51caf50aa97f0.tar.gz
go-tangerine-6788f955c2414b025a4ea44efaf51caf50aa97f0.tar.bz2
go-tangerine-6788f955c2414b025a4ea44efaf51caf50aa97f0.tar.lz
go-tangerine-6788f955c2414b025a4ea44efaf51caf50aa97f0.tar.xz
go-tangerine-6788f955c2414b025a4ea44efaf51caf50aa97f0.tar.zst
go-tangerine-6788f955c2414b025a4ea44efaf51caf50aa97f0.zip
rlp: fix handling of single byte zero when decoding into a pointer
A single zero byte carries information and should not set the pointer to nil. This is arguably a corner case. While here, fix the comment to explain pointer reuse.
Diffstat (limited to 'rlp/decode.go')
-rw-r--r--rlp/decode.go10
1 files changed, 5 insertions, 5 deletions
diff --git a/rlp/decode.go b/rlp/decode.go
index 1e39054e6..42be31a2d 100644
--- a/rlp/decode.go
+++ b/rlp/decode.go
@@ -37,9 +37,9 @@ type Decoder interface {
// DecodeRLP.
//
// To decode into a pointer, Decode will set the pointer to nil if the
-// input has size zero or the input is a single byte with value zero.
-// If the input has nonzero size, Decode will allocate a new value of
-// the type being pointed to.
+// input has size zero. If the input has nonzero size, Decode will
+// parse the input data into a value of the type being pointed to.
+// If the pointer is non-nil, the existing value will reused.
//
// To decode into a struct, Decode expects the input to be an RLP
// list. The decoded elements of the list are assigned to each public
@@ -382,8 +382,8 @@ func makePtrDecoder(typ reflect.Type) (decoder, error) {
return nil, err
}
dec := func(s *Stream, val reflect.Value) (err error) {
- _, size, err := s.Kind()
- if err != nil || size == 0 && s.byteval == 0 {
+ kind, size, err := s.Kind()
+ if err != nil || size == 0 && kind != Byte {
// rearm s.Kind. This is important because the input
// position must advance to the next value even though
// we don't read anything.