summaryrefslogtreecommitdiffstats
path: root/Python/compile.c
diff options
context:
space:
mode:
authorNeal Norwitz <nnorwitz@gmail.com>2006-08-21 19:47:08 (GMT)
committerNeal Norwitz <nnorwitz@gmail.com>2006-08-21 19:47:08 (GMT)
commit4f096d948797cabbe717197faf4d979d68badd0b (patch)
treeecba29cf8fafc590b7a3fb8cfa1f6a911534d3da /Python/compile.c
parent076d1e0c0b1858a9086c63c237cbe13691231b0f (diff)
downloadcpython-4f096d948797cabbe717197faf4d979d68badd0b.zip
cpython-4f096d948797cabbe717197faf4d979d68badd0b.tar.gz
cpython-4f096d948797cabbe717197faf4d979d68badd0b.tar.bz2
Patch #1542451: disallow continue anywhere under a finally
I'm undecided if this should be backported to 2.5 or 2.5.1. Armin suggested to wait (I'm of the same opinion). Thomas W thinks it's fine to go in 2.5.
Diffstat (limited to 'Python/compile.c')
-rw-r--r--Python/compile.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/Python/compile.c b/Python/compile.c
index 5aaf809..a03de0d 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -1682,6 +1682,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)
@@ -1693,15 +1695,18 @@ 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 continue anywhere under a finally
+ even if hidden in a sub-try or except. */
+ 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;