Producing an adequate error message when the syntax name is improperly quoted.

This fixes Savannah bug #47324.


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@5711 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
This commit is contained in:
Benno Schulenberg 2016-03-09 20:28:50 +00:00
parent 6a4d3aad80
commit b0bdfbb0f7
2 changed files with 16 additions and 9 deletions

View File

@ -1,3 +1,7 @@
2016-03-09 Benno Schulenberg <bensberg@justemail.net>
* src/rcfile.c (parse_syntax): Produce an adequate error message
when the syntax name is unquoted. This fixes Savannah bug #47324.
2016-03-04 Benno Schulenberg <bensberg@justemail.net> 2016-03-04 Benno Schulenberg <bensberg@justemail.net>
* src/color.c (found_in_list): Don't bother keeping the compiled * src/color.c (found_in_list): Don't bother keeping the compiled
regular expression when it matched -- drop this tiny optimization regular expression when it matched -- drop this tiny optimization

View File

@ -266,7 +266,7 @@ bool nregcomp(const char *regex, int eflags)
* global list of color syntaxes. */ * global list of color syntaxes. */
void parse_syntax(char *ptr) void parse_syntax(char *ptr)
{ {
const char *fileregptr = NULL, *nameptr = NULL; char *fileregptr, *nameptr;
regexlisttype *endext = NULL; regexlisttype *endext = NULL;
/* The end of the extensions list for this syntax. */ /* The end of the extensions list for this syntax. */
@ -274,21 +274,24 @@ void parse_syntax(char *ptr)
assert(ptr != NULL); assert(ptr != NULL);
if (*ptr == '\0') { /* Check that the syntax name is not empty. */
if (*ptr == '\0' || (*ptr == '"' &&
(*(ptr + 1) == '\0' || *(ptr + 1) == '"'))) {
rcfile_error(N_("Missing syntax name")); rcfile_error(N_("Missing syntax name"));
return; return;
} }
if (*ptr != '"') { nameptr = ++ptr;
rcfile_error( ptr = parse_next_word(ptr);
N_("Regex strings must begin and end with a \" character"));
/* Check that the name starts and ends with a double quote. */
if (*(nameptr - 1) != '\x22' || nameptr[strlen(nameptr) - 1] != '\x22') {
rcfile_error(N_("A syntax name must be quoted"));
return; return;
} }
nameptr = ++ptr; /* Strip the end quote. */
ptr = parse_next_regex(ptr); nameptr[strlen(nameptr) - 1] = '\0';
if (ptr == NULL)
return;
/* Redefining the "none" syntax is not allowed. */ /* Redefining the "none" syntax is not allowed. */
if (strcmp(nameptr, "none") == 0) { if (strcmp(nameptr, "none") == 0) {