aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2023-06-30 19:16:41 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2023-06-30 19:16:41 +0200
commit38f769ab4e5f6cd2ffab88300ddaddef3aac3345 (patch)
tree75791824e2228d553737d0ee1e121a9e60490690
parent6a0ba673820cb6880e2f93f739de7d16d45d2b26 (diff)
downloadbusybox-w32-38f769ab4e5f6cd2ffab88300ddaddef3aac3345.tar.gz
busybox-w32-38f769ab4e5f6cd2ffab88300ddaddef3aac3345.tar.bz2
busybox-w32-38f769ab4e5f6cd2ffab88300ddaddef3aac3345.zip
shell/math: code shrink
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@googlemail.com>
-rw-r--r--shell/math.c11
1 files 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_
369 369
370 if (math_state->evaluation_disabled) { 370 if (math_state->evaluation_disabled) {
371 dbg("binary op %02x skipped", op); 371 dbg("binary op %02x skipped", op);
372 goto ret_NULL; 372 return NULL;
373 /* bash 5.2.12 does not execute "2/0" in disabled 373 /* bash 5.2.12 does not execute "2/0" in disabled
374 * branches of ?: (and thus does not complain), 374 * branches of ?: (and thus does not complain),
375 * but complains about negative exp: "2**-1". 375 * 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_
452 452
453 if (math_state->evaluation_disabled) { 453 if (math_state->evaluation_disabled) {
454 dbg("unary op %02x skipped", op); 454 dbg("unary op %02x skipped", op);
455 goto ret_NULL; 455 return NULL;
456 } 456 }
457 457
458 if (is_assign_op(op)) { 458 if (is_assign_op(op)) {
@@ -598,15 +598,18 @@ static arith_t strto_arith_t(const char *nptr, char **endptr)
598 return parse_with_base(nptr, endptr, base); 598 return parse_with_base(nptr, endptr, base);
599 } 599 }
600 600
601 /* base is 1..9 here */
602
601 if (nptr[1] == '#') { 603 if (nptr[1] == '#') {
602 if (base > 1) 604 if (base > 1)
603 return parse_with_base(nptr + 2, endptr, base); 605 return parse_with_base(nptr + 2, endptr, base);
604 /* else: bash says "invalid arithmetic base" */ 606 /* else: "1#NN", bash says "invalid arithmetic base" */
605 } 607 }
606 608
607 if (isdigit(nptr[1]) && nptr[2] == '#') { 609 if (isdigit(nptr[1]) && nptr[2] == '#') {
608 base = 10 * base + (nptr[1] - '0'); 610 base = 10 * base + (nptr[1] - '0');
609 if (base >= 2 && base <= 64) 611 /* base is at least 10 here */
612 if (base <= 64)
610 return parse_with_base(nptr + 3, endptr, base); 613 return parse_with_base(nptr + 3, endptr, base);
611 /* else: bash says "invalid arithmetic base" */ 614 /* else: bash says "invalid arithmetic base" */
612 } 615 }