nil pointer dereference
Trying to follow a pointer that is nil, which makes a Go program panic with an invalid memory address error.
An unchecked nil pointer crashes the whole process, taking down every request it was serving.
In more detail
It is one of the most common Go crashes, usually from an optional value or a failed call whose result was used without checking the error. Check if p == nil before using *p, or design so the zero value is useful and no pointer is needed.
Example
if value == nil {
return
}
fmt.Println(*value)Related terms
- nil — The Go value meaning nothing or not set, which is the zero value for pointers, slices, maps, channels, functions, interfaces and errors.
- dereference — Following a reference or pointer to reach the value it points at.
- panic — A Go run-time failure that stops normal execution, runs deferred functions and, unless recovered, crashes the program with a stack trace.
- pointer — A value that stores the memory location of another piece of data, so the program can follow it to that data.
Taught in
- Pointers and Memory — Concurrent Systems Programming with Go