From a016f00f1412301e1e189f1058f700a60f9c974f Mon Sep 17 00:00:00 2001 From: Chris Allegretta Date: Thu, 3 Jan 2013 05:17:36 +0000 Subject: [PATCH] 2013-01-02 David Benjamin * src/search.c (parse_syntax): Fix blatantly and dangerously incorrect code for deleting old syntaxes. git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@4560 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- ChangeLog | 4 ++++ src/rcfile.c | 17 ++++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 592ba697..91aca9f8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2013-01-02 David Benjamin + * src/search.c (parse_syntax): Fix blatantly and dangerously incorrect code for + deleting old syntaxes. + 2013-01-02 Mike Frysinger * src/files.c (cwd_tab_completion): Remove unnecessary variables * src/search.c (search_init): Fix gcc complaints on certain versions diff --git a/src/rcfile.c b/src/rcfile.c index 56eeb72d..991eba93 100644 --- a/src/rcfile.c +++ b/src/rcfile.c @@ -252,7 +252,7 @@ bool nregcomp(const char *regex, int cflags) void parse_syntax(char *ptr) { const char *fileregptr = NULL, *nameptr = NULL; - syntaxtype *tmpsyntax; + syntaxtype *tmpsyntax, *prev_syntax; exttype *endext = NULL; /* The end of the extensions list for this syntax. */ @@ -279,15 +279,26 @@ void parse_syntax(char *ptr) /* Search for a duplicate syntax name. If we find one, free it, so * that we always use the last syntax with a given name. */ + prev_syntax = NULL; for (tmpsyntax = syntaxes; tmpsyntax != NULL; tmpsyntax = tmpsyntax->next) { if (strcmp(nameptr, tmpsyntax->desc) == 0) { - syntaxtype *prev_syntax = tmpsyntax; + syntaxtype *old_syntax = tmpsyntax; + + if (endsyntax == tmpsyntax) + endsyntax = prev_syntax; tmpsyntax = tmpsyntax->next; - free(prev_syntax); + if (prev_syntax != NULL) + prev_syntax->next = tmpsyntax; + else + syntaxes = tmpsyntax; + + free(old_syntax->desc); + free(old_syntax); break; } + prev_syntax = tmpsyntax; } if (syntaxes == NULL) { -- 2.39.5