diff options
| author | Ron Yorston <rmy@pobox.com> | 2015-08-06 13:34:09 +0100 |
|---|---|---|
| committer | Ron Yorston <rmy@pobox.com> | 2015-08-06 13:34:09 +0100 |
| commit | 336c09e79815ba8dce842c7e70da2bc06700e929 (patch) | |
| tree | 4b5dfa08a188596f36835e7c7e77efbaa1c89a3f /miscutils | |
| parent | fb69410e583f04ede9e641e9f4bb0df83a67e882 (diff) | |
| download | busybox-w32-336c09e79815ba8dce842c7e70da2bc06700e929.tar.gz busybox-w32-336c09e79815ba8dce842c7e70da2bc06700e929.tar.bz2 busybox-w32-336c09e79815ba8dce842c7e70da2bc06700e929.zip | |
less: fix bugs in terminal width handling
Diffstat (limited to 'miscutils')
| -rw-r--r-- | miscutils/less.c | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/miscutils/less.c b/miscutils/less.c index 86dcebb10..014a649e0 100644 --- a/miscutils/less.c +++ b/miscutils/less.c | |||
| @@ -462,7 +462,7 @@ static void read_lines(void) | |||
| 462 | if (option_mask32 & FLAG_N) | 462 | if (option_mask32 & FLAG_N) |
| 463 | w -= 8; | 463 | w -= 8; |
| 464 | 464 | ||
| 465 | p = current_line = ((char*)xmalloc(w + 4)) + 4; | 465 | p = current_line = ((char*)xmalloc(w + 5)) + 4; |
| 466 | if (!last_terminated) { | 466 | if (!last_terminated) { |
| 467 | const char *cp = flines[max_fline]; | 467 | const char *cp = flines[max_fline]; |
| 468 | p = stpcpy(p, cp); | 468 | p = stpcpy(p, cp); |
| @@ -515,6 +515,16 @@ static void read_lines(void) | |||
| 515 | *--p = '\0'; | 515 | *--p = '\0'; |
| 516 | continue; | 516 | continue; |
| 517 | } | 517 | } |
| 518 | { | ||
| 519 | size_t new_last_line_pos = last_line_pos + 1; | ||
| 520 | if (c == '\t') { | ||
| 521 | new_last_line_pos += 7; | ||
| 522 | new_last_line_pos &= (~7); | ||
| 523 | } | ||
| 524 | if ((int)new_last_line_pos > w) | ||
| 525 | break; | ||
| 526 | last_line_pos = new_last_line_pos; | ||
| 527 | } | ||
| 518 | /* ok, we will eat this char */ | 528 | /* ok, we will eat this char */ |
| 519 | readpos++; | 529 | readpos++; |
| 520 | if (c == '\n') { | 530 | if (c == '\n') { |
| @@ -531,16 +541,6 @@ static void read_lines(void) | |||
| 531 | if (c == '\0') c = '\n'; | 541 | if (c == '\0') c = '\n'; |
| 532 | *p++ = c; | 542 | *p++ = c; |
| 533 | *p = '\0'; | 543 | *p = '\0'; |
| 534 | { | ||
| 535 | size_t new_last_line_pos = last_line_pos + 1; | ||
| 536 | if (c == '\t') { | ||
| 537 | new_last_line_pos += 7; | ||
| 538 | new_last_line_pos &= (~7); | ||
| 539 | } | ||
| 540 | if ((int)new_last_line_pos >= w) | ||
| 541 | break; | ||
| 542 | last_line_pos = new_last_line_pos; | ||
| 543 | } | ||
| 544 | } /* end of "read chars until we have a line" loop */ | 544 | } /* end of "read chars until we have a line" loop */ |
| 545 | #if 0 | 545 | #if 0 |
| 546 | //BUG: also triggers on this: | 546 | //BUG: also triggers on this: |
| @@ -584,7 +584,7 @@ static void read_lines(void) | |||
| 584 | break; | 584 | break; |
| 585 | } | 585 | } |
| 586 | max_fline++; | 586 | max_fline++; |
| 587 | current_line = ((char*)xmalloc(w + 4)) + 4; | 587 | current_line = ((char*)xmalloc(w + 5)) + 4; |
| 588 | p = current_line; | 588 | p = current_line; |
| 589 | last_line_pos = 0; | 589 | last_line_pos = 0; |
| 590 | } /* end of "read lines until we reach cur_fline" loop */ | 590 | } /* end of "read lines until we reach cur_fline" loop */ |
| @@ -771,7 +771,7 @@ static void print_found(const char *line) | |||
| 771 | char *growline; | 771 | char *growline; |
| 772 | regmatch_t match_structs; | 772 | regmatch_t match_structs; |
| 773 | 773 | ||
| 774 | char buf[width]; | 774 | char buf[width+1]; |
| 775 | const char *str = line; | 775 | const char *str = line; |
| 776 | char *p = buf; | 776 | char *p = buf; |
| 777 | size_t n; | 777 | size_t n; |
| @@ -835,7 +835,7 @@ void print_found(const char *line); | |||
| 835 | 835 | ||
| 836 | static void print_ascii(const char *str) | 836 | static void print_ascii(const char *str) |
| 837 | { | 837 | { |
| 838 | char buf[width]; | 838 | char buf[width+1]; |
| 839 | char *p; | 839 | char *p; |
| 840 | size_t n; | 840 | size_t n; |
| 841 | 841 | ||
