awk: fix handling of "if ... break ; else ..." - closes 7226
authorDenys Vlasenko <vda.linux@googlemail.com>
Thu, 26 Jun 2014 14:40:28 +0000 (16:40 +0200)
committerDenys Vlasenko <vda.linux@googlemail.com>
Thu, 26 Jun 2014 14:40:28 +0000 (16:40 +0200)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
editors/awk.c
testsuite/awk.tests

index d0e3781e751cb1b4a909499ce4965cf614c5e2cd..f487163af731e3b26d0cb7fca3601ff94200bd93 100644 (file)
@@ -1540,12 +1540,14 @@ static void chain_group(void)
                        debug_printf_parse("%s: OC_BREAK\n", __func__);
                        n = chain_node(OC_EXEC);
                        n->a.n = break_ptr;
+                       chain_expr(t_info);
                        break;
 
                case OC_CONTINUE:
                        debug_printf_parse("%s: OC_CONTINUE\n", __func__);
                        n = chain_node(OC_EXEC);
                        n->a.n = continue_ptr;
+                       chain_expr(t_info);
                        break;
 
                /* delete, next, nextfile, return, exit */
index 132afc6a94c27c37615effbffd7cc49ab775b8a2..9e6952ffd3c39fc5b300b984109470c4a079324b 100755 (executable)
@@ -295,6 +295,22 @@ 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" \
+       "" \
+       'BEGIN { if (1) break; else a = 1 }'
+testing "awk continue" \
+       "awk -f - 2>&1; echo \$?" \
+       "0\n" \
+       "" \
+       'BEGIN { if (1) continue; else a = 1 }'
+
 # testing "description" "command" "result" "infile" "stdin"
 
 exit $FAILCOUNT