[Python-checkins] cpython (2.7): Issue #18647: Correctly bound calculated min/max width of a subexpression.
serhiy.storchaka
python-checkins at python.org
Mon Aug 19 22:30:28 CEST 2013
http://hg.python.org/cpython/rev/d10c287c200c
changeset: 85270:d10c287c200c
branch: 2.7
parent: 85265:5d691723bfbd
user: Serhiy Storchaka <storchaka at gmail.com>
date: Mon Aug 19 22:53:46 2013 +0300
summary:
Issue #18647: Correctly bound calculated min/max width of a subexpression.
Now max width is MAXREPEAT on 32- and 64-bit platforms when one of
subexpressions is unbounded repetition.
files:
Lib/sre_parse.py | 10 +++++-----
1 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/Lib/sre_parse.py b/Lib/sre_parse.py
--- a/Lib/sre_parse.py
+++ b/Lib/sre_parse.py
@@ -142,12 +142,12 @@
# 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 @@
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:
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list