From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-workers@zsh.org
Cc: Chi-Hsuan Yen <yan12125@gmail.com>
Subject: Re: [BUG] SIGSEGV under certain circumstances
Date: Sun, 5 Mar 2017 14:31:18 -0800 [thread overview]
Message-ID: <170305143118.ZM3173@torch.brasslantern.com> (raw)
In-Reply-To: <170305134513.ZM26364@torch.brasslantern.com>
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;
next prev parent reply other threads:[~2017-03-05 22:31 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-01 15:38 Chi-Hsuan Yen
2017-03-04 23:11 ` Bart Schaefer
2017-03-05 12:55 ` Chi-Hsuan Yen
2017-03-05 13:09 ` Chi-Hsuan Yen
2017-03-05 16:00 ` Bart Schaefer
2017-03-05 16:17 ` Peter Stephenson
2017-03-05 18:42 ` Bart Schaefer
2017-03-05 18:52 ` Peter Stephenson
2017-03-05 21:45 ` Bart Schaefer
2017-03-05 22:31 ` Bart Schaefer [this message]
2017-03-05 22:41 ` Daniel Shahaf
2017-03-05 22:51 ` Bart Schaefer
2017-03-05 23:07 ` Bart Schaefer
2017-03-06 0:23 ` Bart Schaefer
2017-03-06 9:47 ` Peter Stephenson
2017-03-06 17:10 ` Bart Schaefer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=170305143118.ZM3173@torch.brasslantern.com \
--to=schaefer@brasslantern.com \
--cc=yan12125@gmail.com \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).