From fe5bf674e6b7bd2a4d807602f0210480fe93e9b1 Mon Sep 17 00:00:00 2001 From: Kyle Evans Date: Mon, 22 Jan 2018 02:58:33 +0000 Subject: Add missing patch from r328240 regcomp uses some libc internal collation bits that are not available in the libregex context. It's easy enough to bring in the needed parts that can work in a libregex world, so do so. Pointy hat to: me --- lib/libc/regex/regcomp.c | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) (limited to 'lib/libc/regex') diff --git a/lib/libc/regex/regcomp.c b/lib/libc/regex/regcomp.c index 37d37a9bc52e..586621c5a745 100644 --- a/lib/libc/regex/regcomp.c +++ b/lib/libc/regex/regcomp.c @@ -57,7 +57,9 @@ __FBSDID("$FreeBSD$"); #include #include +#ifndef LIBREGEX #include "collate.h" +#endif #include "utils.h" #include "regex2.h" @@ -124,6 +126,7 @@ static void p_re(struct parse *p, int end1, int end2); static bool p_simp_re(struct parse *p, struct branchc *bc); static int p_count(struct parse *p); static void p_bracket(struct parse *p); +static int p_range_cmp(wchar_t c1, wchar_t c2); static void p_b_term(struct parse *p, cset *cs); static void p_b_cclass(struct parse *p, cset *cs); static void p_b_eclass(struct parse *p, cset *cs); @@ -904,6 +907,23 @@ p_bracket(struct parse *p) EMIT(OANYOF, (int)(cs - p->g->sets)); } +static int +p_range_cmp(wchar_t c1, wchar_t c2) +{ +#ifndef LIBREGEX + return __wcollate_range_cmp(c1, c2); +#else + /* Copied from libc/collate __wcollate_range_cmp */ + wchar_t s1[2], s2[2]; + + s1[0] = c1; + s1[1] = L'\0'; + s2[0] = c2; + s2[1] = L'\0'; + return (wcscoll(s1, s2)); +#endif +} + /* - p_b_term - parse one term of a bracketed character list == static void p_b_term(struct parse *p, cset *cs); @@ -914,9 +934,10 @@ p_b_term(struct parse *p, cset *cs) char c; wint_t start, finish; wint_t i; +#ifndef LIBREGEX struct xlocale_collate *table = (struct xlocale_collate*)__get_locale()->components[XLC_COLLATE]; - +#endif /* classify what we've got */ switch ((MORE()) ? PEEK() : '\0') { case '[': @@ -963,15 +984,18 @@ p_b_term(struct parse *p, cset *cs) if (start == finish) CHadd(p, cs, start); else { +#ifndef LIBREGEX if (table->__collate_load_error || MB_CUR_MAX > 1) { +#else + if (MB_CUR_MAX > 1) { +#endif (void)REQUIRE(start <= finish, REG_ERANGE); CHaddrange(p, cs, start, finish); } else { - (void)REQUIRE(__wcollate_range_cmp(start, finish) <= 0, REG_ERANGE); + (void)REQUIRE(p_range_cmp(start, finish) <= 0, REG_ERANGE); for (i = 0; i <= UCHAR_MAX; i++) { - if ( __wcollate_range_cmp(start, i) <= 0 - && __wcollate_range_cmp(i, finish) <= 0 - ) + if (p_range_cmp(start, i) <= 0 && + p_range_cmp(i, finish) <= 0 ) CHadd(p, cs, i); } } -- cgit v1.2.3