forked from cerc-io/plugeth
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.
This commit is contained in:
parent
509d0a8d78
commit
6788f955c2
@ -37,9 +37,9 @@ type Decoder interface {
|
|||||||
// DecodeRLP.
|
// DecodeRLP.
|
||||||
//
|
//
|
||||||
// To decode into a pointer, Decode will set the pointer to nil if the
|
// 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.
|
// input has size zero. If the input has nonzero size, Decode will
|
||||||
// If the input has nonzero size, Decode will allocate a new value of
|
// parse the input data into a value of the type being pointed to.
|
||||||
// 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
|
// 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
|
// 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
|
return nil, err
|
||||||
}
|
}
|
||||||
dec := func(s *Stream, val reflect.Value) (err error) {
|
dec := func(s *Stream, val reflect.Value) (err error) {
|
||||||
_, size, err := s.Kind()
|
kind, size, err := s.Kind()
|
||||||
if err != nil || size == 0 && s.byteval == 0 {
|
if err != nil || size == 0 && kind != Byte {
|
||||||
// rearm s.Kind. This is important because the input
|
// rearm s.Kind. This is important because the input
|
||||||
// position must advance to the next value even though
|
// position must advance to the next value even though
|
||||||
// we don't read anything.
|
// we don't read anything.
|
||||||
|
@ -378,7 +378,7 @@ var decodeTests = []decodeTest{
|
|||||||
},
|
},
|
||||||
|
|
||||||
// pointers
|
// pointers
|
||||||
{input: "00", ptr: new(*uint), value: (*uint)(nil)},
|
{input: "00", ptr: new(*uint), value: uintp(0)},
|
||||||
{input: "80", ptr: new(*uint), value: (*uint)(nil)},
|
{input: "80", ptr: new(*uint), value: (*uint)(nil)},
|
||||||
{input: "C0", ptr: new(*uint), value: (*uint)(nil)},
|
{input: "C0", ptr: new(*uint), value: (*uint)(nil)},
|
||||||
{input: "07", ptr: new(*uint), value: uintp(7)},
|
{input: "07", ptr: new(*uint), value: uintp(7)},
|
||||||
|
Loading…
Reference in New Issue
Block a user