Ticket #3783: mc-3783-mcview-invalid-utf8.patch

File mc-3783-mcview-invalid-utf8.patch, 1.3 KB (added by egmont, 7 years ago)
  • src/viewer/ascii.c

    diff --git a/src/viewer/ascii.c b/src/viewer/ascii.c
    index 623cd9a3b..2e23db076 100644
    a b mcview_char_display (const WView * view, int c, char *s) 
    341341 * Normally: stores c, updates state, returns TRUE. 
    342342 * At EOF: state is unchanged, c is undefined, returns FALSE. 
    343343 * 
     344 * Just as with mcview_get_utf(), invalid UTF-8 is reported using negative integers. 
     345 * 
    344346 * Also, temporary hack: handle force_max here. 
    345347 * TODO: move it to lower layers (datasource.c)? 
    346348 */ 
  • src/viewer/datasource.c

    diff --git a/src/viewer/datasource.c b/src/viewer/datasource.c
    index c90caf32e..94e6f06f0 100644
    a b mcview_get_ptr_file (WView * view, off_t byte_index) 
    147147 
    148148/* --------------------------------------------------------------------------------------------- */ 
    149149 
     150/* Invalid UTF-8 is reported as negative integers (one for each byte), 
     151 * see ticket 3783. */ 
    150152gboolean 
    151153mcview_get_utf (WView * view, off_t byte_index, int *ch, int *ch_len) 
    152154{ 
    mcview_get_utf (WView * view, off_t byte_index, int *ch, int *ch_len) 
    200202 
    201203    if (res < 0) 
    202204    { 
    203         *ch = (unsigned char) (*str); 
     205        /* Implicit conversion from signed char to signed int keeps negative values. */ 
     206        *ch = *str; 
    204207        *ch_len = 1; 
    205208    } 
    206209    else