aboutsummaryrefslogtreecommitdiff
path: root/miscutils/bc.c
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2019-01-03 23:34:36 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2019-01-03 23:34:36 +0100
commit96b5ec10fb8abdb8050a6af87330e6cf3d881d5a (patch)
tree8fbc53fb1f7057170415adf6516319dcba2e7cdc /miscutils/bc.c
parentae6c44ea15f4b73e8e5532f6392d1e6ce8c087e7 (diff)
downloadbusybox-w32-96b5ec10fb8abdb8050a6af87330e6cf3d881d5a.tar.gz
busybox-w32-96b5ec10fb8abdb8050a6af87330e6cf3d881d5a.tar.bz2
busybox-w32-96b5ec10fb8abdb8050a6af87330e6cf3d881d5a.zip
bc: fix "...; return}" to work, disallow "return ()"
function old new delta zbc_parse_expr 24 1865 +1841 zbc_parse_stmt_possibly_auto 1425 1413 -12 bc_parse_expr_empty_ok 1843 - -1843 ------------------------------------------------------------------------------ (add/remove: 0/1 grow/shrink: 1/1 up/down: 1841/-1855) Total: -14 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'miscutils/bc.c')
-rw-r--r--miscutils/bc.c13
1 files changed, 5 insertions, 8 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c
index e5726ca40..6d8e2d991 100644
--- a/miscutils/bc.c
+++ b/miscutils/bc.c
@@ -4121,18 +4121,15 @@ static BC_STATUS zbc_parse_return(void)
4121 if (s) RETURN_STATUS(s); 4121 if (s) RETURN_STATUS(s);
4122 4122
4123 t = p->lex; 4123 t = p->lex;
4124 if (t == XC_LEX_NLINE || t == BC_LEX_SCOLON) 4124 if (t == XC_LEX_NLINE || t == BC_LEX_SCOLON || t == BC_LEX_RBRACE)
4125 xc_parse_push(BC_INST_RET0); 4125 xc_parse_push(BC_INST_RET0);
4126 else { 4126 else {
4127 bool paren = (t == BC_LEX_LPAREN); 4127 s = zbc_parse_expr(0);
4128 s = bc_parse_expr_empty_ok(0);
4129 if (s == BC_STATUS_PARSE_EMPTY_EXP) {
4130 xc_parse_push(BC_INST_RET0);
4131 s = zxc_lex_next();
4132 }
4133 if (s) RETURN_STATUS(s); 4128 if (s) RETURN_STATUS(s);
4134 4129
4135 if (!paren || p->lex_last != BC_LEX_RPAREN) { 4130 if (t != BC_LEX_LPAREN // "return EXPR", no ()
4131 || p->lex_last != BC_LEX_RPAREN // example: "return (a) + b"
4132 ) {
4136 s = zbc_POSIX_requires("parentheses around return expressions"); 4133 s = zbc_POSIX_requires("parentheses around return expressions");
4137 if (s) RETURN_STATUS(s); 4134 if (s) RETURN_STATUS(s);
4138 } 4135 }