Merge branch '3783_mcview_invalid_utf8'

* 3783_mcview_invalid_utf8:
  Ticket #3783: mcview: fix interpretation of invalid utf-8 symbols.
This commit is contained in:
Andrew Borodin 2017-05-17 11:28:53 +03:00
commit ed0ed4ac72
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