• Brian Kessler's avatar
    math/big: clean up z.div(z, x, y) calls · 7818b82f
    Brian Kessler authored
    Updates #22830
    
    Due to not checking if the output slices alias in divLarge,
    calls of the form z.div(z, x, y) caused the slice z
    to attempt to be used to store both the quotient and the
    remainder of the division.  CL 78995 applies an alias
    check to correct that error.  This CL cleans up the
    additional div calls that attempt to supply the same slice
    to hold both the quotient and remainder.
    
    Note that the call in expNN was responsible for the reported
    error in r.Exp(x, 1, m) when r was initialized to a non-zero value.
    
    The second instance in expNNMontgomery did not result in an error
    due to the size of the arguments.
    
    	// RR = 2**(2*_W*len(m)) mod m
    	RR := nat(nil).setWord(1)
    	zz := nat(nil).shl(RR, uint(2*numWords*_W))
    	_, RR = RR.div(RR, zz, m)
    
    Specifically,
    
    cap(RR) == 5 after setWord(1) due to const e = 4 in z.make(1)
    len(zz) == 2*len(m) + 1 after shifting left, numWords = len(m)
    
    Reusing the backing array for z and z2 in div was only triggered if
    cap(RR) >= len(zz) + 1 and len(m) > 1 so that divLarge was called.
    
    But, 5 < 2*len(m) + 2 if len(m) > 1, so new arrays were allocated
    and the error was never triggered in this case.
    
    Change-Id: Iedac80dbbde13216c94659e84d28f6f4be3aaf24
    Reviewed-on: https://go-review.googlesource.com/81055
    Run-TryBot: Robert Griesemer <gri@golang.org>
    TryBot-Result: Gobot Gobot <gobot@golang.org>
    Reviewed-by: 's avatarRobert Griesemer <gri@golang.org>
    7818b82f
Name
Last commit
Last update
..
accuracy_string.go Loading commit data...
arith.go Loading commit data...
arith_386.s Loading commit data...
arith_amd64.go Loading commit data...
arith_amd64.s Loading commit data...
arith_amd64p32.s Loading commit data...
arith_arm.s Loading commit data...
arith_arm64.s Loading commit data...
arith_decl.go Loading commit data...
arith_decl_pure.go Loading commit data...
arith_decl_s390x.go Loading commit data...
arith_mips64x.s Loading commit data...
arith_mipsx.s Loading commit data...
arith_ppc64x.s Loading commit data...
arith_s390x.s Loading commit data...
arith_s390x_test.go Loading commit data...
arith_test.go Loading commit data...
bits_test.go Loading commit data...
calibrate_test.go Loading commit data...
decimal.go Loading commit data...
decimal_test.go Loading commit data...
doc.go Loading commit data...
example_rat_test.go Loading commit data...
example_test.go Loading commit data...
float.go Loading commit data...
float_test.go Loading commit data...
floatconv.go Loading commit data...
floatconv_test.go Loading commit data...
floatexample_test.go Loading commit data...
floatmarsh.go Loading commit data...
floatmarsh_test.go Loading commit data...
ftoa.go Loading commit data...
gcd_test.go Loading commit data...
hilbert_test.go Loading commit data...
int.go Loading commit data...
int_test.go Loading commit data...
intconv.go Loading commit data...
intconv_test.go Loading commit data...
intmarsh.go Loading commit data...
intmarsh_test.go Loading commit data...
nat.go Loading commit data...
nat_test.go Loading commit data...
natconv.go Loading commit data...
natconv_test.go Loading commit data...
prime.go Loading commit data...
prime_test.go Loading commit data...
rat.go Loading commit data...
rat_test.go Loading commit data...
ratconv.go Loading commit data...
ratconv_test.go Loading commit data...
ratmarsh.go Loading commit data...
ratmarsh_test.go Loading commit data...
roundingmode_string.go Loading commit data...
sqrt.go Loading commit data...
sqrt_test.go Loading commit data...