term: handle bad utf8 chars in writeutf8()
authorAli Gholami Rudi <ali@rudi.ir>
Tue, 7 Feb 2012 15:59:58 +0000 (7 19:29 +0330)
committerAli Gholami Rudi <ali@rudi.ir>
Tue, 7 Feb 2012 16:09:09 +0000 (7 19:39 +0330)
Otherwise bad utf8 chars would cause segfault, since l < 0.

term.c

diff --git a/term.c b/term.c
index 08355d6..58f3a16 100644 (file)
--- 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);