Go vet "possible misuse of unsafe.Pointer" - Fix in CI
The unsafe.Pointer rules require that pointer arithmetic happen in a single expression so the GC never sees a bare uintptr holding a live address. vet flags conversions that store uintptr across statements.
What this error means
go vet fails with possible misuse of unsafe.Pointer. A uintptr was held in a variable between converting from and back to unsafe.Pointer, which is not GC-safe.
go
./mem.go:14:9: possible misuse of unsafe.PointerCommon causes
uintptr stored across statements
A pointer was converted to uintptr, kept in a variable, then converted back later, leaving a window where the GC could move the object.
Arithmetic split into steps
Pointer offset math was broken into multiple statements instead of a single expression, violating the unsafe rules.
How to fix it
Keep the conversion in one expression
- Do the offset arithmetic and the back-conversion in a single expression so no uintptr persists.
Go
p := unsafe.Pointer(uintptr(base) + offset)Prefer safe abstractions
- Replace manual pointer math with unsafe.Add or a typed slice where possible.
Go
p := unsafe.Add(base, offset)How to prevent it
- Never store an address in a uintptr variable across statements.
- Use unsafe.Add and unsafe.Slice instead of manual arithmetic.
- Run go vet in CI so unsafe misuse is caught early.
Related guides
staticcheck SA1019 "is deprecated" - Fix in CIFix staticcheck SA1019 "X is deprecated" in CI - code uses an API marked deprecated. Migrate to the replaceme…
golangci-lint "typecheck" errors - Fix in CIFix golangci-lint "typecheck" errors in CI - the linter could not compile the package, so every analyzer fail…
Go "DATA RACE" in goroutine - Fix in CIFix Go "WARNING: DATA RACE" under -race in CI - two goroutines touched the same memory unsynchronized. Add a…