]> Cypherpunks repositories - gostls13.git/commitdiff
big: bug fix for division
authorRobert Griesemer <gri@golang.org>
Tue, 18 May 2010 23:31:49 +0000 (16:31 -0700)
committerRobert Griesemer <gri@golang.org>
Tue, 18 May 2010 23:31:49 +0000 (16:31 -0700)
Fixes #784.

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

src/pkg/big/nat.go

index 56f3c444ef410fec20de9af68a83fd35d7f5c81d..668a626891de7193f02ad896a90480422a5b89ff 100755 (executable)
@@ -528,10 +528,15 @@ func (z nat) divLarge(u, uIn, v nat) (q, r nat) {
        n := len(v)
        m := len(uIn) - n
 
+       // determine if z can be reused
+       if alias(z, uIn) || alias(z, v) {
+               z = nil // z is an alias for uIn or v - cannot reuse
+       }
        q = z.make(m + 1)
+
        qhatv := make(nat, n+1)
-       if alias(u, uIn) {
-               u = nil // u is an alias for uIn - cannot reuse
+       if alias(u, uIn) || alias(u, v) {
+               u = nil // u is an alias for uIn or v - cannot reuse
        }
        u = u.make(len(uIn) + 1)
        u.clear()