Ticket #1730: mc-4.7.5.5-mcviewutf8fix.patch

File mc-4.7.5.5-mcviewutf8fix.patch, 936 bytes (added by sergem, 13 years ago)

fix, based on patch from #2372

  • src/viewer/datasource.c

    diff -urN mc-4.7.5.5.orig/src/viewer/datasource.c mc-4.7.5.5/src/viewer/datasource.c
    old new  
    164164    int res = -1; 
    165165    gunichar ch; 
    166166    gchar *next_ch = NULL; 
     167    gchar utf8buf[6 + 1]; 
    167168 
    168169    *char_width = 0; 
    169170    *result = FALSE; 
     
    189190 
    190191    res = g_utf8_get_char_validated (str, -1); 
    191192 
     193    if (res < 0) 
     194    { 
     195        /* Retry with explicit bytes to make sure it's not a buffer boundary */ 
     196        int i; 
     197        for (i = 0; i < 6; i++) 
     198            if (mcview_get_byte (view, byte_index + i, &res)) 
     199                utf8buf[i] = res; 
     200            else 
     201                utf8buf[i] = '\0'; 
     202        utf8buf[6] = '\0'; 
     203        str = utf8buf; 
     204        res = g_utf8_get_char_validated (str, -1); 
     205    } 
     206 
    192207    if (res < 0) 
    193208    { 
    194209        ch = *str;