Renumber multidataflags to not start at 0 in case it confuses alloc_multidata_if_needed().

Add alloc_multidata_if_needed() call in edit_draw as the last defense against a crash.



git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@4367 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
This commit is contained in:
Chris Allegretta 2009-02-07 14:48:30 +00:00
parent 803379c52c
commit 56a295bc90
4 changed files with 14 additions and 10 deletions

View File

@ -260,9 +260,10 @@ void reset_multis_after(filestruct *fileptr, int mindex)
{ {
filestruct *oof; filestruct *oof;
for (oof = fileptr->next; oof != NULL; oof = oof->next) { for (oof = fileptr->next; oof != NULL; oof = oof->next) {
alloc_multidata_if_needed(oof);
if (oof->multidata == NULL) if (oof->multidata == NULL)
continue; continue;
if (oof->multidata[mindex] != 0) if (oof->multidata[mindex] != CNONE)
oof->multidata[mindex] = -1; oof->multidata[mindex] = -1;
else else
break; break;
@ -273,9 +274,10 @@ void reset_multis_before(filestruct *fileptr, int mindex)
{ {
filestruct *oof; filestruct *oof;
for (oof = fileptr->prev; oof != NULL; oof = oof->prev) { for (oof = fileptr->prev; oof != NULL; oof = oof->prev) {
alloc_multidata_if_needed(oof);
if (oof->multidata == NULL) if (oof->multidata == NULL)
continue; continue;
if (oof->multidata[mindex] != 0) if (oof->multidata[mindex] != CNONE)
oof->multidata[mindex] = -1; oof->multidata[mindex] = -1;
else else
break; break;
@ -299,6 +301,7 @@ void reset_multis(filestruct *fileptr)
if (tmpcolor->end == NULL) if (tmpcolor->end == NULL)
continue; continue;
alloc_multidata_if_needed(fileptr);
/* Figure out where the first begin and end are to determine if /* Figure out where the first begin and end are to determine if
things changed drastically for the precalculated multi values */ things changed drastically for the precalculated multi values */
nobegin = regexec(tmpcolor->start, fileptr->data, 1, &startmatch, 0); nobegin = regexec(tmpcolor->start, fileptr->data, 1, &startmatch, 0);

View File

@ -224,17 +224,17 @@ typedef struct syntaxtype {
/* Next syntax. */ /* Next syntax. */
} syntaxtype; } syntaxtype;
#define CNONE (1<<0) #define CNONE (1<<1)
/* Yay, regex doesn't apply to this line at all! */ /* Yay, regex doesn't apply to this line at all! */
#define CBEGINBEFORE (1<<1) #define CBEGINBEFORE (1<<2)
/* regex starts on an earlier line, ends on this one */ /* regex starts on an earlier line, ends on this one */
#define CENDAFTER (1<<2) #define CENDAFTER (1<<3)
/* regex sraers on this line and ends on a later one */ /* regex sraers on this line and ends on a later one */
#define CWHOLELINE (1<<3) #define CWHOLELINE (1<<4)
/* whole line engulfed by the regex start < me, end > me */ /* whole line engulfed by the regex start < me, end > me */
#define CSTARTENDHERE (1<<4) #define CSTARTENDHERE (1<<5)
/* regex starts and ends within this line */ /* regex starts and ends within this line */
#define CWTF (1<<5) #define CWTF (1<<6)
/* Something else */ /* Something else */
#endif /* ENABLE_COLOR */ #endif /* ENABLE_COLOR */

View File

@ -544,6 +544,7 @@ void parse_include(char *ptr);
short color_to_short(const char *colorname, bool *bright); short color_to_short(const char *colorname, bool *bright);
void parse_colors(char *ptr, bool icase); void parse_colors(char *ptr, bool icase);
void reset_multis(filestruct *fileptr); void reset_multis(filestruct *fileptr);
void alloc_multidata_if_needed(filestruct *fileptr);
#endif #endif
void parse_rcfile(FILE *rcstream void parse_rcfile(FILE *rcstream
#ifdef ENABLE_COLOR #ifdef ENABLE_COLOR

View File

@ -2551,7 +2551,7 @@ void edit_draw(filestruct *fileptr, const char *converted, int
} }
k = startmatch.rm_eo; k = startmatch.rm_eo;
} }
} else if (fileptr->multidata != NULL && fileptr->multidata[tmpcolor->id] != 0) { } else if (fileptr->multidata != NULL && fileptr->multidata[tmpcolor->id] != CNONE) {
/* This is a multi-line regex. There are two steps. /* This is a multi-line regex. There are two steps.
* First, we have to see if the beginning of the line is * First, we have to see if the beginning of the line is
* colored by a start on an earlier line, and an end on * colored by a start on an earlier line, and an end on
@ -2571,7 +2571,7 @@ void edit_draw(filestruct *fileptr, const char *converted, int
short md = fileptr->multidata[tmpcolor->id]; short md = fileptr->multidata[tmpcolor->id];
if (md == -1) if (md == -1)
fileptr->multidata[tmpcolor->id] = 0; /* until we find out otherwise */ fileptr->multidata[tmpcolor->id] = CNONE; /* until we find out otherwise */
else if (md == CNONE) else if (md == CNONE)
continue; continue;
else if (md == CWHOLELINE) { else if (md == CWHOLELINE) {