Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F136931713
D18297.id50940.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
D18297.id50940.diff
View Options
Index: lib/libc/regex/engine.c
===================================================================
--- lib/libc/regex/engine.c
+++ lib/libc/regex/engine.c
@@ -48,6 +48,7 @@
*/
#ifdef SNAMES
+#define stepback sstepback
#define matcher smatcher
#define walk swalk
#define dissect sdissect
@@ -58,6 +59,7 @@
#define match smat
#endif
#ifdef LNAMES
+#define stepback lstepback
#define matcher lmatcher
#define walk lwalk
#define dissect ldissect
@@ -68,6 +70,7 @@
#define match lmat
#endif
#ifdef MNAMES
+#define stepback mstepback
#define matcher mmatcher
#define walk mwalk
#define dissect mdissect
@@ -141,6 +144,39 @@
#define NOTE(s) /* nothing */
#endif
+/*
+ * Given a multibyte string pointed to by start, step back nchar characters
+ * from current position pointed to by cur.
+ */
+static const char *
+stepback(const char *start, const char *cur, int nchar)
+{
+ const char *ret;
+ int wc, mbc;
+ mbstate_t mbs;
+ size_t clen;
+
+ if (MB_CUR_MAX == 1)
+ return ((cur - nchar) > start ? cur - nchar : NULL);
+
+ ret = cur;
+ for (wc = nchar; wc > 0; wc--) {
+ for (mbc = 1; mbc <= MB_CUR_MAX; mbc++) {
+ if ((ret - mbc) < start)
+ return (NULL);
+ memset(&mbs, 0, sizeof(mbs));
+ clen = mbrtowc(NULL, ret - mbc, mbc, &mbs);
+ if (clen != (size_t)-1 && clen != (size_t)-2)
+ break;
+ }
+ if (mbc > MB_CUR_MAX)
+ return (NULL);
+ ret -= mbc;
+ }
+
+ return (ret);
+}
+
/*
- matcher - the actual matching engine
== static int matcher(struct re_guts *g, const char *string, \
@@ -244,8 +280,13 @@
ZAPSTATE(&m->mbs);
/* Adjust start according to moffset, to speed things up */
- if (dp != NULL && g->moffset > -1)
- start = ((dp - g->moffset) < start) ? start : dp - g->moffset;
+ if (dp != NULL && g->moffset > -1) {
+ const char *nstart;
+
+ nstart = stepback(start, dp, g->moffset);
+ if (nstart != NULL)
+ start = nstart;
+ }
SP("mloop", m->st, *start);
@@ -1083,6 +1124,7 @@
#endif
#endif
+#undef stepback
#undef matcher
#undef walk
#undef dissect
Index: lib/libc/tests/regex/Makefile.inc
===================================================================
--- lib/libc/tests/regex/Makefile.inc
+++ lib/libc/tests/regex/Makefile.inc
@@ -4,6 +4,9 @@
BINDIR?= ${TESTSDIR}
+# local test cases
+ATF_TESTS_SH+= multibyte
+
# SKIP_LEFTASSOC -> these testcases fail on FreeBSD.
IMPLEMENTATION?= -DREGEX_SPENCER -DSKIP_LEFTASSOC
Index: lib/libc/tests/regex/multibyte.sh
===================================================================
--- /dev/null
+++ lib/libc/tests/regex/multibyte.sh
@@ -0,0 +1,35 @@
+# $FreeBSD$
+
+atf_test_case multibyte
+multibyte_head()
+{
+ atf_set "descr" "Check matching multibyte characters (PR153502)"
+}
+multibyte_body()
+{
+ export LC_CTYPE="C.UTF-8"
+
+ printf 'é' | atf_check -o "inline:é" \
+ sed -ne '/^.$/p'
+ printf 'éé' | atf_check -o "inline:éé" \
+ sed -ne '/^..$/p'
+ printf 'aéa' | atf_check -o "inline:aéa" \
+ sed -ne '/a.a/p'
+ printf 'aéa'| atf_check -o "inline:aéa" \
+ sed -ne '/a.*a/p'
+ printf 'aaéaa' | atf_check -o "inline:aaéaa" \
+ sed -ne '/aa.aa/p'
+ printf 'aéaéa' | atf_check -o "inline:aéaéa" \
+ sed -ne '/a.a.a/p'
+ printf 'éa' | atf_check -o "inline:éa" \
+ sed -ne '/.a/p'
+ printf 'aéaa' | atf_check -o "inline:aéaa" \
+ sed -ne '/a.aa/p'
+ printf 'éaé' | atf_check -o "inline:éaé" \
+ sed -ne '/.a./p'
+}
+
+atf_init_test_cases()
+{
+ atf_add_test_case multibyte
+}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Nov 21, 5:36 PM (3 h, 49 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
25782535
Default Alt Text
D18297.id50940.diff (3 KB)
Attached To
Mode
D18297: PR153502: [libc] regex(3) bug with UTF-8 locale
Attached
Detach File
Event Timeline
Log In to Comment