]> Cypherpunks repositories - gostls13.git/commitdiff
big: do not modify divisor
authorRobert Griesemer <gri@golang.org>
Thu, 2 Jun 2011 18:07:41 +0000 (11:07 -0700)
committerRobert Griesemer <gri@golang.org>
Thu, 2 Jun 2011 18:07:41 +0000 (11:07 -0700)
Fixes #1907.

R=rsc
CC=golang-dev
https://golang.org/cl/4527096

src/pkg/big/nat.go

index 4f17e3690c0e53d88c48c7b30ab95c9dfabff4c3..db02a43c2e1e5f9273e5f54379a54f9e8d2f32a8 100755 (executable)
@@ -551,7 +551,12 @@ func (z nat) divLarge(u, uIn, v nat) (q, r nat) {
 
        // D1.
        shift := Word(leadingZeros(v[n-1]))
-       shlVW(v, v, shift)
+       if shift > 0 {
+               // do not modify v, it may be used by another goroutine simultaneously
+               v1 := make(nat, n)
+               shlVW(v1, v, shift)
+               v = v1
+       }
        u[len(uIn)] = shlVW(u[0:len(uIn)], uIn, shift)
 
        // D2.
@@ -592,7 +597,6 @@ func (z nat) divLarge(u, uIn, v nat) (q, r nat) {
 
        q = q.norm()
        shrVW(u, u, shift)
-       shrVW(v, v, shift)
        r = u.norm()
 
        return q, r