Skip to content

Commit

Permalink
More robust utf8 decoding and error handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefano Stabellini committed Aug 18, 2008
1 parent b3a23e1 commit 9e987c6
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions console.c
Expand Up @@ -1613,6 +1613,7 @@ static void console_putchar(TextConsole *s, int ch)
if ((ch & 0xc0) != 0x80) {
dprintf("bogus unicode data %u\n", ch);
s->unicodeIndex = 0;
do_putchar(s, '?');
return;
}
s->unicodeData[s->unicodeIndex++] = ch;
Expand Down Expand Up @@ -1649,13 +1650,9 @@ static void console_putchar(TextConsole *s, int ch)
ch = get_glyphcode(s, ch);
do_putchar_utf(s, wc, ch);
return;
}
else {
if ((ch & 0x80) == 0) {
do_putchar(s, ch);
return;
}
else
}
/* multibyte sequence */
else if (ch > 0x7f) {
if ((ch & 0xe0) == 0xc0) {
memset(s->unicodeData, '\0', 7);
s->unicodeData[0] = ch;
Expand Down Expand Up @@ -1694,7 +1691,15 @@ static void console_putchar(TextConsole *s, int ch)
s->unicodeIndex = 1;
s->unicodeLength = 6;
return;
} else {
printf("Invalid unicode sequence start %x\n", ch);
s->unicodeIndex = 0;
do_putchar(s, '?');
return;
}
} else {
/* single ASCII char */
do_putchar(s, ch);
}
/* end of utf 8 bit */
} else {
Expand Down

0 comments on commit 9e987c6

Please sign in to comment.