summaryrefslogtreecommitdiff
path: root/src/math
diff options
context:
space:
mode:
authorCasey Marshall <casey.marshall@gmail.com>2014-10-13 12:41:14 -0700
committerCasey Marshall <casey.marshall@gmail.com>2014-10-13 12:41:14 -0700
commitf4662d9cf2a785a6fd76c8b2680936c6bda00203 (patch)
tree78c15f6c4c0aa8d26098e3231f943c7a224abfe9 /src/math
parent99f7d48a8fee437940b6456da34187fb4f46a3b9 (diff)
downloadgo-f4662d9cf2a785a6fd76c8b2680936c6bda00203.tar.gz
math/big: Fixes issue 8920
(*Rat).SetString checks for denominator. LGTM=gri R=golang-codereviews, gri CC=golang-codereviews https://codereview.appspot.com/159760043 Committer: Robert Griesemer <gri@golang.org>
Diffstat (limited to 'src/math')
-rw-r--r--src/math/big/rat.go3
-rw-r--r--src/math/big/rat_test.go1
2 files changed, 4 insertions, 0 deletions
diff --git a/src/math/big/rat.go b/src/math/big/rat.go
index 0bcec3025..c5339fe44 100644
--- a/src/math/big/rat.go
+++ b/src/math/big/rat.go
@@ -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
}
diff --git a/src/math/big/rat_test.go b/src/math/big/rat_test.go
index 598eac8cc..5dbbb3510 100644
--- a/src/math/big/rat_test.go
+++ b/src/math/big/rat_test.go
@@ -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) {