-
Notifications
You must be signed in to change notification settings - Fork 17.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
proposal: cmd/go: consider adding unsafeptr to go vet during test list #57794
Comments
The expression |
Note that
I am not sure why the |
checkptr
in go test
vet checks, or document why it is not included
checkptr
in go test
vet checks, or document why it is not included
This looks like a shortcoming in the unsafe package docs that propagated into both the checkptr compiler code and the unsafeptr vet code. The compiler knows that when you read a SliceHeader or StructHeader Data field, it is as though you are writing uintptr(an unsafe.Pointer-typed field), but the docs and the checks don't apply this rule. I don't think it's particularly defensible to say that
is permitted but somehow the single-line form
is not. |
Caveat: The compiler knows this well enough to satisfy safety rule 6 in isolation, but I'm not certain it already satisfies it in combination with rule 3. That is, off hand, I can't think of any reason why It's certainly not safe today to combine rules 3 and 5; e.g., One nice thing about that is it's safe to do regardless of what |
I think we can close this as a duplicate of #58625. In particular, the reports examined in #58625 (comment) make clear that the unsafeptr check is not accurate enough to turn on by default in 'go test' and instead probably should be removed from vet entirely. In any event, that conversation is happening on #58625 and need not be duplicated here. |
This proposal is a duplicate of a previously discussed proposal, as noted above, |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
compile with flag
-race
https://go.dev/play/p/wNXEyU8p6XD?v=gotip
What did you expect to see?
Two same addresses, example:
0xc00012e280
0xc00012e280
What did you see instead?
fatal error: checkptr: pointer arithmetic result points to invalid allocation
I think the error cause incorrect compile on this place, because original value is null.
The text was updated successfully, but these errors were encountered: