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.
This commit is contained in:
Daniel Eklöf 2020-01-23 17:39:25 +01:00
parent 51f8453f9d
commit 75b8fc52b8
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F

5
vt.c
View file

@ -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 */