diff options
| author | Dave Collins <[email protected]> | 2013-01-12 23:30:04 -0600 |
|---|---|---|
| committer | Dave Collins <[email protected]> | 2013-01-12 23:30:04 -0600 |
| commit | 389ea44d6a60b489ba166fe882b531e967dbc14a (patch) | |
| tree | df56b1c36f7370d138f1598fb78fa056e36fd14a | |
| parent | a2ceabae67d4867f3edbffc1669e8267794ae860 (diff) | |
Fix incorrect type display on nil pointers.
This was reported by korschak as issue #4 who also pinpointed the issue
and provided a patch.
| -rw-r--r-- | spew/dump.go | 16 | ||||
| -rw-r--r-- | spew/format.go | 2 |
2 files changed, 10 insertions, 8 deletions
diff --git a/spew/dump.go b/spew/dump.go index 361e90e..4697263 100644 --- a/spew/dump.go +++ b/spew/dump.go @@ -66,11 +66,11 @@ func (d *dumpState) dumpPtr(v reflect.Value) { indirects := 0 ve := v for ve.Kind() == reflect.Ptr { - indirects++ if ve.IsNil() { nilFound = true break } + indirects++ addr := ve.Pointer() pointerChain = append(pointerChain, addr) if pd, ok := d.pointers[addr]; ok && pd < d.depth { @@ -97,14 +97,16 @@ func (d *dumpState) dumpPtr(v reflect.Value) { d.w.Write(closeParenBytes) // Display pointer information. - d.w.Write(openParenBytes) - for i, addr := range pointerChain { - if i > 0 { - d.w.Write(pointerChainBytes) + if len(pointerChain) > 0 { + d.w.Write(openParenBytes) + for i, addr := range pointerChain { + if i > 0 { + d.w.Write(pointerChainBytes) + } + printHexPtr(d.w, addr) } - printHexPtr(d.w, addr) + d.w.Write(closeParenBytes) } - d.w.Write(closeParenBytes) // Display dereferenced value. d.w.Write(openParenBytes) diff --git a/spew/format.go b/spew/format.go index 4a285e2..d55df63 100644 --- a/spew/format.go +++ b/spew/format.go @@ -115,11 +115,11 @@ func (f *formatState) formatPtr(v reflect.Value) { indirects := 0 ve := v for ve.Kind() == reflect.Ptr { - indirects++ if ve.IsNil() { nilFound = true break } + indirects++ addr := ve.Pointer() pointerChain = append(pointerChain, addr) if pd, ok := f.pointers[addr]; ok && pd < f.depth { |
