summaryrefslogtreecommitdiffstats
path: root/Modules/_sre.c
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2013-02-16 14:47:47 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2013-02-16 14:47:47 (GMT)
commit70ca0210e8958d2665541ddd38fce2965075674e (patch)
treef24e31538d932eebe73bdb07079096cabeb0e50a /Modules/_sre.c
parentb19ed57d8d75b1183193558a9880db44b95157b3 (diff)
downloadcpython-70ca0210e8958d2665541ddd38fce2965075674e.zip
cpython-70ca0210e8958d2665541ddd38fce2965075674e.tar.gz
cpython-70ca0210e8958d2665541ddd38fce2965075674e.tar.bz2
Issue #13169: The maximal repetition number in a regular expression has been
increased from 65534 to 2147483647 (on 32-bit platform) or 4294967294 (on 64-bit).
Diffstat (limited to 'Modules/_sre.c')
-rw-r--r--Modules/_sre.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/Modules/_sre.c b/Modules/_sre.c
index 88bbf6a..4421eae 100644
--- a/Modules/_sre.c
+++ b/Modules/_sre.c
@@ -517,7 +517,7 @@ SRE_COUNT(SRE_STATE* state, SRE_CODE* pattern, Py_ssize_t maxcount)
Py_ssize_t i;
/* adjust end */
- if (maxcount < end - ptr && maxcount != 65535)
+ if (maxcount < end - ptr && maxcount != SRE_MAXREPEAT)
end = ptr + maxcount;
switch (pattern[0]) {
@@ -1132,7 +1132,7 @@ entrance:
} else {
/* general case */
LASTMARK_SAVE();
- while ((Py_ssize_t)ctx->pattern[2] == 65535
+ while ((Py_ssize_t)ctx->pattern[2] == SRE_MAXREPEAT
|| ctx->count <= (Py_ssize_t)ctx->pattern[2]) {
state->ptr = ctx->ptr;
DO_JUMP(JUMP_MIN_REPEAT_ONE,jump_min_repeat_one,
@@ -1218,7 +1218,7 @@ entrance:
}
if ((ctx->count < ctx->u.rep->pattern[2] ||
- ctx->u.rep->pattern[2] == 65535) &&
+ ctx->u.rep->pattern[2] == SRE_MAXREPEAT) &&
state->ptr != ctx->u.rep->last_ptr) {
/* we may have enough matches, but if we can
match another item, do so */
@@ -1296,7 +1296,7 @@ entrance:
LASTMARK_RESTORE();
if (ctx->count >= ctx->u.rep->pattern[2]
- && ctx->u.rep->pattern[2] != 65535)
+ && ctx->u.rep->pattern[2] != SRE_MAXREPEAT)
RETURN_FAILURE;
ctx->u.rep->count = ctx->count;
@@ -3072,7 +3072,7 @@ _validate_inner(SRE_CODE *code, SRE_CODE *end, Py_ssize_t groups)
GET_ARG; max = arg;
if (min > max)
FAIL;
- if (max > 65535)
+ if (max > SRE_MAXREPEAT)
FAIL;
if (!_validate_inner(code, code+skip-4, groups))
FAIL;
@@ -3091,7 +3091,7 @@ _validate_inner(SRE_CODE *code, SRE_CODE *end, Py_ssize_t groups)
GET_ARG; max = arg;
if (min > max)
FAIL;
- if (max > 65535)
+ if (max > SRE_MAXREPEAT)
FAIL;
if (!_validate_inner(code, code+skip-3, groups))
FAIL;
@@ -3979,6 +3979,12 @@ PyMODINIT_FUNC PyInit__sre(void)
Py_DECREF(x);
}
+ x = PyLong_FromUnsignedLong(SRE_MAXREPEAT);
+ if (x) {
+ PyDict_SetItemString(d, "MAXREPEAT", x);
+ Py_DECREF(x);
+ }
+
x = PyUnicode_FromString(copyright);
if (x) {
PyDict_SetItemString(d, "copyright", x);