summaryrefslogtreecommitdiff
path: root/Src/Zle/compmatch.c
diff options
context:
space:
mode:
authorBarton E. Schaefer <schaefer@zsh.org>2017-03-08 21:26:55 -0800
committerBarton E. Schaefer <schaefer@zsh.org>2017-03-08 21:26:55 -0800
commit071017965f469c88b10467205f30ea3e609e56dc (patch)
treea6472c26ba37ff83be987c782eef231d989d2607 /Src/Zle/compmatch.c
parent67d882479b61165c5d58bd72430d6009f4a7f25f (diff)
downloadzsh-071017965f469c88b10467205f30ea3e609e56dc.tar.gz
zsh-071017965f469c88b10467205f30ea3e609e56dc.zip
40763: count wide characters and Cmatcher pointers more sanely in cfp_matcher_pats(), and count characters in pattern_match() the same way to stay in sync
Might not fix wide-char matching in completion matcher-lists but should avoid wild pointer crash
Diffstat (limited to 'Src/Zle/compmatch.c')
-rw-r--r--Src/Zle/compmatch.c57
1 files changed, 5 insertions, 52 deletions
diff --git a/Src/Zle/compmatch.c b/Src/Zle/compmatch.c
index aedf463fc..1cdbb8a48 100644
--- a/Src/Zle/compmatch.c
+++ b/Src/Zle/compmatch.c
@@ -1548,27 +1548,11 @@ pattern_match(Cpattern p, char *s, Cpattern wp, char *ws)
{
convchar_t c, wc;
convchar_t ind, wind;
- int len = 0, wlen, mt, wmt;
-#ifdef MULTIBYTE_SUPPORT
- mbstate_t lstate, wstate;
-
- memset(&lstate, 0, sizeof(lstate));
- memset(&wstate, 0, sizeof(wstate));
-#endif
+ int len = 0, wlen = 0, mt, wmt;
while (p && wp && *s && *ws) {
/* First test the word character */
-#ifdef MULTIBYTE_SUPPORT
- wlen = mb_metacharlenconv_r(ws, &wc, &wstate);
-#else
- if (*ws == Meta) {
- wc = STOUC(ws[1]) ^ 32;
- wlen = 2;
- } else {
- wc = STOUC(*ws);
- wlen = 1;
- }
-#endif
+ wc = unmeta_one(ws, &wlen);
wind = pattern_match1(wp, wc, &wmt);
if (!wind)
return 0;
@@ -1576,18 +1560,7 @@ pattern_match(Cpattern p, char *s, Cpattern wp, char *ws)
/*
* Now the line character.
*/
-#ifdef MULTIBYTE_SUPPORT
- len = mb_metacharlenconv_r(s, &c, &lstate);
-#else
- /* We have the character itself. */
- if (*s == Meta) {
- c = STOUC(s[1]) ^ 32;
- len = 2;
- } else {
- c = STOUC(*s);
- len = 1;
- }
-#endif
+ c = unmeta_one(s, &len);
/*
* If either is "?", they match each other; no further tests.
* Apply this even if the character wasn't convertable;
@@ -1627,17 +1600,7 @@ pattern_match(Cpattern p, char *s, Cpattern wp, char *ws)
}
while (p && *s) {
-#ifdef MULTIBYTE_SUPPORT
- len = mb_metacharlenconv_r(s, &c, &lstate);
-#else
- if (*s == Meta) {
- c = STOUC(s[1]) ^ 32;
- len = 2;
- } else {
- c = STOUC(*s);
- len = 1;
- }
-#endif
+ c = unmeta_one(s, &len);
if (!pattern_match1(p, c, &mt))
return 0;
p = p->next;
@@ -1645,17 +1608,7 @@ pattern_match(Cpattern p, char *s, Cpattern wp, char *ws)
}
while (wp && *ws) {
-#ifdef MULTIBYTE_SUPPORT
- wlen = mb_metacharlenconv_r(ws, &wc, &wstate);
-#else
- if (*ws == Meta) {
- wc = STOUC(ws[1]) ^ 32;
- wlen = 2;
- } else {
- wc = STOUC(*ws);
- wlen = 1;
- }
-#endif
+ wc = unmeta_one(ws, &wlen);
if (!pattern_match1(wp, wc, &wmt))
return 0;
wp = wp->next;