summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2024-03-20 16:56:46 -0400
committerTavian Barnes <tavianator@tavianator.com>2024-03-20 16:56:46 -0400
commit54490a29006529f7ceb4dc0514a075f9f4175621 (patch)
tree2362a394bce4f8b2b2b51ed16f835a4aa7d9ffba /src
parent745fd4be765407f7c56d61c281c28e2468ba25b5 (diff)
downloadbfs-54490a29006529f7ceb4dc0514a075f9f4175621.tar.xz
bfstd: Check that wcwidth() is positive
wcwidth() returns -1 for non-printable characters, but terminals typically don't print anything for them, so treat them as 0.
Diffstat (limited to 'src')
-rw-r--r--src/bfstd.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/bfstd.c b/src/bfstd.c
index c6c2e7f..5b64452 100644
--- a/src/bfstd.c
+++ b/src/bfstd.c
@@ -695,8 +695,12 @@ size_t xstrwidth(const char *str) {
if (wc == WEOF) {
// Assume a single-width '?'
++ret;
- } else {
- ret += xwcwidth(wc);
+ continue;
+ }
+
+ int width = xwcwidth(wc);
+ if (width > 0) {
+ ret += width;
}
}