summaryrefslogtreecommitdiffstats
path: root/Modules/_sre.c
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2012-12-29 21:41:08 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2012-12-29 21:41:08 (GMT)
commitac1069387e8e970b52abb4a72c3f13cc933e3a86 (patch)
treee96993c35ea38128fc05d2dd47fd0fece1a7e18f /Modules/_sre.c
parent9edccb47db7683031e76f02e659e637cf04ba2d7 (diff)
parentc1b59d455261de2d18fb3f5005958b4411d6b314 (diff)
downloadcpython-ac1069387e8e970b52abb4a72c3f13cc933e3a86.zip
cpython-ac1069387e8e970b52abb4a72c3f13cc933e3a86.tar.gz
cpython-ac1069387e8e970b52abb4a72c3f13cc933e3a86.tar.bz2
Issue #16688: Fix backreferences did make case-insensitive regex fail on non-ASCII strings.
Patch by Matthew Barnett.
Diffstat (limited to 'Modules/_sre.c')
-rw-r--r--Modules/_sre.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/Modules/_sre.c b/Modules/_sre.c
index 8349e1a..24eb4dd 100644
--- a/Modules/_sre.c
+++ b/Modules/_sre.c
@@ -492,7 +492,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) / state->charsize && maxcount != 65535)
end = ptr + maxcount*state->charsize;
switch (pattern[0]) {
@@ -583,7 +583,7 @@ SRE_INFO(SRE_STATE* state, SRE_CODE* pattern)
Py_ssize_t i;
/* check minimal length */
- if (pattern[3] && (end - ptr) < pattern[3])
+ if (pattern[3] && (end - ptr)/state->charsize < pattern[3])
return 0;
/* check known prefix */
@@ -801,7 +801,7 @@ entrance:
/* <INFO> <1=skip> <2=flags> <3=min> ... */
if (ctx->pattern[3] && (end - ctx->ptr)/state->charsize < ctx->pattern[3]) {
TRACE(("reject (got %d chars, need %d)\n",
- (end - ctx->ptr), ctx->pattern[3]));
+ (end - ctx->ptr)/state->charsize, ctx->pattern[3]));
RETURN_FAILURE;
}
ctx->pattern += ctx->pattern[1] + 1;
@@ -1329,9 +1329,10 @@ entrance:
RETURN_FAILURE;
while (p < e) {
if (ctx->ptr >= end ||
- state->lower(SRE_CHARGET(state, ctx->ptr, 0)) != state->lower(*p))
+ state->lower(SRE_CHARGET(state, ctx->ptr, 0)) !=
+ state->lower(SRE_CHARGET(state, p, 0)))
RETURN_FAILURE;
- p++;
+ p += state->charsize;
ctx->ptr += state->charsize;
}
}