{"record":{"id":"e7843d8d99736ca1","repo":"go-delve/delve","slug":"non-zero-length-array-with-nil-base","errorCode":null,"errorMessage":"non-zero length array with nil base","messagePattern":"non-zero length array with nil base","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/proc/variables.go","lineNumber":1732,"sourceCode":"\t\tTypedefType: godwarf.TypedefType{\n\t\t\tCommonType: chanType.TypedefType.CommonType,\n\t\t\tType:       pointerTo(newStructType, v.bi.Arch),\n\t\t},\n\t\tElemType: chanType.ElemType,\n\t}\n}\n\nfunc (v *Variable) loadArrayValues(recurseLevel int, cfg LoadConfig) {\n\tif v.Unreadable != nil {\n\t\treturn\n\t}\n\tif v.Len < 0 {\n\t\t//lint:ignore ST1005 backwards compatibility\n\t\tv.Unreadable = errors.New(\"Negative array length\")\n\t\treturn\n\t}\n\tif v.Base == 0 && v.Len > 0 {\n\t\tv.Unreadable = errors.New(\"non-zero length array with nil base\")\n\t\treturn\n\t}\n\n\tcount := v.Len\n\t// Cap number of elements\n\tif (v.Flags&variableTrustLen == 0) && (count > int64(cfg.MaxArrayValues)) {\n\t\tcount = int64(cfg.MaxArrayValues)\n\t}\n\tif v.Base+uint64(v.stride*count) < v.Base {\n\t\tv.Unreadable = fmt.Errorf(\"bad array base address %#x\", v.Base)\n\t\treturn\n\t}\n\n\tif v.stride < maxArrayStridePrefetch {\n\t\tv.mem = cacheMemory(v.mem, v.Base, int(v.stride*count))\n\t}\n\n\terrcount := 0","sourceCodeStart":1714,"sourceCodeEnd":1750,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/pkg/proc/variables.go#L1714-L1750","documentation":"loadArrayValues requires a non-empty array/slice to have a non-zero Base (the address of the first element). If Len > 0 but Base == 0, the value claims to have elements but points to nil memory, so reading it is impossible and the variable is marked unreadable. This typically reflects a nil or zero-valued slice being evaluated as if it had elements.","triggerScenarios":"Evaluating a slice whose header says len > 0 but whose data pointer is nil — e.g. a zero-value struct misinterpreted as an initialized slice, reading uninitialized memory, or a type-cast producing an impossible slice header.","commonSituations":"Inspecting structs before initialization in a crash, evaluating slices cast via unsafe from zeroed memory, debugging programs that crashed mid-initialization, or stale/incorrect variable evaluation in cgo frames.","solutions":["Check whether the slice is truly initialized in your program (a nil-backed slice with nonzero len is a program bug).","Inspect the individual header fields: `print lenField`, `print dataPtr` to confirm the inconsistency.","Step to a point where the slice is initialized before evaluating it.","If it came from an unsafe cast, validate that the source memory was populated first."],"exampleFix":"// before\ns := *(*[]byte)(unsafe.Pointer(&zeroedHeader)) // len=4, data=nil\nprint(s)\n// after\nif hdr.data != 0 { print(s) } else { print(\"nil data pointer\") }","handlingStrategy":"validation","validationCode":"if v.Len > 0 && v.Base == 0 {\n    // impossible slice header; do not attempt element reads\n    return\n}","typeGuard":"func hasValidSliceHeader(v *Variable) bool {\n    return v.Len >= 0 && !(v.Base == 0 && v.Len > 0)\n}","tryCatchPattern":"if v.Unreadable != nil && strings.Contains(v.Unreadable.Error(), \"nil base\") {\n    // treat as uninitialized slice; report header fields instead\n    return\n}","preventionTips":["Initialize slices before inspecting them at breakpoints","Validate data pointer != nil when slices come from unsafe casts","Check for program bugs: a nonzero-length slice with nil data is always invalid"],"tags":["debugger","arrays","slices","nil"],"backgroundTag":"nil-array-base-pointer","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}