Ticket #3783: mcview: fix interpretation of invalid utf-8 symbols.

(mcview_get_utf): report invalid utf-8 as negative integer.

The bug was introduced in 4d65a731c28d53a536a044a85e82223a7aa46bd5.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Egmont Koblinger 2017-05-07 20:50:27 +03:00 committed by Andrew Borodin
parent cea0973393
commit 5e238fae95
2 changed files with 6 additions and 1 deletions

View File

@ -341,6 +341,8 @@ mcview_char_display (const WView * view, int c, char *s)
* Normally: stores c, updates state, returns TRUE.
* At EOF: state is unchanged, c is undefined, returns FALSE.
*
* Just as with mcview_get_utf(), invalid UTF-8 is reported using negative integers.
*
* Also, temporary hack: handle force_max here.
* TODO: move it to lower layers (datasource.c)?
*/

View File

@ -147,6 +147,8 @@ mcview_get_ptr_file (WView * view, off_t byte_index)
/* --------------------------------------------------------------------------------------------- */
/* Invalid UTF-8 is reported as negative integers (one for each byte),
* see ticket 3783. */
gboolean
mcview_get_utf (WView * view, off_t byte_index, int *ch, int *ch_len)
{
@ -200,7 +202,8 @@ mcview_get_utf (WView * view, off_t byte_index, int *ch, int *ch_len)
if (res < 0)
{
*ch = (unsigned char) (*str);
/* Implicit conversion from signed char to signed int keeps negative values. */
*ch = *str;
*ch_len = 1;
}
else