]> Cypherpunks.ru repositories - gostls13.git/commitdiff
math/big: don't force second arg to Jacobi and Int.ModSqrt to escape
authorNathan VanBenschoten <nvanbenschoten@gmail.com>
Sun, 9 Jan 2022 20:29:40 +0000 (20:29 +0000)
committerGopher Robot <gobot@golang.org>
Sun, 8 May 2022 17:15:30 +0000 (17:15 +0000)
This CL updates big.Jacobi to avoid forcing its y argument to escape
to the heap. The argument was escaping because it was being passed
through an empty interface to fmt.Sprintf during an assertion failure.
As a result, callers of Jacobi and Int.ModSqrt (which calls Jacobi)
could not keep this value on the stack.

Noticed when working on https://github.com/cockroachdb/apd/pull/103.

Change-Id: I5db9ee2149bf13b921886929425861721b53b085
GitHub-Last-Rev: 3ee07b5dc3292553cc0cd0eb2d38ef036c341a9d
GitHub-Pull-Request: golang/go#50527
Reviewed-on: https://go-review.googlesource.com/c/go/+/377014
Auto-Submit: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Filippo Valsorda <filippo@golang.org>
src/math/big/int.go

index 01ff0bf8c6161930798c2dc8d5d59af874597123..ec168f8ffe57189b736c19b39c642f0aeb1b3f72 100644 (file)
@@ -840,7 +840,7 @@ func (z *Int) ModInverse(g, n *Int) *Int {
 // The y argument must be an odd integer.
 func Jacobi(x, y *Int) int {
        if len(y.abs) == 0 || y.abs[0]&1 == 0 {
-               panic(fmt.Sprintf("big: invalid 2nd argument to Int.Jacobi: need odd integer but got %s", y))
+               panic(fmt.Sprintf("big: invalid 2nd argument to Int.Jacobi: need odd integer but got %s", y.String()))
        }
 
        // We use the formulation described in chapter 2, section 2.4,