diff options
author | Kevin McCarthy <kevin@8t8.us> | 2022-05-27 13:24:11 -0700 |
---|---|---|
committer | Kevin McCarthy <kevin@8t8.us> | 2022-05-27 14:15:28 -0700 |
commit | f8336984f055b151f0b212b32190249ac6f770e6 (patch) | |
tree | 42a75fffc29f3ea9564646f6c7d95bfb7f328236 | |
parent | def28317711dacf45dfbad760d952b70aaf27a58 (diff) |
Fix mbrtowc() error handling in mutt_which_case().
The function did not reset the increment value on a -2 return value.
Increase the maximum conversion size to the string length, and check
for -2. Since we're looking at the whole string, we can then just
terminate the loop on either value, assuming a case-sensitive search.
mbrtowc() will return -2 if passed n==0, so add an explicit check for
the end of string and a positive n count.
-rw-r--r-- | pattern.c | 9 |
1 files changed, 4 insertions, 5 deletions
@@ -313,15 +313,14 @@ int mutt_which_case (const char *s) { wchar_t w; mbstate_t mb; - size_t l; + size_t l, n; memset (&mb, 0, sizeof (mb)); + n = mutt_strlen (s); - for (; (l = mbrtowc (&w, s, MB_CUR_MAX, &mb)) != 0; s += l) + for (; n && *s && (l = mbrtowc (&w, s, n, &mb)) != 0; s += l, n -= l) { - if (l == (size_t) -2) - continue; /* shift sequences */ - if (l == (size_t) -1) + if (l == (size_t)(-1) || l == (size_t)(-2)) return 0; /* error; assume case-sensitive */ if (iswalpha ((wint_t) w) && iswupper ((wint_t) w)) return 0; /* case-sensitive */ |