]> Cypherpunks repositories - gostls13.git/commit
math/big: fix spurious race in Rat.Denom, Float.SetRat
authorRuss Cox <rsc@golang.org>
Thu, 6 Jan 2022 17:20:14 +0000 (12:20 -0500)
committerRuss Cox <rsc@golang.org>
Fri, 7 Jan 2022 00:15:59 +0000 (00:15 +0000)
commit07525e16ba9fcb8924ed872b015dc217d1b01b6b
tree61c324c7aab2eafa9b108293f5f62a5a9767df77
parentc295137ad8e5e947205d060a26164cb71952c1bb
math/big: fix spurious race in Rat.Denom, Float.SetRat

Rat maintains the invariant that x.b.neg is always false,
but Rat.Denom was writing x.b.neg = false itself too.
That makes Rat.Denom a writing operation, when it should
be a read-only operation. That in turn makes it unsafe to
use from multiple goroutines, which is highly unexpected.
Make it read-only and therefore race-free again.

Fixes #50473.

Change-Id: I97b87913954511e5200c0665d16b9ed63422e505
Reviewed-on: https://go-review.googlesource.com/c/go/+/375935
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
src/math/big/rat.go
src/math/big/rat_test.go