diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2014-06-26 16:40:28 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2014-06-26 16:40:28 +0200 |
commit | 5f8daefb835687e428215f90d26fdf1f0206149d (patch) | |
tree | b42723b59183e1bcf6196b37b34113d5a843fabb | |
parent | 0b0ccd457016d6a4eaa3e79bd65a852ea7d4294b (diff) | |
download | busybox-w32-5f8daefb835687e428215f90d26fdf1f0206149d.tar.gz busybox-w32-5f8daefb835687e428215f90d26fdf1f0206149d.tar.bz2 busybox-w32-5f8daefb835687e428215f90d26fdf1f0206149d.zip |
awk: fix handling of "if ... break ; else ..." - closes 7226
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | editors/awk.c | 2 | ||||
-rwxr-xr-x | testsuite/awk.tests | 16 |
2 files changed, 18 insertions, 0 deletions
diff --git a/editors/awk.c b/editors/awk.c index d0e3781e7..f487163af 100644 --- a/editors/awk.c +++ b/editors/awk.c | |||
@@ -1540,12 +1540,14 @@ static void chain_group(void) | |||
1540 | debug_printf_parse("%s: OC_BREAK\n", __func__); | 1540 | debug_printf_parse("%s: OC_BREAK\n", __func__); |
1541 | n = chain_node(OC_EXEC); | 1541 | n = chain_node(OC_EXEC); |
1542 | n->a.n = break_ptr; | 1542 | n->a.n = break_ptr; |
1543 | chain_expr(t_info); | ||
1543 | break; | 1544 | break; |
1544 | 1545 | ||
1545 | case OC_CONTINUE: | 1546 | case OC_CONTINUE: |
1546 | debug_printf_parse("%s: OC_CONTINUE\n", __func__); | 1547 | debug_printf_parse("%s: OC_CONTINUE\n", __func__); |
1547 | n = chain_node(OC_EXEC); | 1548 | n = chain_node(OC_EXEC); |
1548 | n->a.n = continue_ptr; | 1549 | n->a.n = continue_ptr; |
1550 | chain_expr(t_info); | ||
1549 | break; | 1551 | break; |
1550 | 1552 | ||
1551 | /* delete, next, nextfile, return, exit */ | 1553 | /* delete, next, nextfile, return, exit */ |
diff --git a/testsuite/awk.tests b/testsuite/awk.tests index 132afc6a9..9e6952ffd 100755 --- a/testsuite/awk.tests +++ b/testsuite/awk.tests | |||
@@ -295,6 +295,22 @@ testing "awk -e and ARGC" \ | |||
295 | "" | 295 | "" |
296 | SKIP= | 296 | SKIP= |
297 | 297 | ||
298 | # The examples are in fact not valid awk programs (break/continue | ||
299 | # can only be used inside loops). | ||
300 | # But we do accept them outside of loops. | ||
301 | # We had a bug with misparsing "break ; else" sequence. | ||
302 | # Test that *that* bug is fixed, using simplest possible scripts: | ||
303 | testing "awk break" \ | ||
304 | "awk -f - 2>&1; echo \$?" \ | ||
305 | "0\n" \ | ||
306 | "" \ | ||
307 | 'BEGIN { if (1) break; else a = 1 }' | ||
308 | testing "awk continue" \ | ||
309 | "awk -f - 2>&1; echo \$?" \ | ||
310 | "0\n" \ | ||
311 | "" \ | ||
312 | 'BEGIN { if (1) continue; else a = 1 }' | ||
313 | |||
298 | # testing "description" "command" "result" "infile" "stdin" | 314 | # testing "description" "command" "result" "infile" "stdin" |
299 | 315 | ||
300 | exit $FAILCOUNT | 316 | exit $FAILCOUNT |