Commit 158b427e authored by Robert Griesemer's avatar Robert Griesemer

big: fix broken overflow test

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

R=iant
CC=golang-dev
https://golang.org/cl/4526100
parent f259f6ba
......@@ -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 {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment