diff options
Diffstat (limited to 'spew/dump.go')
| -rw-r--r-- | spew/dump.go | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/spew/dump.go b/spew/dump.go index 5783145..36a2b6c 100644 --- a/spew/dump.go +++ b/spew/dump.go @@ -181,25 +181,30 @@ func (d *dumpState) dumpSlice(v reflect.Value) { // Try to use existing uint8 slices and fall back to converting // and copying if that fails. case vt.Kind() == reflect.Uint8: - // We need an addressable interface to convert the type back - // into a byte slice. However, the reflect package won't give - // us an interface on certain things like unexported struct - // fields in order to enforce visibility rules. We use unsafe - // to bypass these restrictions since this package does not + // TODO(davec): Fix up the disableUnsafe bits... + + // We need an addressable interface to convert the type + // to a byte slice. However, the reflect package won't + // give us an interface on certain things like + // unexported struct fields in order to enforce + // visibility rules. We use unsafe, when available, to + // bypass these restrictions since this package does not // mutate the values. vs := v if !vs.CanInterface() || !vs.CanAddr() { vs = unsafeReflectValue(vs) } - vs = vs.Slice(0, numEntries) + if !UnsafeDisabled { + vs = vs.Slice(0, numEntries) - // Use the existing uint8 slice if it can be type - // asserted. - iface := vs.Interface() - if slice, ok := iface.([]uint8); ok { - buf = slice - doHexDump = true - break + // Use the existing uint8 slice if it can be + // type asserted. + iface := vs.Interface() + if slice, ok := iface.([]uint8); ok { + buf = slice + doHexDump = true + break + } } // The underlying data needs to be converted if it can't |
