From 56a295bc90d62a772e5a4be9a4b1cc0a6bcd5e50 Mon Sep 17 00:00:00 2001 From: Chris Allegretta Date: Sat, 7 Feb 2009 14:48:30 +0000 Subject: [PATCH] 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 --- src/color.c | 7 +++++-- src/nano.h | 12 ++++++------ src/proto.h | 1 + src/winio.c | 4 ++-- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/color.c b/src/color.c index 2211ceb8..25c9603a 100644 --- a/src/color.c +++ b/src/color.c @@ -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); diff --git a/src/nano.h b/src/nano.h index e4beb8dc..0d725de5 100644 --- a/src/nano.h +++ b/src/nano.h @@ -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 */ diff --git a/src/proto.h b/src/proto.h index 0e962275..2328cc13 100644 --- a/src/proto.h +++ b/src/proto.h @@ -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 diff --git a/src/winio.c b/src/winio.c index 39a89811..759b69e6 100644 --- a/src/winio.c +++ b/src/winio.c @@ -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) { -- 2.39.5