summaryrefslogtreecommitdiff
path: root/shell/math.c
diff options
context:
space:
mode:
authorDenys Vlasenko2009-06-05 16:24:29 +0200
committerDenys Vlasenko2009-06-05 16:24:29 +0200
commit71016baf5524d739d1dd4d9110b111a7c3ddcaf9 (patch)
tree4d012db2dc2dd20e0956c0b188e52ab43059d2cc /shell/math.c
parent0f952c249e30834a3ee5cd821e9afc3197b05f9c (diff)
downloadbusybox-71016baf5524d739d1dd4d9110b111a7c3ddcaf9.zip
busybox-71016baf5524d739d1dd4d9110b111a7c3ddcaf9.tar.gz
printf: accept negative numbers for %x; sh: overflowed numbers are 0
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell/math.c')
-rw-r--r--shell/math.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/shell/math.c b/shell/math.c
index cc298bd..d75bcae 100644
--- a/shell/math.c
+++ b/shell/math.c
@@ -562,7 +562,11 @@ arith(const char *expr, int *perrcode, a_e_h_t *math_hooks)
}
if (isdigit(arithval)) {
numstackptr->var = NULL;
+ errno = 0;
+ /* call strtoul[l]: */
numstackptr->val = strto_arith_t(expr, (char **) &expr, 0);
+ if (errno)
+ numstackptr->val = 0; /* bash compat */
goto num;
}
for (p = op_tokens; ; p++) {
@@ -592,7 +596,7 @@ arith(const char *expr, int *perrcode, a_e_h_t *math_hooks)
lasttok = TOK_NUM;
/* Plus and minus are binary (not unary) _only_ if the last
- * token was as number, or a right paren (which pretends to be
+ * token was a number, or a right paren (which pretends to be
* a number, since it evaluates to one). Think about it.
* It makes sense. */
if (lasttok != TOK_NUM) {
@@ -611,7 +615,7 @@ arith(const char *expr, int *perrcode, a_e_h_t *math_hooks)
break;
}
}
- /* We don't want a unary operator to cause recursive descent on the
+ /* We don't want an unary operator to cause recursive descent on the
* stack, because there can be many in a row and it could cause an
* operator to be evaluated before its argument is pushed onto the
* integer stack. */