mirror of
https://github.com/MidnightCommander/mc
synced 2025-01-03 01:54:24 +03:00
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:
parent
5cc8114d33
commit
b4fb7b0c74
@ -163,6 +163,7 @@ mcview_get_utf (mcview_t * view, off_t byte_index, int *char_width, gboolean * r
|
||||
int res = -1;
|
||||
gunichar ch;
|
||||
gchar *next_ch = NULL;
|
||||
gchar utf8buf[UTF8_CHAR_LEN + 1];
|
||||
|
||||
*char_width = 0;
|
||||
*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);
|
||||
|
||||
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)
|
||||
{
|
||||
ch = *str;
|
||||
|
Loading…
Reference in New Issue
Block a user