diff options
-rw-r--r-- | coreutils/printf.c | 8 | ||||
-rw-r--r-- | shell/math.c | 8 | ||||
-rw-r--r-- | shell/math.h | 4 |
3 files changed, 16 insertions, 4 deletions
diff --git a/coreutils/printf.c b/coreutils/printf.c index 0b004eaeb..2beea7189 100644 --- a/coreutils/printf.c +++ b/coreutils/printf.c | |||
@@ -78,6 +78,14 @@ static int multiconvert(const char *arg, void *result, converter convert) | |||
78 | static void FAST_FUNC conv_strtoull(const char *arg, void *result) | 78 | static void FAST_FUNC conv_strtoull(const char *arg, void *result) |
79 | { | 79 | { |
80 | *(unsigned long long*)result = bb_strtoull(arg, NULL, 0); | 80 | *(unsigned long long*)result = bb_strtoull(arg, NULL, 0); |
81 | /* both coreutils 6.10 and bash 3.2: | ||
82 | * $ printf '%x\n' -2 | ||
83 | * fffffffffffffffe | ||
84 | * Mimic that: | ||
85 | */ | ||
86 | if (errno) { | ||
87 | *(unsigned long long*)result = bb_strtoll(arg, NULL, 0); | ||
88 | } | ||
81 | } | 89 | } |
82 | static void FAST_FUNC conv_strtoll(const char *arg, void *result) | 90 | static void FAST_FUNC conv_strtoll(const char *arg, void *result) |
83 | { | 91 | { |
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 |
81 | typedef long long arith_t; | 81 | typedef 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 |
85 | typedef long arith_t; | 85 | typedef 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 | ||
90 | typedef const char *(*arith_var_lookup_t)(const char *name); | 90 | typedef const char *(*arith_var_lookup_t)(const char *name); |