1
0
mirror of https://github.com/golang/go synced 2024-11-21 18:04:40 -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) z = z.make(0)
bb := Word(1) bb := Word(1)
dd := Word(0) dd := Word(0)
for { for max := _M / b; ; {
d := hexValue(ch) d := hexValue(ch)
if d >= b { if d >= b {
r.UnreadRune() // ch does not belong to number anymore r.UnreadRune() // ch does not belong to number anymore
break break
} }
if tmp := bb * b; tmp < bb { if bb <= max {
// overflow bb *= b
dd = dd*b + d
} else {
// bb * b would overflow
z = z.mulAddWW(z, bb, dd) z = z.mulAddWW(z, bb, dd)
bb = b bb = b
dd = d dd = d
} else {
bb = tmp
dd = dd*b + d
} }
if ch, _, err = r.ReadRune(); err != nil { if ch, _, err = r.ReadRune(); err != nil {