summaryrefslogtreecommitdiff
path: root/shell
diff options
context:
space:
mode:
authorDenys Vlasenko2023-06-30 19:16:41 +0200
committerDenys Vlasenko2023-06-30 19:16:41 +0200
commit38f769ab4e5f6cd2ffab88300ddaddef3aac3345 (patch)
tree75791824e2228d553737d0ee1e121a9e60490690 /shell
parent6a0ba673820cb6880e2f93f739de7d16d45d2b26 (diff)
downloadbusybox-38f769ab4e5f6cd2ffab88300ddaddef3aac3345.zip
busybox-38f769ab4e5f6cd2ffab88300ddaddef3aac3345.tar.gz
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>
Diffstat (limited to 'shell')
-rw-r--r--shell/math.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/shell/math.c b/shell/math.c
index 5b99670..beb89d1 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" */
}