Skip to content

Commit f738245

Browse files
committed
1. add asserts
If no error occurs, when the top level call returns: - the stack should be empty - state->repeat should be NULL This prevents the following commits to wreck the stack.
1 parent 8a1bab9 commit f738245

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
re module, fix a few bugs about capturing group. In rare cases, capturing
2+
group gets an incorrect string. Patch by Ma Lin.

Modules/sre_lib.h

+10-2
Original file line numberDiff line numberDiff line change
@@ -1310,8 +1310,15 @@ SRE(match)(SRE_STATE* state, SRE_CODE* pattern, int toplevel)
13101310
ctx_pos = ctx->last_ctx_pos;
13111311
jump = ctx->jump;
13121312
DATA_POP_DISCARD(ctx);
1313-
if (ctx_pos == -1)
1313+
if (ctx_pos == -1) {
1314+
#ifdef Py_DEBUG
1315+
if (ctx->toplevel && ret >= 0) {
1316+
assert(state->repeat == NULL);
1317+
assert(state->data_stack_base == 0);
1318+
}
1319+
#endif
13141320
return ret;
1321+
}
13151322
DATA_LOOKUP_AT(SRE(match_context), ctx, ctx_pos);
13161323

13171324
switch (jump) {
@@ -1360,7 +1367,8 @@ SRE(match)(SRE_STATE* state, SRE_CODE* pattern, int toplevel)
13601367
break;
13611368
}
13621369

1363-
return ret; /* should never get here */
1370+
/* should never get here */
1371+
Py_UNREACHABLE();
13641372
}
13651373

13661374
/* need to reset capturing groups between two SRE(match) callings in loops */

0 commit comments

Comments
 (0)