summaryrefslogtreecommitdiffstats
path: root/lib/libc/regex
diff options
context:
space:
mode:
authortjr <tjr@FreeBSD.org>2004-09-05 08:30:42 +0000
committertjr <tjr@FreeBSD.org>2004-09-05 08:30:42 +0000
commit16f5889d652ee6efae45f9ccfb7f65f9c97efaf4 (patch)
tree6203250c9def2e38b4900eb5e5a064134c75336a /lib/libc/regex
parent24d8f8ddcef45b252500e769bda933ecd4c7c30f (diff)
downloadFreeBSD-src-16f5889d652ee6efae45f9ccfb7f65f9c97efaf4.zip
FreeBSD-src-16f5889d652ee6efae45f9ccfb7f65f9c97efaf4.tar.gz
Fix two problems with REG_ICASE that were introduced with the addition of
multibyte character support: - In CHadd(), avoid writing past the end of the character set bitmap when the opposite-case counterpart of wide characters with values less than NC have values greater than or equal to NC. - In CHaddtype(), fix a braino that caused alphabetic characters to be added to all character classes! (but only with REG_ICASE) PR: 71367
Diffstat (limited to 'lib/libc/regex')
-rw-r--r--lib/libc/regex/regcomp.c23
1 files changed, 10 insertions, 13 deletions
diff --git a/lib/libc/regex/regcomp.c b/lib/libc/regex/regcomp.c
index 7c10f62..ace6d0a 100644
--- a/lib/libc/regex/regcomp.c
+++ b/lib/libc/regex/regcomp.c
@@ -1199,15 +1199,11 @@ struct parse *p;
cset *cs;
wint_t ch;
{
- wint_t *newwides;
+ wint_t nch, *newwides;
assert(ch >= 0);
- if (ch < NC) {
+ if (ch < NC)
cs->bmp[ch >> 3] |= 1 << (ch & 7);
- if (cs->icase) {
- cs->bmp[towlower(ch) >> 3] |= 1 << (towlower(ch) & 7);
- cs->bmp[towupper(ch) >> 3] |= 1 << (towupper(ch) & 7);
- }
- } else {
+ else {
newwides = realloc(cs->wides, (cs->nwides + 1) *
sizeof(*cs->wides));
if (newwides == NULL) {
@@ -1217,6 +1213,12 @@ wint_t ch;
cs->wides = newwides;
cs->wides[cs->nwides++] = ch;
}
+ if (cs->icase) {
+ if ((nch = towlower(ch)) < NC)
+ cs->bmp[nch >> 3] |= 1 << (nch & 7);
+ if ((nch = towupper(ch)) < NC)
+ cs->bmp[nch >> 3] |= 1 << (nch & 7);
+ }
}
/*
@@ -1258,14 +1260,9 @@ wctype_t wct;
wint_t i;
wctype_t *newtypes;
- for (i = 0; i < NC; i++) {
+ for (i = 0; i < NC; i++)
if (iswctype(i, wct))
CHadd(p, cs, i);
- if (cs->icase && i != towlower(i))
- CHadd(p, cs, towlower(i));
- if (cs->icase && i != towupper(i))
- CHadd(p, cs, towupper(i));
- }
newtypes = realloc(cs->types, (cs->ntypes + 1) *
sizeof(*cs->types));
if (newtypes == NULL) {
OpenPOWER on IntegriCloud