aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2018-12-18 03:16:48 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2018-12-18 03:16:48 +0100
commit0f31a5c79e8d4a35f790d9f7f2c0a63e3c0d6808 (patch)
treeb23a796d1ae9b3c13b13ed6fe8904918fd032229
parentf4f10720fe4f7a37685bf2d9a535d7bd59a64e86 (diff)
downloadbusybox-w32-0f31a5c79e8d4a35f790d9f7f2c0a63e3c0d6808.tar.gz
busybox-w32-0f31a5c79e8d4a35f790d9f7f2c0a63e3c0d6808.tar.bz2
busybox-w32-0f31a5c79e8d4a35f790d9f7f2c0a63e3c0d6808.zip
bc: fixes to bugs found while testing 64-bit build
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--miscutils/bc.c21
1 files changed, 13 insertions, 8 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c
index 20ce497dd..57ae52ce7 100644
--- a/miscutils/bc.c
+++ b/miscutils/bc.c
@@ -2690,12 +2690,11 @@ static void bc_lex_whitespace(BcLex *l)
2690static BC_STATUS zbc_lex_number(BcLex *l, char start) 2690static BC_STATUS zbc_lex_number(BcLex *l, char start)
2691{ 2691{
2692 const char *buf = l->buf + l->i; 2692 const char *buf = l->buf + l->i;
2693 size_t len, bslashes, i, ccnt; 2693 size_t len, i, ccnt;
2694 bool pt; 2694 bool pt;
2695 2695
2696 pt = (start == '.'); 2696 pt = (start == '.');
2697 l->t.t = BC_LEX_NUMBER; 2697 l->t.t = BC_LEX_NUMBER;
2698 bslashes = 0;
2699 ccnt = i = 0; 2698 ccnt = i = 0;
2700 for (;;) { 2699 for (;;) {
2701 char c = buf[i]; 2700 char c = buf[i];
@@ -2703,26 +2702,31 @@ static BC_STATUS zbc_lex_number(BcLex *l, char start)
2703 break; 2702 break;
2704 if (c == '\\' && buf[i + 1] == '\n') { 2703 if (c == '\\' && buf[i + 1] == '\n') {
2705 i += 2; 2704 i += 2;
2706 bslashes++; 2705 //number_of_backslashes++ - see comment below
2707 continue; 2706 continue;
2708 } 2707 }
2709 if (!isdigit(c) && (c < 'A' || c > 'F')) { 2708 if (!isdigit(c) && (c < 'A' || c > 'F')) {
2710 if (c != '.') break; 2709 if (c != '.') break;
2711 // if '.' was already seen, stop on second one: 2710 // if '.' was already seen, stop on second one:
2712 if (pt) break; 2711 if (pt) break;
2713 pt = 1; 2712 pt = true;
2714 } 2713 }
2715 // buf[i] is one of "0-9A-F." 2714 // buf[i] is one of "0-9A-F."
2716 i++; 2715 i++;
2717 if (c != '.') 2716 if (c != '.')
2718 ccnt = i; 2717 ccnt = i;
2719 } 2718 }
2720 //i is buf[i] index of the first not-yet-parsed char 2719 //ccnt is the number of chars in the number string, excluding possible
2720 //trailing "[\<newline>].[\<newline>]" (with any number of \<NL> repetitions).
2721 //i is buf[i] index of the first not-yet-parsed char after that.
2721 l->i += i; 2722 l->i += i;
2722 2723
2723 //ccnt is the number of chars in the number string, excluding possible 2724 // This might overestimate the size, if there are "\<NL>"'s
2724 //trailing "." and possible following trailing "\<newline>"(s). 2725 // in the number. Subtracting number_of_backslashes*2 correctly
2725 len = ccnt - bslashes * 2 + 1; // +1 byte for NUL termination 2726 // is not that easy: consider that in the case of "NNN.\<NL>"
2727 // loop above will count "\<NL>" before it realizes it is not
2728 // in fact *inside* the number:
2729 len = ccnt + 1; // +1 byte for NUL termination
2726 2730
2727 // This check makes sense only if size_t is (much) larger than BC_MAX_NUM. 2731 // This check makes sense only if size_t is (much) larger than BC_MAX_NUM.
2728 if (SIZE_MAX > (BC_MAX_NUM | 0xff)) { 2732 if (SIZE_MAX > (BC_MAX_NUM | 0xff)) {
@@ -2979,6 +2983,7 @@ static BC_STATUS zbc_lex_identifier(BcLex *l)
2979 } 2983 }
2980 2984
2981 bc_lex_name(l); 2985 bc_lex_name(l);
2986 s = BC_STATUS_SUCCESS;
2982 2987
2983 if (l->t.v.len > 2) { 2988 if (l->t.v.len > 2) {
2984 // Prevent this: 2989 // Prevent this: