summaryrefslogtreecommitdiff
path: root/usr.bin/less
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@cvs.openbsd.org>2019-03-14 16:21:36 +0000
committerIngo Schwarze <schwarze@cvs.openbsd.org>2019-03-14 16:21:36 +0000
commit5f1a7fbe2f8cd57fa7afd4924620468a10b957fe (patch)
tree0378941889c4c23afb5d5eeb27face9c941062b9 /usr.bin/less
parentf0ad0ef22c330a46e5b5470a527d495219a7da89 (diff)
Cleanup and bugfix:
When looking for uppercase characters, iterate over multibyte characters with the standard function mbtowc(3) rather than with the buggy and outdated step_char(), skipping invalid bytes, and correctly use iswupper(3) instead of the inapplicable isupper(3). OK stsp@
Diffstat (limited to 'usr.bin/less')
-rw-r--r--usr.bin/less/search.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/usr.bin/less/search.c b/usr.bin/less/search.c
index 48e5314cbf5..770ff0cf5b1 100644
--- a/usr.bin/less/search.c
+++ b/usr.bin/less/search.c
@@ -75,12 +75,14 @@ static struct pattern_info filter_info;
static int
is_ucase(char *str)
{
- char *str_end = str + strlen(str);
- LWCHAR ch;
-
- while (str < str_end) {
- ch = step_char(&str, +1, str_end);
- if (isupper(ch))
+ wchar_t ch;
+ int len;
+
+ for (; *str != '\0'; str += len) {
+ if ((len = mbtowc(&ch, str, MB_CUR_MAX)) == -1) {
+ mbtowc(NULL, NULL, MB_CUR_MAX);
+ len = 1;
+ } else if (iswupper(ch))
return (1);
}
return (0);