From 3ee07b5dc3292553cc0cd0eb2d38ef036c341a9d Mon Sep 17 00:00:00 2001 From: Nathan VanBenschoten Date: Sun, 9 Jan 2022 15:24:21 -0500 Subject: [PATCH] math/big: don't force second arg to Jacobi and Int.ModSqrt to escape 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. --- src/math/big/int.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/math/big/int.go b/src/math/big/int.go index 7647346486c4cb..945caa20770b38 100644 --- a/src/math/big/int.go +++ b/src/math/big/int.go @@ -837,7 +837,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,