aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2019-09-22 18:26:05 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2019-09-22 18:26:05 +0200
commitca1ce4b9fa2b48f8898a51782543fe32546ba1ec (patch)
tree9bdde33fa93749361e594d32c97d615a4e813562
parentf159352112671e3c1e07356ebf6f590d8f79c8ff (diff)
downloadbusybox-w32-ca1ce4b9fa2b48f8898a51782543fe32546ba1ec.tar.gz
busybox-w32-ca1ce4b9fa2b48f8898a51782543fe32546ba1ec.tar.bz2
busybox-w32-ca1ce4b9fa2b48f8898a51782543fe32546ba1ec.zip
ash: fix BASE###nn bashism to accept letter 'digits' for bases > 9
function old new delta evaluate_string 873 876 +3 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--shell/math.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/shell/math.c b/shell/math.c
index eaf4f2453..0c806ad39 100644
--- a/shell/math.c
+++ b/shell/math.c
@@ -538,9 +538,16 @@ static arith_t strto_arith_t(const char *nptr, char **endptr)
538 n = 0; 538 n = 0;
539 nptr = *endptr + 1; 539 nptr = *endptr + 1;
540 /* bash allows "N#" (empty "nnnn" part) */ 540 /* bash allows "N#" (empty "nnnn" part) */
541 while (isdigit(*nptr)) { 541 for (;;) {
542 unsigned digit = (unsigned)*nptr - '0';
543 if (digit >= 10 || digit >= base) {
544 digit = (unsigned)(*nptr | 0x20) - ('a' - 10);
545 if (digit >= base)
546 break;
547 }
542 /* bash does not check for overflows */ 548 /* bash does not check for overflows */
543 n = n * base + (*nptr++ - '0'); 549 n = n * base + digit;
550 nptr++;
544 } 551 }
545 *endptr = (char*)nptr; 552 *endptr = (char*)nptr;
546 return n; 553 return n;