Patch #1542451: fix crash with continue in nested try/finally

(backport from rev. 51439)
This commit is contained in:
Georg Brandl 2006-10-08 07:06:29 +00:00
parent 2c8851e614
commit 74284b9606
3 changed files with 96 additions and 4 deletions

View file

@ -2288,6 +2288,8 @@ static int
compiler_continue(struct compiler *c)
{
static const char LOOP_ERROR_MSG[] = "'continue' not properly in loop";
static const char IN_FINALLY_ERROR_MSG[] =
"'continue' not supported inside 'finally' clause";
int i;
if (!c->u->u_nfblocks)
@ -2299,15 +2301,19 @@ compiler_continue(struct compiler *c)
break;
case EXCEPT:
case FINALLY_TRY:
while (--i >= 0 && c->u->u_fblock[i].fb_type != LOOP)
;
while (--i >= 0 && c->u->u_fblock[i].fb_type != LOOP) {
/* Prevent try: ... finally:
try: continue ... or
try: ... except: continue */
if (c->u->u_fblock[i].fb_type == FINALLY_END)
return compiler_error(c, IN_FINALLY_ERROR_MSG);
}
if (i == -1)
return compiler_error(c, LOOP_ERROR_MSG);
ADDOP_JABS(c, CONTINUE_LOOP, c->u->u_fblock[i].fb_block);
break;
case FINALLY_END:
return compiler_error(c,
"'continue' not supported inside 'finally' clause");
return compiler_error(c, IN_FINALLY_ERROR_MSG);
}
return 1;