diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2019-09-22 23:40:10 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2019-10-21 16:54:40 +0200 |
commit | 49a8839638cb335a2fe8a3a332e97fbb01027a72 (patch) | |
tree | 82cf95b18f7fd56b8218ef401a0382ce31a5ba97 | |
parent | 3004510fdc7dfb0c511cfdc0011011bf65a75345 (diff) | |
download | busybox-w32-49a8839638cb335a2fe8a3a332e97fbb01027a72.tar.gz busybox-w32-49a8839638cb335a2fe8a3a332e97fbb01027a72.tar.bz2 busybox-w32-49a8839638cb335a2fe8a3a332e97fbb01027a72.zip |
ash: fix BASE##nn bashism for bases 36..64
function old new delta
evaluate_string 876 932 +56
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | shell/math.c | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/shell/math.c b/shell/math.c index 0c806ad39..af1ab55c0 100644 --- a/shell/math.c +++ b/shell/math.c | |||
@@ -540,11 +540,29 @@ static arith_t strto_arith_t(const char *nptr, char **endptr) | |||
540 | /* bash allows "N#" (empty "nnnn" part) */ | 540 | /* bash allows "N#" (empty "nnnn" part) */ |
541 | for (;;) { | 541 | for (;;) { |
542 | unsigned digit = (unsigned)*nptr - '0'; | 542 | unsigned digit = (unsigned)*nptr - '0'; |
543 | if (digit >= 10 || digit >= base) { | 543 | if (digit >= 10) { |
544 | /* *nptr is not 0..9 */ | ||
545 | if (*nptr > 'z') | ||
546 | break; /* this rejects e.g. $((64#~)) */ | ||
547 | /* in bases up to 36, case does not matter for a-z */ | ||
544 | digit = (unsigned)(*nptr | 0x20) - ('a' - 10); | 548 | digit = (unsigned)(*nptr | 0x20) - ('a' - 10); |
545 | if (digit >= base) | 549 | if (base > 36 && *nptr <= '_') { |
546 | break; | 550 | /* otherwise, A-Z,@,_ are 36..61,62,63 */ |
551 | if (*nptr == '@') | ||
552 | digit = 62; | ||
553 | else if (*nptr == '_') | ||
554 | digit = 63; | ||
555 | else if (digit < 36) /* A-Z */ | ||
556 | digit += 36 - 10; | ||
557 | else | ||
558 | break; /* error, such as [ or \ */ | ||
559 | } | ||
560 | //bb_error_msg("ch:'%c'%d digit:%u", *nptr, *nptr, digit); | ||
561 | //if (digit < 10) - example where we need this? | ||
562 | // break; | ||
547 | } | 563 | } |
564 | if (digit >= base) | ||
565 | break; | ||
548 | /* bash does not check for overflows */ | 566 | /* bash does not check for overflows */ |
549 | n = n * base + digit; | 567 | n = n * base + digit; |
550 | nptr++; | 568 | nptr++; |