go-delve/delve · error
Negative array length
Error message
Negative array length
What it means
loadArrayValues refuses to read an array/slice whose Len field is negative. A negative length is impossible for real Go arrays/slices and indicates corrupted memory, bad type interpretation, or a misread slice header. The variable is marked unreadable with this exact (capitalized, for backwards compatibility) message.
Source
Thrown at pkg/proc/variables.go:1728
newStructType.Field[i] = field
}
v.RealType = &godwarf.ChanType{
TypedefType: godwarf.TypedefType{
CommonType: chanType.TypedefType.CommonType,
Type: pointerTo(newStructType, v.bi.Arch),
},
ElemType: chanType.ElemType,
}
}
func (v *Variable) loadArrayValues(recurseLevel int, cfg LoadConfig) {
if v.Unreadable != nil {
return
}
if v.Len < 0 {
//lint:ignore ST1005 backwards compatibility
v.Unreadable = errors.New("Negative array length")
return
}
if v.Base == 0 && v.Len > 0 {
v.Unreadable = errors.New("non-zero length array with nil base")
return
}
count := v.Len
// Cap number of elements
if (v.Flags&variableTrustLen == 0) && (count > int64(cfg.MaxArrayValues)) {
count = int64(cfg.MaxArrayValues)
}
if v.Base+uint64(v.stride*count) < v.Base {
v.Unreadable = fmt.Errorf("bad array base address %#x", v.Base)
return
}
if v.stride < maxArrayStridePrefetch {View on GitHub (pinned to a23773e6c3)
Solutions
- Inspect the slice header fields individually (data ptr, len, cap) with `print` to confirm the length value.
- Re-evaluate after stepping to a state where the slice is fully initialized.
- Verify the variable's address is valid (not reading garbage memory).
- If persistent, check the debuggee for memory corruption (this may be a real bug in your program).
Example fix
// before (evaluating possibly-garbage header as slice)
print(*(*[]int)(unsafe.Pointer(&garbage)))
// after
if lenHeader >= 0 { print(slice) } else { print("invalid slice header") } Defensive patterns
Strategy: validation
Validate before calling
if v.Len < 0 {
// do not call array-loading APIs on this variable
return
} Try / catch
if v.Unreadable != nil && strings.Contains(v.Unreadable.Error(), "Negative array length") {
// treat as unreadable; inspect the raw header manually
return
} Prevention
- Validate slice headers (0 <= len <= cap) before evaluating casted memory
- Avoid evaluating slices from uninitialized or corrupted memory regions
- Re-evaluate variables only at program points where they are in scope and initialized
When it happens
Trigger: Evaluating a slice/array whose slice header (data pointer, len, cap) was read as garbage — e.g. reading through an invalid address, evaluating a non-slice as a slice, or memory corruption in the debuggee.
Common situations: Inspecting slices in corrupted heap regions, evaluating unsafe-cast values, debugging crashes where the slice header itself was overwritten, or stale registers after a crash point.
Related errors
- non-zero length array with nil base
- hardware breakpoints exhausted
- break on read only not supported
- ErrCouldNotDetermineRelocation
- errBinaryInfoClose
AI-assisted analysis of go-delve/delve@a23773e6c3 (2026-08-31).
Data as JSON: /api/errors/8e8768d3e24ccad1.
Report an issue: GitHub.