Browse code

highlighting: add missing end-of-highlights check when displaying a line with highlighting

Dario Rodriguez authored on 19/10/2020 21:33:48
Showing 1 changed files
... ...
@@ -1014,7 +1014,7 @@ re_drawcontents(re_t *re)
1014 1014
                                 int used,usedcol; /* number of bytes/columns used of redata chunk (those are already drawn) */
1015 1015
                                 used=usedcol=0;
1016 1016
                                 /* while the avail text is larger than the linecolor len */
1017
-                                while((len-has_nl-used)>=(linecolors[curlinecolor].len-usedlenlinecolor)) {
1017
+                                while(curlinecolor<nlinecolors && (len-has_nl-used)>=(linecolors[curlinecolor].len-usedlenlinecolor)) {
1018 1018
                                         reui_write(re->ui,re->x+(tmpcol-re->origincol+usedcol)*re->ui->fontwidth,y,colors[linecolors[curlinecolor].color].rgba,ptr+used,linecolors[curlinecolor].len-usedlenlinecolor);
1019 1019
                                         usedcol+=redata_generic_utf8len(ptr+used,linecolors[curlinecolor].len-usedlenlinecolor);
1020 1020
                                         used+=linecolors[curlinecolor].len-usedlenlinecolor;
... ...
@@ -1022,7 +1022,7 @@ re_drawcontents(re_t *re)
1022 1022
                                         usedlenlinecolor=0;
1023 1023
                                 }
1024 1024
                                 /* for the last bytes of avail text, after writing them we save how many bytes we have processed of that linecolor to be able to continue later */
1025
-                                if((len-has_nl-used)>0 && (linecolors[curlinecolor].len-usedlenlinecolor)>(len-has_nl-used)) {
1025
+                                if(curlinecolor<nlinecolors && (len-has_nl-used)>0 && (linecolors[curlinecolor].len-usedlenlinecolor)>(len-has_nl-used)) {
1026 1026
                                         reui_write(re->ui,re->x+(tmpcol-re->origincol+usedcol)*re->ui->fontwidth,y,colors[linecolors[curlinecolor].color].rgba,ptr+used,(len-has_nl-used));
1027 1027
                                         usedcol+=redata_generic_utf8len(ptr+used,(len-has_nl-used));
1028 1028
                                         usedlenlinecolor+=(len-has_nl-used);