summaryrefslogtreecommitdiff
path: root/src/dged
diff options
context:
space:
mode:
authorAlbert Cervin <albert@acervin.com>2024-03-27 11:01:08 +0100
committerAlbert Cervin <albert@acervin.com>2024-03-27 11:01:08 +0100
commit80e6ab5ec9fdb0f4a3b3fa35e4ea502a54b85e1a (patch)
tree89aba4244d946c50a87701ed632da2923e8d8f9f /src/dged
parent1b888cc723792ec0e49c7e5aaa78c3c5486a95b9 (diff)
downloaddged-80e6ab5ec9fdb0f4a3b3fa35e4ea502a54b85e1a.tar.gz
dged-80e6ab5ec9fdb0f4a3b3fa35e4ea502a54b85e1a.tar.xz
dged-80e6ab5ec9fdb0f4a3b3fa35e4ea502a54b85e1a.zip
Do something better when wcwidth returns -1
On systems that has unkown widths for emojis for example, using -1 for width is not a good fallback.
Diffstat (limited to 'src/dged')
-rw-r--r--src/dged/utf8.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/dged/utf8.c b/src/dged/utf8.c
index b71a7e1..52de2da 100644
--- a/src/dged/utf8.c
+++ b/src/dged/utf8.c
@@ -72,9 +72,10 @@ uint32_t utf8_visual_char_width(uint8_t *bytes, uint32_t len) {
wchar_t wc;
size_t nbytes = 0;
if ((nbytes = mbrtowc(&wc, (char *)bytes, len, NULL)) > 0) {
- return wcwidth(wc);
+ size_t w = wcwidth(wc);
+ return w > 0 ? w : 2;
} else {
- return 0;
+ return 1;
}
} else if (utf8_byte_is_unicode_continuation(*bytes)) {
return 0;