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

View File

@ -224,17 +224,17 @@ typedef struct syntaxtype {
/* Next syntax. */
} syntaxtype;
#define CNONE (1<<0)
#define CNONE (1<<1)
/* 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 */
#define CENDAFTER (1<<2)
#define CENDAFTER (1<<3)
/* 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 */
#define CSTARTENDHERE (1<<4)
#define CSTARTENDHERE (1<<5)
/* regex starts and ends within this line */
#define CWTF (1<<5)
#define CWTF (1<<6)
/* Something else */
#endif /* ENABLE_COLOR */

View File

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

View File

@ -2551,7 +2551,7 @@ void edit_draw(filestruct *fileptr, const char *converted, int
}
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.
* First, we have to see if the beginning of the line is
* 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];
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)
continue;
else if (md == CWHOLELINE) {