]> Cypherpunks repositories - gostls13.git/commitdiff
regexp/syntax: fix validity testing of zero repeats
authorIan Lance Taylor <iant@golang.org>
Mon, 20 Oct 2014 15:12:45 +0000 (08:12 -0700)
committerIan Lance Taylor <iant@golang.org>
Mon, 20 Oct 2014 15:12:45 +0000 (08:12 -0700)
This is already tested by TestRE2Exhaustive, but the build has
not broken because that test is not run when using -test.short.

LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/155580043

src/regexp/syntax/parse.go

index 3dc8ccf503a5e20fea7c237f78796ef30ae45698..d579a4069b16021b11438e9d04543c2d6c68d028 100644 (file)
@@ -272,13 +272,18 @@ func (p *parser) repeat(op Op, min, max int, before, after, lastRepeat string) (
 func repeatIsValid(re *Regexp, n int) bool {
        if re.Op == OpRepeat {
                m := re.Max
+               if m == 0 {
+                       return true
+               }
                if m < 0 {
                        m = re.Min
                }
                if m > n {
                        return false
                }
-               n /= m
+               if m > 0 {
+                       n /= m
+               }
        }
        for _, sub := range re.Sub {
                if !repeatIsValid(sub, n) {