Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: Re: Bug in colored listings with backreference patterns?



Bart Schaefer wrote:

> Possibly related is a repeatable core dump I'm getting.
> 
> ------------------------------------------------------------------------
> setopt extendedglob	# Doc for ZLS_COLORS should mention this
> zstyle ':completion:*:zsh-options' list-colors \
> 	'no=22:=(#b)(sh|csh|ksh)#(*glob*)#*=39=04;32=31'
> # The above crashes the shell, but if this 04; ^^^ is removed, it works.
> ------------------------------------------------------------------------
> 
> I have zsh-mem-debug enabled, and it appears to be dereferencing through
> what used to be a pointer inside a struct that has since been freed (it's
> dereferncing 0xffffffff), possibly in getcoldef() -- the stack is mostly
> garbage, even running inside GDB.
> 
> What you should see if the pattern above works, is that all options that
> start with sh|csh|ksh are underlined and have the shell name in green; if
> the substring "glob" appears, then the rest is in red (still underlined);
> and all other options that contain "glob" are in red (but not underlined).

Wrong calculation of the maximum capability length (which was then
used in a VARARR, which messed up the stack).

Bye
 Sven

Index: Src/Zle/complist.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/complist.c,v
retrieving revision 1.25
diff -u -r1.25 complist.c
--- Src/Zle/complist.c	2000/06/11 08:15:27	1.25
+++ Src/Zle/complist.c	2000/06/13 10:38:06
@@ -122,13 +122,17 @@
     Extcol exts;		/* strings for extensions */
 };
 
+/* Combined length of LC and RC, maximum length of capability strings. */
+
+static int lr_caplen, max_caplen;
+
 /* This parses the value of a definition (the part after the `=').
  * The return value is a pointer to the character after it. */
 
 static char *
 getcolval(char *s, int multi)
 {
-    char *p;
+    char *p, *o = s;
 
     for (p = s; *s && *s != ':' && (!multi || *s != '='); p++, s++) {
 	if (*s == '\\' && s[1]) {
@@ -172,6 +176,8 @@
     }
     if (p != s)
 	*p = '\0';
+    if ((s - o) > max_caplen)
+	max_caplen = s - o;
     return s;
 }
 
@@ -325,10 +331,6 @@
     return fc;
 }
 
-/* Combined length of LC and RC, maximum length of capability strings. */
-
-static int lr_caplen, max_caplen;
-
 /* This initializes the given terminal color structure. */
 
 static void
@@ -337,6 +339,7 @@
     char *s;
     int i, l;
 
+    max_caplen = lr_caplen = 0;
     if (!(s = getsparam("ZLS_COLORS")) &&
 	!(s = getsparam("ZLS_COLOURS"))) {
 	for (i = 0; i < NUM_COLS; i++)
@@ -362,7 +365,6 @@
 	s = getcoldef(c, s);
 
     /* Use default values for those that aren't set explicitly. */
-    max_caplen = lr_caplen = 0;
     for (i = 0; i < NUM_COLS; i++) {
 	if (!c->files[i] || !c->files[i]->col)
 	    c->files[i] = filecol(defcols[i]);

--
Sven Wischnowsky                         wischnow@xxxxxxxxxxxxxxxxxxxxxxx



Messages sorted by: Reverse Date, Date, Thread, Author