-
-
Notifications
You must be signed in to change notification settings - Fork 483
Open
Labels
erratumErratumErratum
Description
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.
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
pellared, kirugan and dlwyatt
Metadata
Metadata
Assignees
Labels
erratumErratumErratum