]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: fix overflow in PingPongHog test
authorKeith Randall <khr@golang.org>
Thu, 19 May 2022 20:45:51 +0000 (13:45 -0700)
committerKeith Randall <khr@golang.org>
Thu, 19 May 2022 21:33:15 +0000 (21:33 +0000)
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 <mknyszek@google.com>
Run-TryBot: Keith Randall <khr@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
src/runtime/proc_test.go

index 418e448d2fec02f6b51921c34917cc57da613ec7..f354facc49539c1a94cc2bc76916a872d5ba6860 100644 (file)
@@ -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))
        }
 }