summaryrefslogtreecommitdiff
path: root/src/searchutils.c
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2014-09-14 14:52:56 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2014-09-16 18:23:49 -0700
commit6e319a818ed7b15b452ed2baab2f6a38d42fd1fe (patch)
tree42a80dcac7ef57d4ca41df6f4ddb03c38d4fce16 /src/searchutils.c
parentcd36abd46c5e0768606979ea75a51732062f5624 (diff)
downloadgrep-6e319a818ed7b15b452ed2baab2f6a38d42fd1fe.tar.gz
grep: improve performance for older glibc
glibc has a bug where mbrlen and mbrtowc mishandle length-0 inputs. Working around it in gnulib slows grep down, so disable the tests for it and make sure grep works even if the bug is present. * bootstrap.conf (avoided_gnulib_modules): Add mbrtowc-tests. * configure.ac (gl_cv_func_mbrtowc_empty_input): Assume yes. * src/searchutils.c (mb_next_wc): Don't invoke mbrtowc on empty input.
Diffstat (limited to 'src/searchutils.c')
-rw-r--r--src/searchutils.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/searchutils.c b/src/searchutils.c
index 5eb9a12f..18dd584e 100644
--- a/src/searchutils.c
+++ b/src/searchutils.c
@@ -285,5 +285,6 @@ mb_next_wc (char const *cur, char const *end)
{
wchar_t wc;
mbstate_t mbs = { 0 };
- return mbrtowc (&wc, cur, end - cur, &mbs) < (size_t) -2 ? wc : WEOF;
+ return (end - cur != 0 && mbrtowc (&wc, cur, end - cur, &mbs) < (size_t) -2
+ ? wc : WEOF);
}