Skip to content

Commit

Permalink
math/big: don't force second arg to Jacobi and Int.ModSqrt to escape
Browse files Browse the repository at this point in the history
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 cockroachdb/apd#103.
  • Loading branch information
nvanbenschoten committed Jan 9, 2022
1 parent 2639f2f commit 3ee07b5
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/math/big/int.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 3ee07b5

Please sign in to comment.