From f2dd3897bbc907a21174c64ee90c534c1753ea5c Mon Sep 17 00:00:00 2001 From: Ali Gholami Rudi Date: Tue, 7 Feb 2012 19:29:58 +0330 Subject: [PATCH] term: handle bad utf8 chars in writeutf8() Otherwise bad utf8 chars would cause segfault, since l < 0. --- term.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/term.c b/term.c index 08355d6..58f3a16 100644 --- a/term.c +++ b/term.c @@ -379,10 +379,6 @@ static int writeutf8(char *dst, int c) { char *d = dst; int l; - if (!(c & ~0x7f)) { - *d++ = c ? c : ' '; - return 1; - } if (c > 0xffff) { *d++ = 0xf0 | (c >> 18); l = 3; @@ -392,6 +388,9 @@ static int writeutf8(char *dst, int c) } else if (c > 0x7f) { *d++ = 0xc0 | (c >> 6); l = 1; + } else { + *d++ = c > 0 ? c : ' '; + l = 0; } while (l--) *d++ = 0x80 | ((c >> (l * 6)) & 0x3f); -- 2.11.4.GIT