From a2e25e7940d2061c0a9298f4ef8347c6f174d42d Mon Sep 17 00:00:00 2001 From: James Turner Date: Tue, 23 Jul 2013 21:58:38 +0100 Subject: [PATCH] Fix for #587, crash on break/continue. Look for use of break/continue outside of a loop context, and report a parser error instead of crashed. Thanks to Philosopher for the patch. --- simgear/nasal/codegen.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/simgear/nasal/codegen.c b/simgear/nasal/codegen.c index fa2ddc22..8636fbb9 100644 --- a/simgear/nasal/codegen.c +++ b/simgear/nasal/codegen.c @@ -485,6 +485,11 @@ static int tokMatch(struct Token* a, struct Token* b) static void genBreakContinue(struct Parser* p, struct Token* t) { int levels = 1, loop = -1, bp, cp, i; + // http://code.google.com/p/flightgear-bugs/issues/detail?id=587 + // Make sure we are inside of a loop + if(p->cg->loopTop <= 0) + naParseError(p, "break/continue outside of a valid loop", t->line); + if(RIGHT(t)) { if(RIGHT(t)->type != TOK_SYMBOL) naParseError(p, "bad break/continue label", t->line); -- 2.39.5