Ticket #1730 (troubles in mcviewer with utf8)

Fixed troubles in mcviewer with drawing utf8 chars.
    It happens in the middle of an utf8 char (on every 4096 bytes),
    leading to a valid char treated as unprintable.

Signed-off-by: Ilia Maslakov <il.smind@gmail.com>
This commit is contained in:
Sergey 2011-11-17 11:11:40 +04:00 committed by Slava Zanko
parent 5cc8114d33
commit b4fb7b0c74

View File

@ -163,6 +163,7 @@ mcview_get_utf (mcview_t * view, off_t byte_index, int *char_width, gboolean * r
int res = -1; int res = -1;
gunichar ch; gunichar ch;
gchar *next_ch = NULL; gchar *next_ch = NULL;
gchar utf8buf[UTF8_CHAR_LEN + 1];
*char_width = 0; *char_width = 0;
*result = FALSE; *result = FALSE;
@ -188,6 +189,25 @@ mcview_get_utf (mcview_t * view, off_t byte_index, int *char_width, gboolean * r
res = g_utf8_get_char_validated (str, -1); res = g_utf8_get_char_validated (str, -1);
if (res < 0)
{
/* Retry with explicit bytes to make sure it's not a buffer boundary */
int i;
for (i = 0; i < UTF8_CHAR_LEN; i++)
{
if (mcview_get_byte (view, byte_index + i, &res))
utf8buf[i] = res;
else
{
utf8buf[i] = '\0';
break;
}
}
utf8buf[UTF8_CHAR_LEN] = '\0';
str = utf8buf;
res = g_utf8_get_char_validated (str, -1);
}
if (res < 0) if (res < 0)
{ {
ch = *str; ch = *str;