Ticket #3259: mc-3259-hex-update.patch

File mc-3259-hex-update.patch, 2.4 KB (added by egmont, 10 years ago)

Quick fix

  • src/viewer/hex.c

    diff --git a/src/viewer/hex.c b/src/viewer/hex.c
    index e355cfb..a783217 100644
    a b mcview_display_hex (mcview_t * view) 
    192192#ifdef HAVE_CHARSET 
    193193            if (view->utf8) 
    194194            { 
    195                 int cw = 1; 
    196                 gboolean read_res = TRUE; 
    197  
    198                 ch = mcview_get_utf (view, from, &cw, &read_res); 
    199                 if (!read_res) 
    200                     break; 
    201                 /* char width is greater 0 bytes */ 
    202                 if (cw != 0) 
    203                 { 
    204                     int cnt; 
    205                     char corr_buf[UTF8_CHAR_LEN + 1]; 
    206                     struct hexedit_change_node *corr = curr; 
    207                     int res; 
    208  
    209                     res = g_unichar_to_utf8 (ch, (char *) corr_buf); 
    210  
    211                     for (cnt = 0; cnt < cw; cnt++) 
    212                     { 
    213                         if (curr != NULL && from + cnt == curr->offset) 
    214                         { 
    215                             /* replace only changed bytes in array of multibyte char */ 
    216                             corr_buf[cnt] = curr->value; 
    217                             curr = curr->next; 
    218                         } 
    219                     } 
    220                     corr_buf[res] = '\0'; 
    221                     /* Determine the state of the current multibyte char */ 
    222                     ch = utf8_to_int ((char *) corr_buf, &cw, &read_res); 
    223                     curr = corr; 
     195                int res; 
     196                int j; 
     197                struct hexedit_change_node *corr = curr; 
     198                gchar utf8buf[UTF8_CHAR_LEN + 1]; 
     199 
     200                for (j = 0; j < UTF8_CHAR_LEN; j++) { 
     201                    if (mcview_get_byte (view, from + j, &res)) 
     202                        utf8buf[j] = res; 
     203                    else 
     204                    { 
     205                        utf8buf[j] = '\0'; 
     206                        break; 
     207                    } 
     208                    if (curr != NULL && from + j == curr->offset) 
     209                        utf8buf[j] = curr->value; 
     210                    if (curr != NULL && from + j >= curr->offset) 
     211                        curr = curr->next; 
    224212                } 
     213                utf8buf[UTF8_CHAR_LEN] = '\0'; 
     214                /* Determine the state of the current multibyte char */ 
     215                ch = g_utf8_get_char_validated (utf8buf, -1); 
     216                curr = corr; 
    225217            } 
    226218#endif /* HAVE_CHARSET */ 
    227219            if (!mcview_get_byte (view, from, &c))