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 version
$ go version go version go1.14.4 linux/amd64
https://play.golang.org/p/Qf-Pfg1vzeZ
package main import "sync/atomic" func main() { var foo uint64 = 1 atomic.AddUint64(&foo, ^(0)) }
go env
$ go env > on goplayground
atomic.AddUint64(&foo, ^(0))
according to this
go/src/sync/atomic/doc.go
Lines 103 to 106 in 509ee70
compile success, decrement uint64(0) got undefined behavior.
uint64(0)
constant -1 overflows uint64
The text was updated successfully, but these errors were encountered:
I see you fixed the original issue by switching to atomic.AddUint64. I think the new error is guarding against what's usually a bug since you can't store a negative number in an unsigned integer.
atomic.Add
int64
Sorry, something went wrong.
As the comment says ^uint64(0) is what you need to use.
https://play.golang.org/p/Ru41D6UTSUb
No branches or pull requests
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
https://play.golang.org/p/Qf-Pfg1vzeZ
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
atomic.AddUint64(&foo, ^(0))
according to this
go/src/sync/atomic/doc.go
Lines 103 to 106 in 509ee70
What did you expect to see?
compile success, decrement
uint64(0)
got undefined behavior.What did you see instead?
constant -1 overflows uint64
The text was updated successfully, but these errors were encountered: