bugfix - increment endpointer when parsing color_escape_sequence

This commit is contained in:
Nipunn Koorapati 2020-07-02 07:45:29 +00:00 committed by Craig Small
parent 4825797d97
commit 64d35921ba

33
watch.c
View File

@ -138,7 +138,30 @@ static void init_ansi_colors(void)
} }
static int set_ansi_attribute(const int attrib) static int color_escape_sequence(char** escape_sequence) {
int num;
if ((*escape_sequence)[0] != ';')
return 0; /* not understood */
if ((*escape_sequence)[1] == '5') {
// 8 bit!
if ((*escape_sequence)[2] != ';')
return 0; /* not understood */
num = strtol((*escape_sequence) + 3, escape_sequence, 10);
if (num >= 0 && num <= 7) {
return num + 1;
} else if (num >= 8 && num <= 15) {
// Bright intensity colors. Show them as normal for simplicty of impl
return num - 8 + 1;
}
}
return 0; /* not understood */
}
static int set_ansi_attribute(const int attrib, char** escape_sequence)
{ {
switch (attrib) { switch (attrib) {
case -1: /* restore last settings */ case -1: /* restore last settings */
@ -210,6 +233,7 @@ static void process_ansi(FILE * fp)
int i, c; int i, c;
char buf[MAX_ANSIBUF]; char buf[MAX_ANSIBUF];
char *numstart, *endptr = buf; char *numstart, *endptr = buf;
int ansi_attribute;
c = getc(fp); c = getc(fp);
if (c != '[') { if (c != '[') {
@ -238,13 +262,14 @@ static void process_ansi(FILE * fp)
/* Special case of <ESC>[m */ /* Special case of <ESC>[m */
if (buf[0] == '\0') if (buf[0] == '\0')
set_ansi_attribute(0); set_ansi_attribute(0, NULL);
for (endptr = numstart = buf; *endptr != '\0'; numstart = endptr + 1) { for (endptr = numstart = buf; *endptr != '\0'; numstart = endptr + 1) {
if (!set_ansi_attribute(strtol(numstart, &endptr, 10))) ansi_attribute = strtol(numstart, &endptr, 10);
if (!set_ansi_attribute(ansi_attribute, &endptr))
break; break;
if (numstart == endptr) if (numstart == endptr)
set_ansi_attribute(0); /* [m treated as [0m */ set_ansi_attribute(0, NULL); /* [m treated as [0m */
} }
} }