# panic: runtime error: invalid memory address or nil pointer dereference

- **ID:** `go/unsafe-pointer-arithmetic`
- **Domain:** go
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

Using `unsafe.Pointer` arithmetic incorrectly, resulting in accessing out-of-bounds memory.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 1.21 | active | — | — |
| 1.22 | active | — | — |

## Workarounds

1. **Use `unsafe.Add` for safe pointer arithmetic (Go 1.17+)** (90% success)
   ```
   p := unsafe.Pointer(&arr[0])
next := unsafe.Add(p, unsafe.Sizeof(arr[0])*2)
_ = *(*int)(next)
   ```
2. **Convert to `uintptr` only immediately before use and pin** (75% success)
   ```
   runtime.KeepAlive(arr)
ptr := uintptr(unsafe.Pointer(&arr[0])) + unsafe.Sizeof(arr[0])
_ = *(*int)(unsafe.Pointer(ptr))
   ```

## Dead Ends

- **Adding offset without aligning to type size** — Unaligned access can cause crash on some architectures. (70% fail)
- **Using `uintptr` as pointer without pinning** — GC may move the object, making uintptr stale. (80% fail)
