]> granicus.if.org Git - python/commitdiff
Issue #18647: Correctly bound calculated min/max width of a subexpression.
authorSerhiy Storchaka <storchaka@gmail.com>
Mon, 19 Aug 2013 19:53:46 +0000 (22:53 +0300)
committerSerhiy Storchaka <storchaka@gmail.com>
Mon, 19 Aug 2013 19:53:46 +0000 (22:53 +0300)
Now max width is MAXREPEAT on 32- and 64-bit platforms when one of
subexpressions is unbounded repetition.

Lib/sre_parse.py

index 75f8c9601df6ef7d6889392e2a68aef275417a70..e8d35a6d41251a270c5eddb3215fe0c322491543 100644 (file)
@@ -142,12 +142,12 @@ class SubPattern:
         # determine the width (min, max) for this subpattern
         if self.width:
             return self.width
-        lo = hi = 0L
+        lo = hi = 0
         UNITCODES = (ANY, RANGE, IN, LITERAL, NOT_LITERAL, CATEGORY)
         REPEATCODES = (MIN_REPEAT, MAX_REPEAT)
         for op, av in self.data:
             if op is BRANCH:
-                i = sys.maxint
+                i = MAXREPEAT - 1
                 j = 0
                 for av in av[1]:
                     l, h = av.getwidth()
@@ -165,14 +165,14 @@ class SubPattern:
                 hi = hi + j
             elif op in REPEATCODES:
                 i, j = av[2].getwidth()
-                lo = lo + long(i) * av[0]
-                hi = hi + long(j) * av[1]
+                lo = lo + i * av[0]
+                hi = hi + j * av[1]
             elif op in UNITCODES:
                 lo = lo + 1
                 hi = hi + 1
             elif op == SUCCESS:
                 break
-        self.width = int(min(lo, sys.maxint)), int(min(hi, sys.maxint))
+        self.width = min(lo, MAXREPEAT - 1), min(hi, MAXREPEAT)
         return self.width
 
 class Tokenizer: