summaryrefslogtreecommitdiff
path: root/usr/src/lib/libc
diff options
context:
space:
mode:
authorYuri Pankov <yuri.pankov@nexenta.com>2019-09-21 11:49:32 +0300
committerDan McDonald <danmcd@joyent.com>2019-10-22 11:10:03 -0400
commit1603eda21695ca85bfde0e5c75a27d94ac4ce4ff (patch)
tree15ed03687d2d6e662c6eaee0f49666da1373cf18 /usr/src/lib/libc
parent62e7498000cb79c72fafb7270dbc3beb8a41863d (diff)
downloadillumos-joyent-1603eda21695ca85bfde0e5c75a27d94ac4ce4ff.tar.gz
8908 regcomp: reduce size of bitmap for multibyte locales
Reviewed by: Andrew Stormont <andyjstormont@gmail.com> Approved by: Dan McDonald <danmcd@joyent.com>
Diffstat (limited to 'usr/src/lib/libc')
-rw-r--r--usr/src/lib/libc/port/regex/regcomp.c4
-rw-r--r--usr/src/lib/libc/port/regex/regex2.h23
-rw-r--r--usr/src/lib/libc/port/regex/utils.h6
3 files changed, 20 insertions, 13 deletions
diff --git a/usr/src/lib/libc/port/regex/regcomp.c b/usr/src/lib/libc/port/regex/regcomp.c
index 8df8c337cd..d4ab5b40b6 100644
--- a/usr/src/lib/libc/port/regex/regcomp.c
+++ b/usr/src/lib/libc/port/regex/regcomp.c
@@ -1,6 +1,6 @@
/*
* Copyright 2013 Garrett D'Amore <garrett@damore.org>
- * Copyright 2010 Nexenta Systems, Inc. All rights reserved.
+ * Copyright 2019 Nexenta by DDN, Inc. All rights reserved.
* Copyright 2012 Milan Jurik. All rights reserved.
* Copyright (c) 1992, 1993, 1994 Henry Spencer.
* Copyright (c) 1992, 1993, 1994
@@ -1778,7 +1778,7 @@ computejumps(struct parse *p, struct re_guts *g)
if (p->error != 0)
return;
- g->charjump = (int *)malloc((NC + 1) * sizeof (int));
+ g->charjump = (int *)malloc((NC_MAX + 1) * sizeof (int));
if (g->charjump == NULL) /* Not a fatal error */
return;
/* Adjust for signed chars, if necessary */
diff --git a/usr/src/lib/libc/port/regex/regex2.h b/usr/src/lib/libc/port/regex/regex2.h
index 44b20c3c24..dafc8dccc4 100644
--- a/usr/src/lib/libc/port/regex/regex2.h
+++ b/usr/src/lib/libc/port/regex/regex2.h
@@ -35,14 +35,14 @@
* First, the stuff that ends up in the outside-world include file
* typedef off_t regoff_t;
* typedef struct {
- * int re_magic;
- * size_t re_nsub; // number of parenthesized subexpressions
- * const char *re_endp; // end pointer for REG_PEND
- * struct re_guts *re_g; // none of your business :-)
+ * int re_magic;
+ * size_t re_nsub; // number of parenthesized subexpressions
+ * const char *re_endp; // end pointer for REG_PEND
+ * struct re_guts *re_g; // none of your business :-)
* } regex_t;
* typedef struct {
- * regoff_t rm_so; // start of match
- * regoff_t rm_eo; // end of match
+ * regoff_t rm_so; // start of match
+ * regoff_t rm_eo; // end of match
* } regmatch_t;
*/
/*
@@ -108,7 +108,7 @@ typedef struct {
wint_t max;
} crange;
typedef struct {
- unsigned char bmp[NC / 8];
+ unsigned char bmp[NC_MAX / 8];
wctype_t *types;
unsigned int ntypes;
wint_t *wides;
@@ -128,9 +128,14 @@ CHIN1(cset *cs, wint_t ch)
if (ch < NC)
return (((cs->bmp[ch >> 3] & (1 << (ch & 7))) != 0) ^
cs->invert);
- for (i = 0; i < cs->nwides; i++)
- if (ch == cs->wides[i])
+ for (i = 0; i < cs->nwides; i++) {
+ if (cs->icase) {
+ if (ch == towlower(cs->wides[i]) ||
+ ch == towupper(cs->wides[i]))
+ return (!cs->invert);
+ } else if (ch == cs->wides[i])
return (!cs->invert);
+ }
for (i = 0; i < cs->nranges; i++)
if (cs->ranges[i].min <= ch && ch <= cs->ranges[i].max)
return (!cs->invert);
diff --git a/usr/src/lib/libc/port/regex/utils.h b/usr/src/lib/libc/port/regex/utils.h
index b77dc69433..a1e34f3d75 100644
--- a/usr/src/lib/libc/port/regex/utils.h
+++ b/usr/src/lib/libc/port/regex/utils.h
@@ -1,5 +1,5 @@
/*
- * Copyright 2010 Nexenta Systems, Inc. All rights reserved.
+ * Copyright 2019 Nexenta by DDN, Inc. All rights reserved.
* Copyright (c) 1992, 1993, 1994 Henry Spencer.
* Copyright (c) 1992, 1993, 1994
* The Regents of the University of California. All rights reserved.
@@ -35,7 +35,9 @@
/* utility definitions */
#define DUPMAX _POSIX2_RE_DUP_MAX /* xxx is this right? */
#define INFINITY (DUPMAX + 1)
-#define NC (CHAR_MAX - CHAR_MIN + 1)
+
+#define NC_MAX (CHAR_MAX - CHAR_MIN + 1)
+#define NC ((MB_CUR_MAX) == 1 ? (NC_MAX) : (128))
typedef unsigned char uch;
/* switch off assertions (if not already off) if no REDEBUG */