# invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation]

- **ID:** `go/invalid-memory-address-or-nil-pointer-dereference-in-select`
- **Domain:** go
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 90%

## Root Cause

Dereferencing a nil pointer in a goroutine, often inside a select statement or channel operation where a pointer was not properly initialized.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| go1.18 | active | — | — |
| go1.19 | active | — | — |
| go1.20 | active | — | — |
| go1.21 | active | — | — |

## Workarounds

1. **Add explicit nil checks before dereferencing: `if ptr != nil { ptr.Field = value } else { log.Fatal("ptr is nil") }`** (95% success)
   ```
   Add explicit nil checks before dereferencing: `if ptr != nil { ptr.Field = value } else { log.Fatal("ptr is nil") }`
   ```
2. **Initialize all pointers with make or new before use: `ptr = new(StructType)` or `ptr = &StructType{}`** (90% success)
   ```
   Initialize all pointers with make or new before use: `ptr = new(StructType)` or `ptr = &StructType{}`
   ```

## Dead Ends

- **** — SIGSEGV is a signal, not a panic; recover() cannot catch segmentation violations—the program still crashes. (90% fail)
- **** — Nil pointer dereference is not a race condition; the pointer is nil regardless of synchronization. (70% fail)
