From 75b8fc52b85c945e71a6fb6f2e616ee242b07b43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Thu, 23 Jan 2020 17:39:25 +0100 Subject: [PATCH] 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. --- vt.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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 */