From cb009a5c4da40e1987b9dfcffa4d52bcae41e4e1 Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Tue, 17 Mar 2015 23:49:49 +0100 Subject: [PATCH] rlp: don't panic for nil *big.Int All other pointer types can handle nil just fine. --- rlp/encode.go | 7 ++++++- rlp/encode_test.go | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/rlp/encode.go b/rlp/encode.go index 9d11d66bf..42bbb876c 100644 --- a/rlp/encode.go +++ b/rlp/encode.go @@ -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 { diff --git a/rlp/encode_test.go b/rlp/encode_test.go index c283fbd57..852cb6f59 100644 --- a/rlp/encode_test.go +++ b/rlp/encode_test.go @@ -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"},