[git commit] bc: disallow empty statement as function body

Denys Vlasenko vda.linux at googlemail.com
Sun Dec 16 19:46:15 UTC 2018


commit: https://git.busybox.net/busybox/commit/?id=cb18b546f7ee9d1c9315c7357ab620e55f0fa8f3
branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master

	$ bc
	define z() <cr>
	<cr>
	bc: no statement after 'define'

function                                             old     new   delta
zbc_parse_stmt_possibly_auto                        2239    2245      +6
zbc_vm_process                                       589     594      +5
zbc_parse_stmt_fail_if_bare_NLINE                     25      28      +3
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/0 up/down: 14/0)               Total: 14 bytes
   text	   data	    bss	    dec	    hex	filename
 982216	    485	   7296	 989997	  f1b2d	busybox_old
 982237	    485	   7296	 990018	  f1b42	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
 miscutils/bc.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/miscutils/bc.c b/miscutils/bc.c
index ed2497c4c..2dc64dbc6 100644
--- a/miscutils/bc.c
+++ b/miscutils/bc.c
@@ -3677,14 +3677,14 @@ static BC_STATUS zbc_parse_stmt(BcParse *p)
 # define zbc_parse_stmt(...) (zbc_parse_stmt(__VA_ARGS__), BC_STATUS_SUCCESS)
 #endif
 
-static BC_STATUS zbc_parse_stmt_fail_if_bare_NLINE(BcParse *p, const char *after_X)
+static BC_STATUS zbc_parse_stmt_fail_if_bare_NLINE(BcParse *p, bool auto_allowed, const char *after_X)
 {
 	if (p->l.t.t == BC_LEX_NLINE)
 		RETURN_STATUS(bc_error_fmt("no statement after '%s'", after_X));
-	RETURN_STATUS(zbc_parse_stmt(p));
+	RETURN_STATUS(zbc_parse_stmt_possibly_auto(p, auto_allowed));
 }
 #if ERRORS_ARE_FATAL
-# define zbc_parse_stmt_fail_if_bare_NLINE((...) (zbc_parse_stmt_fail_if_bare_NLINE((__VA_ARGS__), BC_STATUS_SUCCESS)
+# define zbc_parse_stmt_fail_if_bare_NLINE(...) (zbc_parse_stmt_fail_if_bare_NLINE(__VA_ARGS__), BC_STATUS_SUCCESS)
 #endif
 
 static void bc_parse_operator(BcParse *p, BcLexType type, size_t start,
@@ -4151,7 +4151,7 @@ static BC_STATUS zbc_parse_if(BcParse *p)
 	bc_vec_push(&p->exits, &ip);
 	bc_vec_push(&p->func->labels, &ip.idx);
 
-	s = zbc_parse_stmt_fail_if_bare_NLINE(p, "if");
+	s = zbc_parse_stmt_fail_if_bare_NLINE(p, false, "if");
 	if (s) RETURN_STATUS(s);
 
 	dbg_lex("%s:%d in if after stmt: p->l.t.t:%d", __func__, __LINE__, p->l.t.t);
@@ -4230,7 +4230,7 @@ static BC_STATUS zbc_parse_while(BcParse *p)
 	bc_parse_push(p, BC_INST_JUMP_ZERO);
 	bc_parse_pushIndex(p, ip.idx);
 
-	s = zbc_parse_stmt_fail_if_bare_NLINE(p, "while");
+	s = zbc_parse_stmt_fail_if_bare_NLINE(p, false, "while");
 	if (s) RETURN_STATUS(s);
 
 	n = *((size_t *) bc_vec_top(&p->conds));
@@ -4334,7 +4334,7 @@ static BC_STATUS zbc_parse_for(BcParse *p)
 	s = zbc_lex_next_and_skip_NLINE(&p->l);
 	if (s) RETURN_STATUS(s);
 
-	s = zbc_parse_stmt_fail_if_bare_NLINE(p, "for");
+	s = zbc_parse_stmt_fail_if_bare_NLINE(p, false, "for");
 	if (s) RETURN_STATUS(s);
 
 	n = *((size_t *) bc_vec_top(&p->conds));
@@ -4468,7 +4468,7 @@ static BC_STATUS zbc_parse_funcdef(BcParse *p)
 //TODO: GNU bc requires a {} block even if function body has single stmt, enforce this?
 
 	p->in_funcdef++; // to determine whether "return" stmt is allowed, and such
-	s = zbc_parse_stmt_possibly_auto(p, true);
+	s = zbc_parse_stmt_fail_if_bare_NLINE(p, true, "define");
 	p->in_funcdef--;
 	if (s) RETURN_STATUS(s);
 


More information about the busybox-cvs mailing list