Fix invalid read errors found with valgrind
This commit is contained in:
parent
8fcefce793
commit
40adb336fb
1 changed files with 12 additions and 3 deletions
|
|
@ -514,8 +514,17 @@ handle_color(line_buffer_t *lines, int line_idx, int *pos, int apply)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
while (p < line_len) {
|
while (p < line_len) {
|
||||||
|
int fit_col = (p + 7) <= line_len;
|
||||||
|
int fit_en = (p + 4) <= line_len;
|
||||||
|
|
||||||
/* fg or bg color */
|
/* fg or bg color */
|
||||||
if (!memcmp(&line[p], "\e[38;5;", 7) || !memcmp(&line[p], "\e[48;5;", 7)) {
|
if (
|
||||||
|
fit_col &&
|
||||||
|
(
|
||||||
|
!memcmp(&line[p], "\e[38;5;", 7) ||
|
||||||
|
!memcmp(&line[p], "\e[48;5;", 7)
|
||||||
|
)
|
||||||
|
) {
|
||||||
char col_str[4] = { 0 };
|
char col_str[4] = { 0 };
|
||||||
short *col = line[p + 2] == '3' ? &fg : &bg;
|
short *col = line[p + 2] == '3' ? &fg : &bg;
|
||||||
|
|
||||||
|
|
@ -543,13 +552,13 @@ handle_color(line_buffer_t *lines, int line_idx, int *pos, int apply)
|
||||||
p++;
|
p++;
|
||||||
}
|
}
|
||||||
/* enable our color */
|
/* enable our color */
|
||||||
else if (!memcmp(&line[p], "\e[1m", 4)) {
|
else if (fit_en && !memcmp(&line[p], "\e[1m", 4)) {
|
||||||
p += 4;
|
p += 4;
|
||||||
enable = 1;
|
enable = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
/* disable our color */
|
/* disable our color */
|
||||||
else if (!memcmp(&line[p], "\e[0m", 4)) {
|
else if (fit_en && !memcmp(&line[p], "\e[0m", 4)) {
|
||||||
p += 4;
|
p += 4;
|
||||||
enable = 0;
|
enable = 0;
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue