]> Savannah Git Hosting - gnulib.git/commitdiff
dfa: avoid false match in non-UTF8 multibyte locales
authorJim Meyering <meyering@fb.com>
Sun, 27 Nov 2016 23:36:51 +0000 (15:36 -0800)
committerJim Meyering <meyering@fb.com>
Sun, 27 Nov 2016 23:36:51 +0000 (15:36 -0800)
* lib/dfa.c (dfa_supported): Treat any non-UTF8 multibyte locale
as "not supported" so that callers will resort to using regex-based
matcher.  This will surely hurt performance, but correctness trumps
performance here, and the affected locales are less and less relevant,
these days.  See grep's bug report https://bugs.gnu.org/24975.

ChangeLog
lib/dfa.c

index 0db3da8ada84952e0dd6ac3be798c8cccbd3c293..fec4fb953cb0b4043e59f0fa42c5f6b5e8f43c0d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2016-11-27  Jim Meyering  <meyering@fb.com>
+
+       dfa: avoid false match in non-UTF8 multibyte locales
+       * lib/dfa.c (dfa_supported): Treat any non-UTF8 multibyte locale
+       as "not supported" so that callers will resort to using regex-based
+       matcher.  This will surely hurt performance, but correctness trumps
+       performance here, and the affected locales are less and less relevant,
+       these days.  See grep's bug report https://bugs.gnu.org/24975.
+
 2016-11-27  Mike Frysinger  <vapier@gentoo.org>
 
        ptsname_r: leverage AC_HEADER_MAJOR to provide major()
index 55782324e34bdceb119517467a60e68fca637e11..f0ed139d3d3434ce1782ac514b5e881287e7f545 100644 (file)
--- a/lib/dfa.c
+++ b/lib/dfa.c
@@ -3272,6 +3272,12 @@ free_mbdata (struct dfa *d)
 static bool _GL_ATTRIBUTE_PURE
 dfa_supported (struct dfa const *d)
 {
+  /* Declare any non-UTF8 multibyte locale "not supported."  Otherwise, a
+     regexp like ".*7" would mistakenly match \uC9, e.g., via this command:
+     (export LC_ALL=zh_CN.gb18030; printf '\uC9\n' | grep '.*7')  */
+  if (d->localeinfo.multibyte && !d->localeinfo.using_utf8)
+    return false;
+
   size_t i;
   for (i = 0; i < d->tindex; i++)
     {