rcfile: don't store a coloring rule before it is complete
This really fixes https://savannah.gnu.org/bugs/?57950.master
parent
6bab8d19c6
commit
d675a549de
51
src/rcfile.c
51
src/rcfile.c
|
@ -1062,6 +1062,8 @@ void parse_rule(char *ptr, int rex_flags)
|
||||||
}
|
}
|
||||||
|
|
||||||
while (*ptr != '\0') {
|
while (*ptr != '\0') {
|
||||||
|
regex_t *start_rgx = NULL, *end_rgx = NULL;
|
||||||
|
/* Intermediate storage for compiled regular expressions. */
|
||||||
colortype *newcolor = NULL;
|
colortype *newcolor = NULL;
|
||||||
/* Container for a regex (or regex pair) and the color it paints. */
|
/* Container for a regex (or regex pair) and the color it paints. */
|
||||||
bool expectend = FALSE;
|
bool expectend = FALSE;
|
||||||
|
@ -1078,18 +1080,37 @@ void parse_rule(char *ptr, int rex_flags)
|
||||||
if (ptr == NULL)
|
if (ptr == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
/* When the regex is invalid, abandon the rule. */
|
||||||
|
if (!compile(regexstring, rex_flags, &start_rgx))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (expectend) {
|
||||||
|
if (strncmp(ptr, "end=", 4) != 0) {
|
||||||
|
jot_error(N_("\"start=\" requires a corresponding \"end=\""));
|
||||||
|
regfree(start_rgx);
|
||||||
|
free(start_rgx);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
regexstring = ptr + 5;
|
||||||
|
ptr = parse_next_regex(ptr + 5);
|
||||||
|
|
||||||
|
/* When there is no valid end= regex, abandon the rule. */
|
||||||
|
if (ptr == NULL || !compile(regexstring, rex_flags, &end_rgx)) {
|
||||||
|
regfree(start_rgx);
|
||||||
|
free(start_rgx);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
newcolor = (colortype *)nmalloc(sizeof(colortype));
|
newcolor = (colortype *)nmalloc(sizeof(colortype));
|
||||||
|
|
||||||
/* When the regex is invalid, abandon the rule. */
|
newcolor->start = start_rgx;
|
||||||
if (!compile(regexstring, rex_flags, &newcolor->start)) {
|
newcolor->end = end_rgx;
|
||||||
free(newcolor);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
newcolor->fg = fg;
|
newcolor->fg = fg;
|
||||||
newcolor->bg = bg;
|
newcolor->bg = bg;
|
||||||
newcolor->attributes = attributes;
|
newcolor->attributes = attributes;
|
||||||
newcolor->end = NULL;
|
|
||||||
|
|
||||||
if (lastcolor == NULL)
|
if (lastcolor == NULL)
|
||||||
live_syntax->color = newcolor;
|
live_syntax->color = newcolor;
|
||||||
|
@ -1102,24 +1123,6 @@ void parse_rule(char *ptr, int rex_flags)
|
||||||
if (!expectend)
|
if (!expectend)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (strncmp(ptr, "end=", 4) != 0) {
|
|
||||||
jot_error(N_("\"start=\" requires a corresponding \"end=\""));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
regexstring = ptr + 5;
|
|
||||||
ptr = parse_next_regex(ptr + 5);
|
|
||||||
|
|
||||||
if (ptr == NULL)
|
|
||||||
return;
|
|
||||||
|
|
||||||
/* When the end= regex is invalid, abandon the whole rule. */
|
|
||||||
if (!compile(regexstring, rex_flags, &newcolor->end)) {
|
|
||||||
regfree(newcolor->start);
|
|
||||||
free(newcolor);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Lame way to skip another static counter. */
|
/* Lame way to skip another static counter. */
|
||||||
newcolor->id = live_syntax->nmultis;
|
newcolor->id = live_syntax->nmultis;
|
||||||
live_syntax->nmultis++;
|
live_syntax->nmultis++;
|
||||||
|
|
Loading…
Reference in New Issue