summaryrefslogtreecommitdiffstats
path: root/src/bfstd.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2023-09-06 16:23:10 -0400
committerTavian Barnes <tavianator@tavianator.com>2023-09-06 16:35:39 -0400
commit90f9205b40b2f2049df46d819d14d67bfcb055be (patch)
treea2829130307c85d74b3c83562cfd20a15f3168f3 /src/bfstd.c
parent377709664480a30fa5acdd11c7ca8c16669678ce (diff)
downloadbfs-90f9205b40b2f2049df46d819d14d67bfcb055be.tar.xz
bfstd: Fix printable_len() off-by-one
If xmbrtowc() fails, or if xiswprint() is false, then we shouldn't include that wide char in the printable length. Fixes: 19c96abe0a1ee56cf206fd5e87defb1fd3e0daa5
Diffstat (limited to 'src/bfstd.c')
-rw-r--r--src/bfstd.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/bfstd.c b/src/bfstd.c
index 2d9f60a..61d2fee 100644
--- a/src/bfstd.c
+++ b/src/bfstd.c
@@ -666,9 +666,9 @@ static size_t printable_len(const char *str, size_t len, enum wesc_flags flags)
multibyte:
memset(&mb, 0, sizeof(mb));
- while (i < len) {
+ for (size_t j = i; i < len; i = j) {
wchar_t wc;
- if (xmbrtowc(&wc, &i, str, len, &mb) != 0) {
+ if (xmbrtowc(&wc, &j, str, len, &mb) != 0) {
break;
}
if (!xiswprint(wc, flags)) {