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>
diff --git a/shell/math.c b/shell/math.c
index eaf4f24..0c806ad 100644
--- a/shell/math.c
+++ b/shell/math.c
@@ -538,9 +538,16 @@
n = 0;
nptr = *endptr + 1;
/* bash allows "N#" (empty "nnnn" part) */
- while (isdigit(*nptr)) {
+ for (;;) {
+ unsigned digit = (unsigned)*nptr - '0';
+ if (digit >= 10 || digit >= base) {
+ digit = (unsigned)(*nptr | 0x20) - ('a' - 10);
+ if (digit >= base)
+ break;
+ }
/* bash does not check for overflows */
- n = n * base + (*nptr++ - '0');
+ n = n * base + digit;
+ nptr++;
}
*endptr = (char*)nptr;
return n;