Ticket #3547: mc-3547-cleanup-conversion-warning-strutils_escape.patch

File mc-3547-cleanup-conversion-warning-strutils_escape.patch, 6.8 KB (added by and, 7 years ago)
  • lib/strescape.h

    fix -Wconversion warning at strutils_escape/strutils_unescape()
    
    remove src_len parameter support, never used in mc
    
    patch will fix following warnings:
    strescape.c:180:34: warning: implicit conversion changes signedness: 'int' to 'gsize' (aka 'unsigned long') [-Wsign-conversion]
    strescape.c:188:34: warning: implicit conversion changes signedness: 'int' to 'gsize' (aka 'unsigned long') [-Wsign-conversion]
    strescape.c:196:34: warning: implicit conversion changes signedness: 'int' to 'gsize' (aka 'unsigned long') [-Wsign-conversion]
    strescape.c:213:37: warning: implicit conversion changes signedness: 'int' to 'gsize' (aka 'unsigned long') [-Wsign-conversion]
    strescape.c:221:37: warning: implicit conversion changes signedness: 'int' to 'gsize' (aka 'unsigned long') [-Wsign-conversion]
    strescape.c:228:37: warning: implicit conversion changes signedness: 'int' to 'gsize' (aka 'unsigned long') [-Wsign-conversion]
    panel.c:2646:41: warning: implicit conversion changes signedness: 'int' to 'gsize' (aka 'unsigned long') [-Wsign-conversion]
    treestore.c:330:63: warning: implicit conversion changes signedness: 'int' to 'gsize' (aka 'unsigned long') [-Wsign-conversion]
    learn.c:363:63: warning: implicit conversion changes signedness: 'int' to 'gsize' (aka 'unsigned long') [-Wsign-conversion]
    
    patch against a5cd0093c5330ae6118cbf2830cf288dd4a68ed0
    compile test with gcc 4.6/4.9/5.2 and clang 3.7
    
    Signed-off-by: Andreas Mohr <and@gmx.li>
    
    a e  
    1515 
    1616/*** declarations of public functions ************************************************************/ 
    1717 
    18 char *strutils_escape (const char *, gsize, const char *, gboolean); 
    19 char *strutils_unescape (const char *, gsize, const char *, gboolean); 
     18char *strutils_escape (const char *, const char *, gboolean); 
     19char *strutils_unescape (const char *, const char *, gboolean); 
    2020 
    2121char *strutils_shell_unescape (const char *); 
    2222char *strutils_shell_escape (const char *); 
  • lib/strutil/strescape.c

    a e  
    4646/*** public functions ****************************************************************************/ 
    4747 
    4848char * 
    49 strutils_escape (const char *src, gsize src_len, const char *escaped_chars, 
     49strutils_escape (const char *src, const char *escaped_chars, 
    5050                 gboolean escape_non_printable) 
    5151{ 
    5252    GString *ret; 
    53     gsize curr_index; 
     53    gsize curr_index, src_len; 
    5454    /* do NOT break allocation semantics */ 
    5555    if (src == NULL) 
    5656        return NULL; 
     
    6060 
    6161    ret = g_string_new (""); 
    6262 
    63     if (src_len == (gsize) (-1)) 
    64         src_len = strlen (src); 
     63    src_len = strlen (src); 
    6564 
    6665    for (curr_index = 0; curr_index < src_len; curr_index++) 
    6766    { 
     
    9695 
    9796/* --------------------------------------------------------------------------------------------- */ 
    9897char * 
    99 strutils_unescape (const char *src, gsize src_len, const char *unescaped_chars, 
     98strutils_unescape (const char *src, const char *unescaped_chars, 
    10099                   gboolean unescape_non_printable) 
    101100{ 
    102101    GString *ret; 
    103     gsize curr_index; 
     102    gsize curr_index, src_len; 
    104103 
    105104    if (src == NULL) 
    106105        return NULL; 
     
    110109 
    111110    ret = g_string_sized_new (16); 
    112111 
    113     if (src_len == (gsize) (-1)) 
    114         src_len = strlen (src); 
     112    src_len = strlen (src); 
    115113    src_len--; 
    116114 
    117115    for (curr_index = 0; curr_index < src_len; curr_index++) 
     
    177175char * 
    178176strutils_shell_escape (const char *src) 
    179177{ 
    180     return strutils_escape (src, -1, ESCAPE_SHELL_CHARS, FALSE); 
     178    return strutils_escape (src, ESCAPE_SHELL_CHARS, FALSE); 
    181179} 
    182180 
    183181/* --------------------------------------------------------------------------------------------- */ 
     
    185183char * 
    186184strutils_glob_escape (const char *src) 
    187185{ 
    188     return strutils_escape (src, -1, ESCAPE_GLOB_CHARS, TRUE); 
     186    return strutils_escape (src, ESCAPE_GLOB_CHARS, TRUE); 
    189187} 
    190188 
    191189/* --------------------------------------------------------------------------------------------- */ 
     
    193191char * 
    194192strutils_regex_escape (const char *src) 
    195193{ 
    196     return strutils_escape (src, -1, ESCAPE_REGEX_CHARS, TRUE); 
     194    return strutils_escape (src, ESCAPE_REGEX_CHARS, TRUE); 
    197195} 
    198196 
    199197/* --------------------------------------------------------------------------------------------- */ 
     
    210208char * 
    211209strutils_shell_unescape (const char *text) 
    212210{ 
    213     return strutils_unescape (text, -1, ESCAPE_SHELL_CHARS, TRUE); 
     211    return strutils_unescape (text, ESCAPE_SHELL_CHARS, TRUE); 
    214212} 
    215213 
    216214/* --------------------------------------------------------------------------------------------- */ 
     
    218216char * 
    219217strutils_glob_unescape (const char *text) 
    220218{ 
    221     return strutils_unescape (text, -1, ESCAPE_GLOB_CHARS, TRUE); 
     219    return strutils_unescape (text, ESCAPE_GLOB_CHARS, TRUE); 
    222220} 
    223221 
    224222/* --------------------------------------------------------------------------------------------- */ 
    225223char * 
    226224strutils_regex_unescape (const char *text) 
    227225{ 
    228     return strutils_unescape (text, -1, ESCAPE_REGEX_CHARS, TRUE); 
     226    return strutils_unescape (text, ESCAPE_REGEX_CHARS, TRUE); 
    229227} 
    230228 
    231229/* --------------------------------------------------------------------------------------------- */ 
  • src/filemanager/panel.c

    a e  
    26432643    } 
    26442644 
    26452645    reg_exp = g_strdup_printf ("%s*", panel->search_buffer); 
    2646     esc_str = strutils_escape (reg_exp, -1, ",|\\{}[]", TRUE); 
     2646    esc_str = strutils_escape (reg_exp, ",|\\{}[]", TRUE); 
    26472647    search = mc_search_new (esc_str, -1, NULL); 
    26482648    search->search_type = MC_SEARCH_T_GLOB; 
    26492649    search->is_entire_line = TRUE; 
  • src/filemanager/treestore.c

    a e  
    327327static char * 
    328328encode (const vfs_path_t * vpath, size_t offset) 
    329329{ 
    330     return strutils_escape (vfs_path_as_str (vpath) + offset, -1, "\n\\", FALSE); 
     330    return strutils_escape (vfs_path_as_str (vpath) + offset, "\n\\", FALSE); 
    331331} 
    332332 
    333333/* --------------------------------------------------------------------------------------------- */ 
  • src/learn.c

    a e  
    360360        { 
    361361            char *esc_str; 
    362362 
    363             esc_str = strutils_escape (learnkeys[i].sequence, -1, ";\\", TRUE); 
     363            esc_str = strutils_escape (learnkeys[i].sequence, ";\\", TRUE); 
    364364            mc_config_set_string_raw_value (mc_main_config, section, key_name_conv_tab[i].name, 
    365365                                            esc_str); 
    366366            g_free (esc_str); 
  • tests/lib/mcconfig/config_string.c

    a e  
    215215    { 
    216216        char *esc_str; 
    217217 
    218         esc_str = strutils_escape ("T;E\\X;T-FOR-\\T;E;S\\TI;N'G", -1, ";", TRUE); 
     218        esc_str = strutils_escape ("T;E\\X;T-FOR-\\T;E;S\\TI;N'G", ";", TRUE); 
    219219        mc_config_set_string_raw (mc_config, "test-group1", "test-param1", esc_str); 
    220220        g_free (esc_str); 
    221221    }