# 无效的内存地址或空指针解引用 [信号 SIGSEGV: 分段违规]

- **ID:** `go/invalid-memory-address-or-nil-pointer-dereference-in-select`
- **领域:** go
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 90%

## 根因

在 goroutine 中解引用空指针，通常发生在 select 语句或通道操作中，指针未正确初始化。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| go1.18 | active | — | — |
| go1.19 | active | — | — |
| go1.20 | active | — | — |
| go1.21 | active | — | — |

## 解决方案

1. ```
   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{}`
   ```

## 无效尝试

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