Skip to content

Commit

Permalink
runtime: fix overflow in PingPongHog test
Browse files Browse the repository at this point in the history
On 32-bit systems the result of hogCount*factor can overflow.
Use division instead to do comparison.

Update #52207

Change-Id: I429fb9dc009af645acb535cee5c70887527ba207
Reviewed-on: https://go-review.googlesource.com/c/go/+/407415
Reviewed-by: Michael Knyszek <[email protected]>
Run-TryBot: Keith Randall <[email protected]>
TryBot-Result: Gopher Robot <[email protected]>
Reviewed-by: Keith Randall <[email protected]>
  • Loading branch information
randall77 committed May 19, 2022
1 parent dd83fd8 commit d8762b2
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/runtime/proc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ func TestPingPongHog(t *testing.T) {
// scheduler isn't working right, the gap should be ~1000X
// (was 5, increased to 20, see issue 52207).
const factor = 20
if hogCount > lightCount*factor || lightCount > hogCount*factor {
if hogCount/factor > lightCount || lightCount/factor > hogCount {
t.Fatalf("want hogCount/lightCount in [%v, %v]; got %d/%d = %g", 1.0/factor, factor, hogCount, lightCount, float64(hogCount)/float64(lightCount))
}
}
Expand Down

0 comments on commit d8762b2

Please sign in to comment.