summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--editors/awk.c6
-rwxr-xr-xtestsuite/awk.tests9
2 files changed, 6 insertions, 9 deletions
diff --git a/editors/awk.c b/editors/awk.c
index 2f8a18c8e..607d69487 100644
--- a/editors/awk.c
+++ b/editors/awk.c
@@ -1671,16 +1671,18 @@ static void chain_group(void)
case OC_BREAK:
debug_printf_parse("%s: OC_BREAK\n", __func__);
n = chain_node(OC_EXEC);
+ if (!break_ptr)
+ syntax_error("'break' not in a loop");
n->a.n = break_ptr;
-//TODO: if break_ptr is NULL, syntax error (not in the loop)?
chain_expr(t_info);
break;
case OC_CONTINUE:
debug_printf_parse("%s: OC_CONTINUE\n", __func__);
n = chain_node(OC_EXEC);
+ if (!continue_ptr)
+ syntax_error("'continue' not in a loop");
n->a.n = continue_ptr;
-//TODO: if continue_ptr is NULL, syntax error (not in the loop)?
chain_expr(t_info);
break;
diff --git a/testsuite/awk.tests b/testsuite/awk.tests
index 3cddb4dd4..f53b1efe2 100755
--- a/testsuite/awk.tests
+++ b/testsuite/awk.tests
@@ -379,19 +379,14 @@ testing "awk -e and ARGC" \
""
SKIP=
-# The examples are in fact not valid awk programs (break/continue
-# can only be used inside loops).
-# But we do accept them outside of loops.
-# We had a bug with misparsing "break ; else" sequence.
-# Test that *that* bug is fixed, using simplest possible scripts:
testing "awk break" \
"awk -f - 2>&1; echo \$?" \
- "0\n" \
+ "awk: -:1: 'break' not in a loop\n1\n" \
"" \
'BEGIN { if (1) break; else a = 1 }'
testing "awk continue" \
"awk -f - 2>&1; echo \$?" \
- "0\n" \
+ "awk: -:1: 'continue' not in a loop\n1\n" \
"" \
'BEGIN { if (1) continue; else a = 1 }'