From a66b22285052386225e870212c307f871d87f838 Mon Sep 17 00:00:00 2001 From: ache Date: Wed, 13 Jul 2016 18:51:19 +0000 Subject: [PATCH] After removing collation for [a-z] ranges in r302512, do it here too. Instead of trying to expand whole range at regcomp() stage as we do, GNU regex allocates separate ranges [start,end] set each character is checked against, so collation is possible and turned on for ranges here. When something like that will be implemented or our obsoleted regex code will be replaced to something like TRE, and in case we decide to use collation in [a-z] ranges, all changes related to r302512 can be backed out, but now we need consistency. --- contrib/libgnuregex/regcomp.c | 9 +++++++++ contrib/libgnuregex/regexec.c | 5 +++++ 2 files changed, 14 insertions(+) diff --git a/contrib/libgnuregex/regcomp.c b/contrib/libgnuregex/regcomp.c index 99fee76b8a8c..b9ff1bf9eac5 100644 --- a/contrib/libgnuregex/regcomp.c +++ b/contrib/libgnuregex/regcomp.c @@ -2664,7 +2664,11 @@ build_range_exp (bitset_t sbcset, bracket_elem_t *start_elem, return REG_ECOLLATE; cmp_buf[0] = start_wc; cmp_buf[4] = end_wc; +#ifdef __FreeBSD__ + if (wcscmp (cmp_buf, cmp_buf + 4) > 0) +#else if (wcscoll (cmp_buf, cmp_buf + 4) > 0) +#endif return REG_ERANGE; /* Got valid collation sequence values, add them as a new entry. @@ -2706,8 +2710,13 @@ build_range_exp (bitset_t sbcset, bracket_elem_t *start_elem, for (wc = 0; wc < SBC_MAX; ++wc) { cmp_buf[2] = wc; +#ifdef __FreeBSD__ + if (wcscmp (cmp_buf, cmp_buf + 2) <= 0 + && wcscmp (cmp_buf + 2, cmp_buf + 4) <= 0) +#else if (wcscoll (cmp_buf, cmp_buf + 2) <= 0 && wcscoll (cmp_buf + 2, cmp_buf + 4) <= 0) +#endif bitset_set (sbcset, wc); } } diff --git a/contrib/libgnuregex/regexec.c b/contrib/libgnuregex/regexec.c index 5b31f5bbd7e5..54f0ffb0d423 100644 --- a/contrib/libgnuregex/regexec.c +++ b/contrib/libgnuregex/regexec.c @@ -3964,8 +3964,13 @@ check_node_accept_bytes (const re_dfa_t *dfa, int node_idx, { cmp_buf[0] = cset->range_starts[i]; cmp_buf[4] = cset->range_ends[i]; +#ifdef __FreeBSD__ + if (wcscmp (cmp_buf, cmp_buf + 2) <= 0 + && wcscmp (cmp_buf + 2, cmp_buf + 4) <= 0) +#else if (wcscoll (cmp_buf, cmp_buf + 2) <= 0 && wcscoll (cmp_buf + 2, cmp_buf + 4) <= 0) +#endif { match_len = char_len; goto check_node_accept_bytes_match;