Skip to content
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

go vet: possible misuse of unsafe.Pointer #791

Closed
dtbartle opened this issue Mar 12, 2020 · 1 comment · Fixed by #814
Closed

go vet: possible misuse of unsafe.Pointer #791

dtbartle opened this issue Mar 12, 2020 · 1 comment · Fixed by #814

Comments

@dtbartle
Copy link

When running go vet ./... I see a few errors that should be fixed:

./sqlite3.go:476:63: possible misuse of unsafe.Pointer
./sqlite3.go:494:67: possible misuse of unsafe.Pointer
./sqlite3.go:507:71: possible misuse of unsafe.Pointer
./sqlite3.go:524:67: possible misuse of unsafe.Pointer
./sqlite3.go:538:70: possible misuse of unsafe.Pointer
@rittneje
Copy link
Collaborator

It looks like these are all flagging uses of the newHandle function, which indeed violates the rules about uintptr to unsafe.Pointer conversions. In particular, it returns an incrementing counter and then tries to treat it as a pointer, which I believe has the capacity to really confuse the garbage collector, or worse.

https://golang.org/pkg/unsafe/#Pointer

Conversion of a uintptr back to Pointer is not valid in general.

A uintptr is an integer, not a reference. Converting a Pointer to a uintptr creates an integer value with no pointer semantics. Even if a uintptr holds the address of some object, the garbage collector will not update that uintptr's value if the object moves, nor will that uintptr keep the object from being reclaimed.

This function ought to be replaced with a compliant implementation, like this.

mattn added a commit that referenced this issue May 15, 2020
mattn added a commit that referenced this issue Aug 26, 2020
* Use go-pointer instead of uintptr hacks.

Fixes #791

* Do same of go-pointer

* Drop older verion of Go

* Fix build

* Fix build
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants