summaryrefslogtreecommitdiff
path: root/spew/dump.go
diff options
context:
space:
mode:
authorDave Collins <[email protected]>2013-01-20 20:44:21 -0600
committerDave Collins <[email protected]>2013-01-20 20:44:21 -0600
commita9907c15845e8273e99fd14a9f1641020ffd5cac (patch)
treeb8c5d2aafa6dc230f58d7b59dacc0c4773237239 /spew/dump.go
parentf2641d5e6e2ffc7bb5d847b6552149f4f3b02136 (diff)
Improve invalid reflect value handling.
It was previously possible for an invalid reflect value to lead to a panic in certain obscure cases. Rather than adding multiple checks for the invalid reflect value, handle invalid reflect values immediately.
Diffstat (limited to 'spew/dump.go')
-rw-r--r--spew/dump.go11
1 files changed, 9 insertions, 2 deletions
diff --git a/spew/dump.go b/spew/dump.go
index c635cfe..057c299 100644
--- a/spew/dump.go
+++ b/spew/dump.go
@@ -139,8 +139,14 @@ func (d *dumpState) dumpPtr(v reflect.Value) {
// appropriately. It is a recursive function, however circular data structures
// are detected and handled properly.
func (d *dumpState) dump(v reflect.Value) {
- // Handle pointers specially.
+ // Handle invalid reflect values immediately.
kind := v.Kind()
+ if kind == reflect.Invalid {
+ d.w.Write(invalidAngleBytes)
+ return
+ }
+
+ // Handle pointers specially.
if kind == reflect.Ptr {
d.pad()
d.dumpPtr(v)
@@ -169,7 +175,8 @@ func (d *dumpState) dump(v reflect.Value) {
switch kind {
case reflect.Invalid:
- d.w.Write(invalidAngleBytes)
+ // Do nothing. We should never get here since invalid has already
+ // been handled above.
case reflect.Bool:
printBool(d.w, v.Bool())