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

Re: [BUG] SIGSEGV under certain circumstances



On Mar 5,  1:45pm, Bart Schaefer wrote:
}
} This will fail in this case, I would think?  We have to unmetafy first,
} possibly several bytes ahead, and THEN attempt multibyte conversion;
} not do either one or the other?

So the following is probably deeply in need of optimization (needs a
version of unmeta() that stops after the widest possible mutltibyte
character), but just to check my hypothesis:

diff --git a/Src/Zle/compmatch.c b/Src/Zle/compmatch.c
index aedf463..b0252c2 100644
--- a/Src/Zle/compmatch.c
+++ b/Src/Zle/compmatch.c
@@ -1548,7 +1548,7 @@ pattern_match(Cpattern p, char *s, Cpattern wp, char *ws)
 {
     convchar_t c, wc;
     convchar_t ind, wind;
-    int len = 0, wlen, mt, wmt;
+    int len = 0, wlen = 0, mt, wmt;
 #ifdef MULTIBYTE_SUPPORT
     mbstate_t lstate, wstate;
 
@@ -1559,7 +1559,13 @@ pattern_match(Cpattern p, char *s, Cpattern wp, char *ws)
     while (p && wp && *s && *ws) {
 	/* First test the word character */
 #ifdef MULTIBYTE_SUPPORT
-	wlen = mb_metacharlenconv_r(ws, &wc, &wstate);
+	int ulen = mb_metacharlenconv_r(unmeta(ws), &wc, &wstate);
+	while (ulen-- > 0) {
+	    if (ws[wlen] == Meta)
+		wlen += 2;
+	    else
+		wlen += 1;
+	}
 #else
 	if (*ws == Meta) {
 	    wc = STOUC(ws[1]) ^ 32;
@@ -1577,7 +1583,13 @@ pattern_match(Cpattern p, char *s, Cpattern wp, char *ws)
 	 * Now the line character.
 	 */
 #ifdef MULTIBYTE_SUPPORT
-	len = mb_metacharlenconv_r(s, &c, &lstate);
+	ulen = mb_metacharlenconv_r(unmeta(s), &c, &lstate);
+	while (ulen-- > 0) {
+	    if (s[len] == Meta)
+		len += 2;
+	    else
+		len += 1;
+	}
 #else
 	/* We have the character itself. */
 	if (*s == Meta) {
@@ -1624,11 +1636,20 @@ pattern_match(Cpattern p, char *s, Cpattern wp, char *ws)
 	ws += wlen;
 	p = p->next;
 	wp = wp->next;
+#ifdef MULTIBYTE_SUPPORT
+	len = wlen = 0;
+#endif
     }
 
     while (p && *s) {
 #ifdef MULTIBYTE_SUPPORT
-	len = mb_metacharlenconv_r(s, &c, &lstate);
+	int ulen = mb_metacharlenconv_r(unmeta(s), &c, &lstate);
+	while (ulen-- > 0) {
+	    if (s[len] == Meta)
+		len += 2;
+	    else
+		len += 1;
+	}
 #else
 	if (*s == Meta) {
 	    c = STOUC(s[1]) ^ 32;
@@ -1642,11 +1663,20 @@ pattern_match(Cpattern p, char *s, Cpattern wp, char *ws)
 	    return 0;
 	p = p->next;
 	s += len;
+#ifdef MULTIBYTE_SUPPORT
+	len = 0;
+#endif
     }
 
     while (wp && *ws) {
 #ifdef MULTIBYTE_SUPPORT
-	wlen = mb_metacharlenconv_r(ws, &wc, &wstate);
+	int ulen = mb_metacharlenconv_r(unmeta(ws), &wc, &wstate);
+	while (ulen-- > 0) {
+	    if (ws[wlen] == Meta)
+		wlen += 2;
+	    else
+		wlen += 1;
+	}
 #else
 	if (*ws == Meta) {
 	    wc = STOUC(ws[1]) ^ 32;
@@ -1660,6 +1690,9 @@ pattern_match(Cpattern p, char *s, Cpattern wp, char *ws)
 	    return 0;
 	wp = wp->next;
 	ws += wlen;
+#ifdef MULTIBYTE_SUPPORT
+	wlen = 0;
+#endif
     }
 
     return 1;



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