diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2023-06-18 20:13:22 +0200 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2023-06-18 20:15:35 +0200 |
| commit | 79b90cbece5d69c4d370347c347f3d17bd1156c6 (patch) | |
| tree | 04122fddeda0c1cc413b9780a0cc507d6873f5d5 /shell | |
| parent | 10cce8ae35654585a09d6e839dd502f04b81599d (diff) | |
| download | busybox-w32-79b90cbece5d69c4d370347c347f3d17bd1156c6.tar.gz busybox-w32-79b90cbece5d69c4d370347c347f3d17bd1156c6.tar.bz2 busybox-w32-79b90cbece5d69c4d370347c347f3d17bd1156c6.zip | |
shell/math: add note on ERANGE
function old new delta
evaluate_string 1488 1478 -10
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell')
| -rw-r--r-- | shell/math.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/shell/math.c b/shell/math.c index 0b30e089d..e5447e767 100644 --- a/shell/math.c +++ b/shell/math.c | |||
| @@ -667,6 +667,7 @@ evaluate_string(arith_state_t *math_state, const char *expr) | |||
| 667 | /* At this point, we're done with the expression */ | 667 | /* At this point, we're done with the expression */ |
| 668 | if (numstackptr != numstack + 1) { | 668 | if (numstackptr != numstack + 1) { |
| 669 | /* if there is not exactly one result, it's bad */ | 669 | /* if there is not exactly one result, it's bad */ |
| 670 | /* Example: $((1 2)) */ | ||
| 670 | goto syntax_err; | 671 | goto syntax_err; |
| 671 | } | 672 | } |
| 672 | return numstack->val; | 673 | return numstack->val; |
| @@ -691,9 +692,10 @@ evaluate_string(arith_state_t *math_state, const char *expr) | |||
| 691 | } | 692 | } |
| 692 | } else { | 693 | } else { |
| 693 | dbg("[%d] var:IGNORED", (int)(numstackptr - numstack)); | 694 | dbg("[%d] var:IGNORED", (int)(numstackptr - numstack)); |
| 694 | numstackptr->var_name = NULL; | ||
| 695 | numstackptr->val = 0; //paranoia, probably not needed | ||
| 696 | expr = p; | 695 | expr = p; |
| 696 | numstackptr->var_name = NULL; | ||
| 697 | push_num0: | ||
| 698 | numstackptr->val = 0; | ||
| 697 | } | 699 | } |
| 698 | push_num: | 700 | push_num: |
| 699 | numstackptr++; | 701 | numstackptr++; |
| @@ -717,8 +719,13 @@ evaluate_string(arith_state_t *math_state, const char *expr) | |||
| 717 | */ | 719 | */ |
| 718 | if (isalnum(*expr) || *expr == '_') | 720 | if (isalnum(*expr) || *expr == '_') |
| 719 | goto syntax_err; | 721 | goto syntax_err; |
| 720 | if (errno) | 722 | if (errno) { |
| 721 | numstackptr->val = 0; /* bash compat */ | 723 | // TODO: bash 5.2.15 does not catch ERANGE (some older version did?). |
| 724 | // $((99999999999999999999)) is 7766279631452241919 (the 64-bit truncated value). | ||
| 725 | // Our BASE# code does this as well: try $((10#99999999999999999999)), | ||
| 726 | // but the "ordinary" code path with strtoull() does not do this. | ||
| 727 | goto push_num0; /* bash compat */ | ||
| 728 | } | ||
| 722 | goto push_num; | 729 | goto push_num; |
| 723 | } | 730 | } |
| 724 | 731 | ||
