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.
This commit is contained in:
Serhiy Storchaka 2013-08-19 22:50:54 +03:00
parent 4d98ca9ff6
commit 9d96542b6d
1 changed files with 4 additions and 4 deletions

View File

@ -148,7 +148,7 @@ class SubPattern:
REPEATCODES = (MIN_REPEAT, MAX_REPEAT) REPEATCODES = (MIN_REPEAT, MAX_REPEAT)
for op, av in self.data: for op, av in self.data:
if op is BRANCH: if op is BRANCH:
i = sys.maxsize i = MAXREPEAT - 1
j = 0 j = 0
for av in av[1]: for av in av[1]:
l, h = av.getwidth() l, h = av.getwidth()
@ -166,14 +166,14 @@ class SubPattern:
hi = hi + j hi = hi + j
elif op in REPEATCODES: elif op in REPEATCODES:
i, j = av[2].getwidth() i, j = av[2].getwidth()
lo = lo + int(i) * av[0] lo = lo + i * av[0]
hi = hi + int(j) * av[1] hi = hi + j * av[1]
elif op in UNITCODES: elif op in UNITCODES:
lo = lo + 1 lo = lo + 1
hi = hi + 1 hi = hi + 1
elif op == SUCCESS: elif op == SUCCESS:
break break
self.width = int(min(lo, sys.maxsize)), int(min(hi, sys.maxsize)) self.width = min(lo, MAXREPEAT - 1), min(hi, MAXREPEAT)
return self.width return self.width
class Tokenizer: class Tokenizer: