--- glob.c-mb Sun Dec 16 20:45:47 2012 +++ glob.c-isw Wed Dec 19 10:45:22 2012 @@ -96,8 +96,6 @@ #include #include -#include "charclass.h" - #define DOLLAR '$' #define DOT '.' #define EOS '\0' @@ -466,7 +464,8 @@ const Char *pattern = *patternp + 1; Char *bufnext = *bufnextp; const Char *colon; - struct cclass *cc; + char cbuf[MB_LEN_MAX + 32]; + wctype_t cc; size_t len; if ((colon = g_strchr(pattern, COLON)) == NULL || @@ -474,26 +473,33 @@ return (1); /* not a character class */ len = (size_t)(colon - pattern); - for (cc = cclasses; cc->name != NULL; cc++) { + if (len + MB_LEN_MAX + 1 > sizeof (cbuf)) + return (-1); /* invalid character class */ + { wchar_t w; const Char *s1 = pattern; - const char *s2 = cc->name; + char *s2 = cbuf; size_t n = len; - /* Are the strings the same? */ - while (n > 0 && (w = (s1++)->wc) == *s2 && w != EOS) { - n--; - s2++; + /* Copy the string. */ + while (n > 0) { + w = (s1++)->wc; + /* Only single byte characters. */ + if (wctomb(s2, w) == 1) { + n--; + s2++; + } else { + return (-1); /* invalid character class */ + } } - if (n == 0 && *s2 == EOS) - break; + *s2 = EOS; } - if (cc->name == NULL) + if ((cc = wctype(cbuf)) == 0) return (-1); /* invalid character class */ bufnext->at = M_QUOTE; (bufnext++)->wc = M_CLASS; - bufnext->at = (cc - &cclasses[0]); - (bufnext++)->wc = COLON; + bufnext->at = 0; + (bufnext++)->wc = cc; *bufnextp = bufnext; *patternp += len + 3; @@ -1080,12 +1086,11 @@ ++pat; while (((c = *pat++).at != M_QUOTE) || c.wc != M_END) { if (c.at == M_QUOTE && c.wc == M_CLASS) { - Char idx; + Char cc; - idx.at = pat->at; - idx.wc = pat->wc; - if (idx.at < NCCLASSES && - cclasses[idx.at].isctype(k.wc)) + cc.at = pat->at; + cc.wc = pat->wc; + if (iswctype(k.wc, cc.wc)) ok = 1; ++pat; }