[git commit] shell/math: trivial code shrink

Denys Vlasenko vda.linux at googlemail.com
Wed Jun 14 11:59:11 UTC 2023


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

function                                             old     new   delta
arith_apply                                         1143    1132     -11

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

diff --git a/shell/math.c b/shell/math.c
index 077aba848..c1bf324f8 100644
--- a/shell/math.c
+++ b/shell/math.c
@@ -321,9 +321,9 @@ arith_apply(arith_state_t *math_state, operator op, var_or_num_t *numstack, var_
 	if (op == TOK_CONDITIONAL_SEP) {
 		/* "expr1 ? expr2 : expr3" operation */
 		var_or_num_t *expr1 = &top_of_stack[-2];
-		if (expr1 < numstack) {
+		NUMPTR = expr1 + 1;
+		if (expr1 < numstack) /* Example: $((2:3)) */
 			return "malformed ?: operator";
-		}
 		err = arith_lookup_val(math_state, expr1);
 		if (err)
 			return err;
@@ -332,7 +332,6 @@ arith_apply(arith_state_t *math_state, operator op, var_or_num_t *numstack, var_
 		err = arith_lookup_val(math_state, top_of_stack);
 		if (err)
 			return err;
-		NUMPTR = expr1 + 1;
 		expr1->val = top_of_stack->val;
 		expr1->var_name = NULL;
 		return NULL;
@@ -343,7 +342,7 @@ arith_apply(arith_state_t *math_state, operator op, var_or_num_t *numstack, var_
 	if (PREC(op) < UNARYPREC) {
 		/* In binops a ~ b, variables are resolved left-to-right,
 		 * resolve top_of_stack[-1] _before_ resolving top_of_stack[0]
-		*/
+		 */
 		if (top_of_stack == numstack) /* need two arguments */
 			goto syntax_err;
 		/* Unless it is =, resolve top_of_stack[-1] name to value */


More information about the busybox-cvs mailing list