Fix incorrect type display on nil pointers.

This was reported by korschak as issue #4 who also pinpointed the issue
and provided a patch.
This commit is contained in:
Dave Collins 2013-01-12 23:30:04 -06:00
parent a2ceabae67
commit 389ea44d6a
2 changed files with 10 additions and 8 deletions

View File

@ -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)

View File

@ -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 {