Ticket #230: mc-name_trunc.rev2.patch

File mc-name_trunc.rev2.patch, 776 bytes (added by andrew_b, 15 years ago)

fixed

  • src/util.c

    diff --git a/src/util.c b/src/util.c
    index 35658b0..4c446b4 100644
    a b name_trunc (const char *txt, int trunc_len) 
    236236    int txt_len; 
    237237    char *p; 
    238238 
     239    if (!txt) 
     240        return NULL; 
     241    if (!*txt) 
     242        return txt; 
     243 
    239244    if ((size_t) trunc_len > sizeof (x) - 1) { 
    240245        trunc_len = sizeof (x) - 1; 
    241246    } 
    242     txt_len = strlen (txt); 
     247    txt_len = (int) strlen (txt); 
    243248    if (txt_len <= trunc_len) { 
    244249        strcpy (x, txt); 
    245250    } else { 
    246251        int y = (trunc_len / 2) + (trunc_len % 2); 
    247         strncpy (x, txt, y); 
    248         strncpy (x + y, txt + txt_len - (trunc_len / 2), trunc_len / 2); 
     252        strncpy (x, txt, (size_t) y); 
     253        strncpy (x + y, txt + (size_t) (txt_len - (trunc_len / 2)), (size_t) trunc_len / 2); 
    249254        x[y] = '~'; 
    250255    } 
    251256    x[trunc_len] = 0;