]> Cypherpunks repositories - gostls13.git/commitdiff
big: fix nat.scan bug
authorEvan Shaw <chickencha@gmail.com>
Wed, 24 Aug 2011 21:55:03 +0000 (14:55 -0700)
committerRobert Griesemer <gri@golang.org>
Wed, 24 Aug 2011 21:55:03 +0000 (14:55 -0700)
Scanning "0" with detected base did not actually set the nat to 0.

R=gri
CC=golang-dev
https://golang.org/cl/4923050

src/pkg/big/int_test.go
src/pkg/big/nat.go

index 03446d6ae2d9cf81398401505dd3df0400cec4b9..b2e1692179943f90e0aa7e4a1b01555f2a77f0f4 100755 (executable)
@@ -301,6 +301,9 @@ func TestGetString(t *testing.T) {
 func TestSetString(t *testing.T) {
        tmp := new(Int)
        for i, test := range stringTests {
+               // initialize to a non-zero value so that issues with parsing
+               // 0 are detected
+               tmp.SetInt64(1234567890)
                n1, ok1 := new(Int).SetString(test.in, test.base)
                n2, ok2 := tmp.SetString(test.in, test.base)
                expected := NewInt(test.val)
index be3aff29d1840d4644567db1aa09ec620b674a7d..33d6bb16ffd8b6bd2839c678315ee2310f9371d8 100755 (executable)
@@ -646,7 +646,7 @@ func (z nat) scan(r io.RuneScanner, base int) (nat, int, os.Error) {
                                        }
                                }
                        case os.EOF:
-                               return z, 10, nil
+                               return z.make(0), 10, nil
                        default:
                                return z, 10, err
                        }