From 96b5ec10fb8abdb8050a6af87330e6cf3d881d5a Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 3 Jan 2019 23:34:36 +0100 Subject: 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 --- miscutils/bc.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'miscutils/bc.c') 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) if (s) RETURN_STATUS(s); t = p->lex; - if (t == XC_LEX_NLINE || t == BC_LEX_SCOLON) + if (t == XC_LEX_NLINE || t == BC_LEX_SCOLON || t == BC_LEX_RBRACE) xc_parse_push(BC_INST_RET0); else { - bool paren = (t == BC_LEX_LPAREN); - s = bc_parse_expr_empty_ok(0); - if (s == BC_STATUS_PARSE_EMPTY_EXP) { - xc_parse_push(BC_INST_RET0); - s = zxc_lex_next(); - } + s = zbc_parse_expr(0); if (s) RETURN_STATUS(s); - if (!paren || p->lex_last != BC_LEX_RPAREN) { + if (t != BC_LEX_LPAREN // "return EXPR", no () + || p->lex_last != BC_LEX_RPAREN // example: "return (a) + b" + ) { s = zbc_POSIX_requires("parentheses around return expressions"); if (s) RETURN_STATUS(s); } -- cgit v1.2.3