diff options
Diffstat (limited to 'shell/math.c')
| -rw-r--r-- | shell/math.c | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/shell/math.c b/shell/math.c index e90a38f05..536f22ff0 100644 --- a/shell/math.c +++ b/shell/math.c | |||
| @@ -585,12 +585,21 @@ static arith_t parse_with_base(const char *nptr, char **endptr, unsigned base) | |||
| 585 | nptr++; | 585 | nptr++; |
| 586 | } | 586 | } |
| 587 | *endptr = (char*)nptr; | 587 | *endptr = (char*)nptr; |
| 588 | |||
| 588 | /* "64#" and "64#+1" used to be valid expressions, but bash 5.2.15 | 589 | /* "64#" and "64#+1" used to be valid expressions, but bash 5.2.15 |
| 589 | * no longer allow such, detect this: | 590 | * no longer allows such, detect this: |
| 590 | */ | 591 | */ |
| 591 | // NB: bash allows $((0x)), this is probably a bug... | 592 | if (nptr == start) { |
| 592 | if (nptr == start) | 593 | /* There weren't any digits */ |
| 593 | *endptr = NULL; /* there weren't any digits, bad */ | 594 | /* Excluding the case of "0x" |
| 595 | * (bash allows 0x: supports 0x$hexdigits when $hexdigits is empty) | ||
| 596 | */ | ||
| 597 | if (base != 16 /* why check 16? for base 10, start[-1] is undefined */ | ||
| 598 | || (start[-1] | 0x20) != 'x' | ||
| 599 | ) | ||
| 600 | *endptr = NULL; /* error indicator */ | ||
| 601 | } | ||
| 602 | |||
| 594 | return n; | 603 | return n; |
| 595 | } | 604 | } |
| 596 | 605 | ||
| @@ -611,7 +620,6 @@ static arith_t strto_arith_t(const char *nptr, char **endptr) | |||
| 611 | base = 16; | 620 | base = 16; |
| 612 | nptr += 2; | 621 | nptr += 2; |
| 613 | } | 622 | } |
| 614 | // NB: bash allows $((0x)), this is probably a bug... | ||
| 615 | return parse_with_base(nptr, endptr, base); | 623 | return parse_with_base(nptr, endptr, base); |
| 616 | } | 624 | } |
| 617 | 625 | ||
