diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2019-10-22 14:25:43 +0200 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2019-10-22 14:25:43 +0200 |
| commit | 7427406580e78666fad3634b4bfaf1922d4bb457 (patch) | |
| tree | 37ecf181da47fa6ad9b04cb16e3a5d6ce963cb0f /shell | |
| parent | 3ef513e787781e26f5996fc19b3540287a57fb9f (diff) | |
| download | busybox-w32-7427406580e78666fad3634b4bfaf1922d4bb457.tar.gz busybox-w32-7427406580e78666fad3634b4bfaf1922d4bb457.tar.bz2 busybox-w32-7427406580e78666fad3634b4bfaf1922d4bb457.zip | |
shell: better comments in BASE#nn code
function old new delta
evaluate_string 932 930 -2
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell')
| -rw-r--r-- | shell/math.c | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/shell/math.c b/shell/math.c index af1ab55c0..aac5017d0 100644 --- a/shell/math.c +++ b/shell/math.c | |||
| @@ -537,25 +537,23 @@ static arith_t strto_arith_t(const char *nptr, char **endptr) | |||
| 537 | base = (unsigned)n; | 537 | base = (unsigned)n; |
| 538 | n = 0; | 538 | n = 0; |
| 539 | nptr = *endptr + 1; | 539 | nptr = *endptr + 1; |
| 540 | /* bash allows "N#" (empty "nnnn" part) */ | ||
| 541 | for (;;) { | 540 | for (;;) { |
| 542 | unsigned digit = (unsigned)*nptr - '0'; | 541 | unsigned digit = (unsigned)*nptr - '0'; |
| 543 | if (digit >= 10) { | 542 | if (digit >= 10 /* not 0..9 */ |
| 544 | /* *nptr is not 0..9 */ | 543 | && digit <= 'z' - '0' /* needed to reject e.g. $((64#~)) */ |
| 545 | if (*nptr > 'z') | 544 | ) { |
| 546 | break; /* this rejects e.g. $((64#~)) */ | ||
| 547 | /* in bases up to 36, case does not matter for a-z */ | 545 | /* in bases up to 36, case does not matter for a-z */ |
| 548 | digit = (unsigned)(*nptr | 0x20) - ('a' - 10); | 546 | digit = (unsigned)(*nptr | 0x20) - ('a' - 10); |
| 549 | if (base > 36 && *nptr <= '_') { | 547 | if (base > 36 && *nptr <= '_') { |
| 550 | /* otherwise, A-Z,@,_ are 36..61,62,63 */ | 548 | /* otherwise, A-Z,@,_ are 36-61,62,63 */ |
| 551 | if (*nptr == '@') | 549 | if (*nptr == '_') |
| 552 | digit = 62; | ||
| 553 | else if (*nptr == '_') | ||
| 554 | digit = 63; | 550 | digit = 63; |
| 551 | else if (*nptr == '@') | ||
| 552 | digit = 62; | ||
| 555 | else if (digit < 36) /* A-Z */ | 553 | else if (digit < 36) /* A-Z */ |
| 556 | digit += 36 - 10; | 554 | digit += 36 - 10; |
| 557 | else | 555 | else |
| 558 | break; /* error, such as [ or \ */ | 556 | break; /* error: one of [\]^ */ |
| 559 | } | 557 | } |
| 560 | //bb_error_msg("ch:'%c'%d digit:%u", *nptr, *nptr, digit); | 558 | //bb_error_msg("ch:'%c'%d digit:%u", *nptr, *nptr, digit); |
| 561 | //if (digit < 10) - example where we need this? | 559 | //if (digit < 10) - example where we need this? |
| @@ -567,6 +565,12 @@ static arith_t strto_arith_t(const char *nptr, char **endptr) | |||
| 567 | n = n * base + digit; | 565 | n = n * base + digit; |
| 568 | nptr++; | 566 | nptr++; |
| 569 | } | 567 | } |
| 568 | /* Note: we do not set errno on bad chars, we just set a pointer | ||
| 569 | * to the first invalid char. For example, this allows | ||
| 570 | * "N#" (empty "nnnn" part): 64#+1 is a valid expression, | ||
| 571 | * it means 64# + 1, whereas 64#~... is not, since ~ is not a valid | ||
| 572 | * operator. | ||
| 573 | */ | ||
| 570 | *endptr = (char*)nptr; | 574 | *endptr = (char*)nptr; |
| 571 | return n; | 575 | return n; |
| 572 | } | 576 | } |
