Skip to content

Commit

Permalink
rlp: don't panic for nil *big.Int
Browse files Browse the repository at this point in the history
All other pointer types can handle nil just fine.
  • Loading branch information
fjl committed Mar 17, 2015
1 parent 86661de commit cb009a5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
7 changes: 6 additions & 1 deletion rlp/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,12 @@ func writeUint(val reflect.Value, w *encbuf) error {
}

func writeBigIntPtr(val reflect.Value, w *encbuf) error {
return writeBigInt(val.Interface().(*big.Int), w)
ptr := val.Interface().(*big.Int)
if ptr == nil {
w.str = append(w.str, 0x80)
return nil
}
return writeBigInt(ptr, w)
}

func writeBigIntNoPtr(val reflect.Value, w *encbuf) error {
Expand Down
1 change: 1 addition & 0 deletions rlp/encode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ var encTests = []encTest{
{val: (*uint)(nil), output: "80"},
{val: (*string)(nil), output: "80"},
{val: (*[]byte)(nil), output: "80"},
{val: (*big.Int)(nil), output: "80"},
{val: (*[]string)(nil), output: "C0"},
{val: (*[]interface{})(nil), output: "C0"},
{val: (*[]struct{ uint })(nil), output: "C0"},
Expand Down

0 comments on commit cb009a5

Please sign in to comment.