[git commit] shell/math: code shrink

Denys Vlasenko vda.linux at googlemail.com
Fri Jun 30 17:16:41 UTC 2023


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

function                                             old     new   delta
arith_apply                                          999     996      -3
evaluate_string                                     1295    1291      -4
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-7)               Total: -7 bytes

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

diff --git a/shell/math.c b/shell/math.c
index 5b996703e..beb89d140 100644
--- a/shell/math.c
+++ b/shell/math.c
@@ -369,7 +369,7 @@ arith_apply(arith_state_t *math_state, operator op, var_or_num_t *numstack, var_
 
 		if (math_state->evaluation_disabled) {
 			dbg("binary op %02x skipped", op);
-			goto ret_NULL;
+			return NULL;
 			/* bash 5.2.12 does not execute "2/0" in disabled
 			 * branches of ?: (and thus does not complain),
 			 * but complains about negative exp: "2**-1".
@@ -452,7 +452,7 @@ arith_apply(arith_state_t *math_state, operator op, var_or_num_t *numstack, var_
 
 	if (math_state->evaluation_disabled) {
 		dbg("unary op %02x skipped", op);
-		goto ret_NULL;
+		return NULL;
 	}
 
 	if (is_assign_op(op)) {
@@ -598,15 +598,18 @@ static arith_t strto_arith_t(const char *nptr, char **endptr)
 		return parse_with_base(nptr, endptr, base);
 	}
 
+	/* base is 1..9 here */
+
 	if (nptr[1] == '#') {
 		if (base > 1)
 			return parse_with_base(nptr + 2, endptr, base);
-		/* else: bash says "invalid arithmetic base" */
+		/* else: "1#NN", bash says "invalid arithmetic base" */
 	}
 
 	if (isdigit(nptr[1]) && nptr[2] == '#') {
 		base = 10 * base + (nptr[1] - '0');
-		if (base >= 2 && base <= 64)
+		/* base is at least 10 here */
+		if (base <= 64)
 			return parse_with_base(nptr + 3, endptr, base);
 		/* else: bash says "invalid arithmetic base" */
 	}


More information about the busybox-cvs mailing list