From 596439f6e8867edc046df4f87644c0ba8bbfef41 Mon Sep 17 00:00:00 2001 From: Demi Obenour Date: Mon, 6 Mar 2017 13:12:03 -0500 Subject: [PATCH] Correctly report out-of-scope gotos Bug was in `fscope_exit`: if a loop contains a break `gola_fixup` will not be called leaving unresolved labels undetected. This cannot cause problems for valid code because `parse_label` calls `gola_resolve` on each newly parsed label. Fixes #228. --- src/lj_parse.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/lj_parse.c b/src/lj_parse.c index b5b7b6b4..c5295124 100644 --- a/src/lj_parse.c +++ b/src/lj_parse.c @@ -1282,12 +1282,15 @@ static void fscope_end(FuncState *fs) MSize idx = gola_new(ls, NAME_BREAK, VSTACK_LABEL, fs->pc); ls->vtop = idx; /* Drop break label immediately. */ gola_resolve(ls, bl, idx); + } else { + /* need the fixup step to propagate the breaks. */ + gola_fixup(ls, bl); return; - } /* else: need the fixup step to propagate the breaks. */ - } else if (!(bl->flags & FSCOPE_GOLA)) { - return; + } + } + if ((bl->flags & FSCOPE_GOLA)) { + gola_fixup(ls, bl); } - gola_fixup(ls, bl); } /* Mark scope as having an upvalue. */