1
0
mirror of https://github.com/golang/go synced 2024-11-21 17:54:39 -07:00

big: fix broken overflow test

- tested with GOARCH=386
- tested with GOARCH=amd64

R=iant
CC=golang-dev
https://golang.org/cl/4526100
This commit is contained in:
Robert Griesemer 2011-06-01 16:28:17 -07:00
parent f259f6ba0a
commit 158b427ea5

View File

@ -681,21 +681,21 @@ func (z nat) scan(r io.RuneScanner, base int) (nat, int, os.Error) {
z = z.make(0)
bb := Word(1)
dd := Word(0)
for {
for max := _M / b; ; {
d := hexValue(ch)
if d >= b {
r.UnreadRune() // ch does not belong to number anymore
break
}
if tmp := bb * b; tmp < bb {
// overflow
if bb <= max {
bb *= b
dd = dd*b + d
} else {
// bb * b would overflow
z = z.mulAddWW(z, bb, dd)
bb = b
dd = d
} else {
bb = tmp
dd = dd*b + d
}
if ch, _, err = r.ReadRune(); err != nil {