]> Cypherpunks repositories - gostls13.git/commitdiff
math/big: Fixes issue 8920
authorCasey Marshall <casey.marshall@gmail.com>
Mon, 13 Oct 2014 19:41:14 +0000 (12:41 -0700)
committerRobert Griesemer <gri@golang.org>
Mon, 13 Oct 2014 19:41:14 +0000 (12:41 -0700)
(*Rat).SetString checks for denominator.

LGTM=gri
R=golang-codereviews, gri
CC=golang-codereviews
https://golang.org/cl/159760043

src/math/big/rat.go
src/math/big/rat_test.go

index 0bcec30252f2decb546938eb1791e12ef69a925f..c5339fe443184583dadb2d6a224123955e2440d8 100644 (file)
@@ -552,6 +552,9 @@ func (z *Rat) SetString(s string) (*Rat, bool) {
                if z.b.abs, _, err = z.b.abs.scan(strings.NewReader(s), 10); err != nil {
                        return nil, false
                }
+               if len(z.b.abs) == 0 {
+                       return nil, false
+               }
                return z.norm(), true
        }
 
index 598eac8cc7b79c280faf42894b7e3b01e7e9204e..5dbbb3510f09cc3c308467e15d352c0a646530fd 100644 (file)
@@ -89,6 +89,7 @@ var setStringTests = []struct {
        {"53/70893980658822810696", "53/70893980658822810696", true},
        {"106/141787961317645621392", "53/70893980658822810696", true},
        {"204211327800791583.81095", "4084226556015831676219/20000", true},
+       {in: "1/0", ok: false},
 }
 
 func TestRatSetString(t *testing.T) {