diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2020-09-23 18:57:57 -0700 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2020-09-23 19:56:24 -0700 |
commit | 016e590a8198009bce0e1078f6d4c7e037e2df3c (patch) | |
tree | 65f7540d987aa52c0a74e4462c613f1e136d8291 /src/searchutils.c | |
parent | c6b0b7df3a4824b9bd3ee2bb96f96ab6b1a7cb76 (diff) | |
download | grep-016e590a8198009bce0e1078f6d4c7e037e2df3c.tar.gz |
grep: fix more Turkish-eyes bugs
Fix more bugs recently uncovered by Norihiro Tanaka (Bug#43577).
* NEWS: Mention new bug report.
* src/grep.c (ok_fold): New static var.
(setup_ok_fold): New function.
(fgrep_icase_charlen): Reject single-byte characters
if they match some multibyte characters when ignoring case.
This part of the patch is partly derived from
<https://bugs.gnu.org/43577#14>, which means it is:
Co-authored-by: Norihiro Tanaka <noritnk@kcn.ne.jp>
(main): Call setup_ok_fold if ok_fold might be needed.
* src/searchutils.c (kwsinit): With the grep.c changes,
this code can now revert to classic 7th Edition Unix style;
aborting would be wrong.
* tests/turkish-eyes: Add tests for these bugs.
Diffstat (limited to 'src/searchutils.c')
-rw-r--r-- | src/searchutils.c | 23 |
1 files changed, 5 insertions, 18 deletions
diff --git a/src/searchutils.c b/src/searchutils.c index c4bb8020..aa110639 100644 --- a/src/searchutils.c +++ b/src/searchutils.c @@ -48,24 +48,11 @@ kwsinit (bool mb_trans) if (match_icase && (MB_CUR_MAX == 1 || mb_trans)) { trans = xmalloc (NCHAR); - if (MB_CUR_MAX == 1) - for (int i = 0; i < NCHAR; i++) - trans[i] = toupper (i); - else - for (int i = 0; i < NCHAR; i++) - { - wint_t wc = localeinfo.sbctowc[i]; - wint_t uwc = towupper (wc); - if (uwc != wc) - { - mbstate_t mbs = { 0 }; - size_t len = wcrtomb (&trans[i], uwc, &mbs); - if (len != 1) - abort (); - } - else - trans[i] = i; - } + /* If I is a single-byte character that becomes a different + single-byte character when uppercased, set trans[I] + to that character. Otherwise, set trans[I] to I. */ + for (int i = 0; i < NCHAR; i++) + trans[i] = toupper (i); } return kwsalloc (trans); |