-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Closed as not planned
Labels
FeatureRequestIssues asking for a new feature that does not need a proposal.Issues asking for a new feature that does not need a proposal.NeedsFixThe path to resolution is known, but the work has not been done.The path to resolution is known, but the work has not been done.ToolsThis label describes issues relating to any tools in the x/tools repository.This label describes issues relating to any tools in the x/tools repository.
Milestone
Description
The code below forms a new pointer y by adding an offset to another pointer ptr:
y := uintptr(unsafe.Pointer(ptr)) + uintptr(n)
return (*byte)(unsafe.Pointer(y))If ptr is the sole reference to a variable, then after the assignment to y is complete, there are no more references to that variable and the GC is free to reclaim its storage. By the time the new pointer is formed in the return statement, the variable may no longer exist.
The correct code either inlines the expression for y into the return statement, or moves the unsafe.Pointer(y) conversion into the definition of y, so that after every statement, the variable is live.
Although the existing unsafeptr package detects some pointer mistakes, it does not detect this one. It should.
See also:
Metadata
Metadata
Assignees
Labels
FeatureRequestIssues asking for a new feature that does not need a proposal.Issues asking for a new feature that does not need a proposal.NeedsFixThe path to resolution is known, but the work has not been done.The path to resolution is known, but the work has not been done.ToolsThis label describes issues relating to any tools in the x/tools repository.This label describes issues relating to any tools in the x/tools repository.