aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2020-01-23 16:39:25 +0000
committerDaniel Eklöf <daniel@ekloef.se>2020-01-23 16:39:25 +0000
commit75b8fc52b85c945e71a6fb6f2e616ee242b07b43 (patch)
tree1ebb14462530d19cd03e7a5ac26073f500219ca8
parentcsi: disable save/restore highlight mouse tracking (diff)
vt: bug: fix check for error from mbrtowc()
mbrtowc() returns an unsigned. Need to cast to signed before checking if less than zero. This fixes an issue where invalid utf-8 sequences where treated as valid.
-rw-r--r--vt.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/vt.c b/vt.c
index 8eeefda2..4af40789 100644
--- a/vt.c
+++ b/vt.c
@@ -474,7 +474,10 @@ action_utf8_print(struct terminal *term, uint8_t c)
/* Convert to wchar */
mbstate_t ps = {0};
wchar_t wc;
- if (mbrtowc(&wc, (const char *)term->vt.utf8.data, term->vt.utf8.idx, &ps) < 0)
+ size_t count = mbrtowc(
+ &wc, (const char *)term->vt.utf8.data, term->vt.utf8.idx, &ps);
+
+ if ((ssize_t)count < 0)
wc = 0;
/* Reset VT utf8 state */