We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
https://github.com/teivah/100-go-mistakes/blob/master/src/03-data-types/18-integer-overflows/main.go#L26-L32
func AddInt(a, b int) int { if a > math.MaxInt-b { panic("int overflow") } return a + b }
This function panics if a is positive and b is negative.
a
b
func main() { AddInt(100, -20) // panic }
Here's an example of correctly handling overflow/underflow: https://github.com/shansec/go_code/blob/61331ebda07df6573065a1baf4fdc032884c43f6/microservices/addsrv/service.go#L40-L42
The text was updated successfully, but these errors were encountered:
No branches or pull requests
https://github.com/teivah/100-go-mistakes/blob/master/src/03-data-types/18-integer-overflows/main.go#L26-L32
This function panics if
a
is positive andb
is negative.Here's an example of correctly handling overflow/underflow: https://github.com/shansec/go_code/blob/61331ebda07df6573065a1baf4fdc032884c43f6/microservices/addsrv/service.go#L40-L42
The text was updated successfully, but these errors were encountered: