Skip to content

Commit cb009a5

Browse files
committed
rlp: don't panic for nil *big.Int
All other pointer types can handle nil just fine.
1 parent 86661de commit cb009a5

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

‎rlp/encode.go‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,12 @@ func writeUint(val reflect.Value, w *encbuf) error {
386386
}
387387

388388
func writeBigIntPtr(val reflect.Value, w *encbuf) error {
389-
return writeBigInt(val.Interface().(*big.Int), w)
389+
ptr := val.Interface().(*big.Int)
390+
if ptr == nil {
391+
w.str = append(w.str, 0x80)
392+
return nil
393+
}
394+
return writeBigInt(ptr, w)
390395
}
391396

392397
func writeBigIntNoPtr(val reflect.Value, w *encbuf) error {

‎rlp/encode_test.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ var encTests = []encTest{
196196
{val: (*uint)(nil), output: "80"},
197197
{val: (*string)(nil), output: "80"},
198198
{val: (*[]byte)(nil), output: "80"},
199+
{val: (*big.Int)(nil), output: "80"},
199200
{val: (*[]string)(nil), output: "C0"},
200201
{val: (*[]interface{})(nil), output: "C0"},
201202
{val: (*[]struct{ uint })(nil), output: "C0"},

0 commit comments

Comments
 (0)