Get rid of signed/unsigned comparaison in _sre.c
Fix compilation warnings on Windows (Visual C++) like: "_sre.c(3121): warning C4018: '>' : signed/unsigned mismatch". _validate_outer() ensures that groups >= 0, so _validate_inner() can cast groups to size_t.
This commit is contained in:
parent
36a5a062dc
commit
1fa174a418
|
@ -795,7 +795,7 @@ entrance:
|
||||||
if (ctx->pattern[0] == SRE_OP_INFO) {
|
if (ctx->pattern[0] == SRE_OP_INFO) {
|
||||||
/* optimization info block */
|
/* optimization info block */
|
||||||
/* <INFO> <1=skip> <2=flags> <3=min> ... */
|
/* <INFO> <1=skip> <2=flags> <3=min> ... */
|
||||||
if (ctx->pattern[3] && (end - ctx->ptr)/state->charsize < ctx->pattern[3]) {
|
if (ctx->pattern[3] && (Py_uintptr_t)(end - ctx->ptr)/state->charsize < ctx->pattern[3]) {
|
||||||
TRACE(("reject (got %d chars, need %d)\n",
|
TRACE(("reject (got %d chars, need %d)\n",
|
||||||
(end - ctx->ptr)/state->charsize, ctx->pattern[3]));
|
(end - ctx->ptr)/state->charsize, ctx->pattern[3]));
|
||||||
RETURN_FAILURE;
|
RETURN_FAILURE;
|
||||||
|
@ -2762,7 +2762,7 @@ _compile(PyObject* self_, PyObject* args)
|
||||||
skip = *code; \
|
skip = *code; \
|
||||||
VTRACE(("%lu (skip to %p)\n", \
|
VTRACE(("%lu (skip to %p)\n", \
|
||||||
(unsigned long)skip, code+skip)); \
|
(unsigned long)skip, code+skip)); \
|
||||||
if (skip-adj > end-code) \
|
if (skip-adj > (Py_uintptr_t)(end - code)) \
|
||||||
FAIL; \
|
FAIL; \
|
||||||
code++; \
|
code++; \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
@ -2795,7 +2795,7 @@ _validate_charset(SRE_CODE *code, SRE_CODE *end)
|
||||||
|
|
||||||
case SRE_OP_CHARSET:
|
case SRE_OP_CHARSET:
|
||||||
offset = 32/sizeof(SRE_CODE); /* 32-byte bitmap */
|
offset = 32/sizeof(SRE_CODE); /* 32-byte bitmap */
|
||||||
if (offset > end-code)
|
if (offset > (Py_uintptr_t)(end - code))
|
||||||
FAIL;
|
FAIL;
|
||||||
code += offset;
|
code += offset;
|
||||||
break;
|
break;
|
||||||
|
@ -2803,7 +2803,7 @@ _validate_charset(SRE_CODE *code, SRE_CODE *end)
|
||||||
case SRE_OP_BIGCHARSET:
|
case SRE_OP_BIGCHARSET:
|
||||||
GET_ARG; /* Number of blocks */
|
GET_ARG; /* Number of blocks */
|
||||||
offset = 256/sizeof(SRE_CODE); /* 256-byte table */
|
offset = 256/sizeof(SRE_CODE); /* 256-byte table */
|
||||||
if (offset > end-code)
|
if (offset > (Py_uintptr_t)(end - code))
|
||||||
FAIL;
|
FAIL;
|
||||||
/* Make sure that each byte points to a valid block */
|
/* Make sure that each byte points to a valid block */
|
||||||
for (i = 0; i < 256; i++) {
|
for (i = 0; i < 256; i++) {
|
||||||
|
@ -2812,7 +2812,7 @@ _validate_charset(SRE_CODE *code, SRE_CODE *end)
|
||||||
}
|
}
|
||||||
code += offset;
|
code += offset;
|
||||||
offset = arg * 32/sizeof(SRE_CODE); /* 32-byte bitmap times arg */
|
offset = arg * 32/sizeof(SRE_CODE); /* 32-byte bitmap times arg */
|
||||||
if (offset > end-code)
|
if (offset > (Py_uintptr_t)(end - code))
|
||||||
FAIL;
|
FAIL;
|
||||||
code += offset;
|
code += offset;
|
||||||
break;
|
break;
|
||||||
|
@ -2875,7 +2875,7 @@ _validate_inner(SRE_CODE *code, SRE_CODE *end, Py_ssize_t groups)
|
||||||
sre_match() code is robust even if they don't, and the worst
|
sre_match() code is robust even if they don't, and the worst
|
||||||
you can get is nonsensical match results. */
|
you can get is nonsensical match results. */
|
||||||
GET_ARG;
|
GET_ARG;
|
||||||
if (arg > 2*groups+1) {
|
if (arg > 2 * (size_t)groups + 1) {
|
||||||
VTRACE(("arg=%d, groups=%d\n", (int)arg, (int)groups));
|
VTRACE(("arg=%d, groups=%d\n", (int)arg, (int)groups));
|
||||||
FAIL;
|
FAIL;
|
||||||
}
|
}
|
||||||
|
@ -2963,11 +2963,11 @@ _validate_inner(SRE_CODE *code, SRE_CODE *end, Py_ssize_t groups)
|
||||||
GET_ARG; prefix_len = arg;
|
GET_ARG; prefix_len = arg;
|
||||||
GET_ARG;
|
GET_ARG;
|
||||||
/* Here comes the prefix string */
|
/* Here comes the prefix string */
|
||||||
if (prefix_len > newcode-code)
|
if (prefix_len > (Py_uintptr_t)(newcode - code))
|
||||||
FAIL;
|
FAIL;
|
||||||
code += prefix_len;
|
code += prefix_len;
|
||||||
/* And here comes the overlap table */
|
/* And here comes the overlap table */
|
||||||
if (prefix_len > newcode-code)
|
if (prefix_len > (Py_uintptr_t)(newcode - code))
|
||||||
FAIL;
|
FAIL;
|
||||||
/* Each overlap value should be < prefix_len */
|
/* Each overlap value should be < prefix_len */
|
||||||
for (i = 0; i < prefix_len; i++) {
|
for (i = 0; i < prefix_len; i++) {
|
||||||
|
@ -3058,7 +3058,7 @@ _validate_inner(SRE_CODE *code, SRE_CODE *end, Py_ssize_t groups)
|
||||||
case SRE_OP_GROUPREF:
|
case SRE_OP_GROUPREF:
|
||||||
case SRE_OP_GROUPREF_IGNORE:
|
case SRE_OP_GROUPREF_IGNORE:
|
||||||
GET_ARG;
|
GET_ARG;
|
||||||
if (arg >= groups)
|
if (arg >= (size_t)groups)
|
||||||
FAIL;
|
FAIL;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -3067,7 +3067,7 @@ _validate_inner(SRE_CODE *code, SRE_CODE *end, Py_ssize_t groups)
|
||||||
'group' is either an integer group number or a group name,
|
'group' is either an integer group number or a group name,
|
||||||
'then' and 'else' are sub-regexes, and 'else' is optional. */
|
'then' and 'else' are sub-regexes, and 'else' is optional. */
|
||||||
GET_ARG;
|
GET_ARG;
|
||||||
if (arg >= groups)
|
if (arg >= (size_t)groups)
|
||||||
FAIL;
|
FAIL;
|
||||||
GET_SKIP_ADJ(1);
|
GET_SKIP_ADJ(1);
|
||||||
code--; /* The skip is relative to the first arg! */
|
code--; /* The skip is relative to the first arg! */
|
||||||
|
@ -3096,7 +3096,7 @@ _validate_inner(SRE_CODE *code, SRE_CODE *end, Py_ssize_t groups)
|
||||||
to allow arbitrary jumps anywhere in the code; so we just look
|
to allow arbitrary jumps anywhere in the code; so we just look
|
||||||
for a JUMP opcode preceding our skip target.
|
for a JUMP opcode preceding our skip target.
|
||||||
*/
|
*/
|
||||||
if (skip >= 3 && skip-3 < end-code &&
|
if (skip >= 3 && skip-3 < (Py_uintptr_t)(end - code) &&
|
||||||
code[skip-3] == SRE_OP_JUMP)
|
code[skip-3] == SRE_OP_JUMP)
|
||||||
{
|
{
|
||||||
VTRACE(("both then and else parts present\n"));
|
VTRACE(("both then and else parts present\n"));
|
||||||
|
|
Loading…
Reference in New Issue