aboutsummaryrefslogtreecommitdiff
path: root/shell
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2009-06-05 16:24:29 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2009-06-05 16:24:29 +0200
commit71016baf5524d739d1dd4d9110b111a7c3ddcaf9 (patch)
tree4d012db2dc2dd20e0956c0b188e52ab43059d2cc /shell
parent0f952c249e30834a3ee5cd821e9afc3197b05f9c (diff)
downloadbusybox-w32-71016baf5524d739d1dd4d9110b111a7c3ddcaf9.tar.gz
busybox-w32-71016baf5524d739d1dd4d9110b111a7c3ddcaf9.tar.bz2
busybox-w32-71016baf5524d739d1dd4d9110b111a7c3ddcaf9.zip
printf: accept negative numbers for %x; sh: overflowed numbers are 0
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell')
-rw-r--r--shell/math.c8
-rw-r--r--shell/math.h4
2 files changed, 8 insertions, 4 deletions
diff --git a/shell/math.c b/shell/math.c
index cc298bd24..d75bcae3a 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)
562 } 562 }
563 if (isdigit(arithval)) { 563 if (isdigit(arithval)) {
564 numstackptr->var = NULL; 564 numstackptr->var = NULL;
565 errno = 0;
566 /* call strtoul[l]: */
565 numstackptr->val = strto_arith_t(expr, (char **) &expr, 0); 567 numstackptr->val = strto_arith_t(expr, (char **) &expr, 0);
568 if (errno)
569 numstackptr->val = 0; /* bash compat */
566 goto num; 570 goto num;
567 } 571 }
568 for (p = op_tokens; ; p++) { 572 for (p = op_tokens; ; p++) {
@@ -592,7 +596,7 @@ arith(const char *expr, int *perrcode, a_e_h_t *math_hooks)
592 lasttok = TOK_NUM; 596 lasttok = TOK_NUM;
593 597
594 /* Plus and minus are binary (not unary) _only_ if the last 598 /* Plus and minus are binary (not unary) _only_ if the last
595 * token was as number, or a right paren (which pretends to be 599 * token was a number, or a right paren (which pretends to be
596 * a number, since it evaluates to one). Think about it. 600 * a number, since it evaluates to one). Think about it.
597 * It makes sense. */ 601 * It makes sense. */
598 if (lasttok != TOK_NUM) { 602 if (lasttok != TOK_NUM) {
@@ -611,7 +615,7 @@ arith(const char *expr, int *perrcode, a_e_h_t *math_hooks)
611 break; 615 break;
612 } 616 }
613 } 617 }
614 /* We don't want a unary operator to cause recursive descent on the 618 /* We don't want an unary operator to cause recursive descent on the
615 * stack, because there can be many in a row and it could cause an 619 * stack, because there can be many in a row and it could cause an
616 * operator to be evaluated before its argument is pushed onto the 620 * operator to be evaluated before its argument is pushed onto the
617 * integer stack. */ 621 * integer stack. */
diff --git a/shell/math.h b/shell/math.h
index 51dbb56cb..7b7898ea0 100644
--- a/shell/math.h
+++ b/shell/math.h
@@ -80,11 +80,11 @@ PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN
80#if ENABLE_SH_MATH_SUPPORT_64 80#if ENABLE_SH_MATH_SUPPORT_64
81typedef long long arith_t; 81typedef long long arith_t;
82#define arith_t_fmt "%lld" 82#define arith_t_fmt "%lld"
83#define strto_arith_t strtoll 83#define strto_arith_t strtoull
84#else 84#else
85typedef long arith_t; 85typedef long arith_t;
86#define arith_t_fmt "%ld" 86#define arith_t_fmt "%ld"
87#define strto_arith_t strtol 87#define strto_arith_t strtoul
88#endif 88#endif
89 89
90typedef const char *(*arith_var_lookup_t)(const char *name); 90typedef const char *(*arith_var_lookup_t)(const char *name);