Ticket #3473: mc-3473-cleanup-format_nonliteral-warning.patch

File mc-3473-cleanup-format_nonliteral-warning.patch, 13.5 KB (added by and, 5 years ago)
  • lib/search/internal.h

    fix most -Wformat-nonliteral warnings
    
    https://fedoraproject.org/wiki/Format-Security-FAQ
    
    not all warnings are fixable(?) and I don't want insert #pragma GCC diagnostic warning
    
    please cross check real catch at lib/widget/gauge.c
    
    Signed-off-by: Andreas Mohr <and@gmx.li>
    
    regex.c:1011:56: error: format string is not a string literal [-Wformat-nonliteral]
    tty-ncurses.c:641:37: error: format string is not a string literal [-Wformat-nonliteral]
    direntry.c:709:28: error: format string is not a string literal [-Wformat-nonliteral]
    direntry.c:713:28: error: format string is not a string literal [-Wformat-nonliteral]
    interface.c:870:30: error: format string is not a string literal [-Wformat-nonliteral]
    strutil.c:267:38: error: format string is not a string literal [-Wformat-nonliteral]
    gauge.c:118:67: error: data argument not used by format string [-Wformat-extra-args]
    label.c:200:37: error: format string is not a string literal [-Wformat-nonliteral]
    util.c:1453:57: error: format string is not a string literal [-Wformat-nonliteral]
    util.c:1427:57: error: format string is not a string literal [-Wformat-nonliteral]
    serialize.c:65:37: error: format string is not a string literal [-Wformat-nonliteral]
    hotlist.c:1571:34: error: format string is not a string literal [-Wformat-nonliteral]
    info.c:255:31: error: format string is not a string literal [-Werror,-Wformat-nonliteral]
    cons.saver.c:213:52: warning: format string is not a string literal [-Wformat-nonliteral]
    cons.saver.c:220:46: warning: format string is not a string literal [-Wformat-nonliteral]
    fish.c:248:29: warning: format string is not a string literal [-Wformat-nonliteral]
    fish.c:387:40: error: format string is not a string literal (potentially insecure) [-Wformat-security]
    file.c:711:33: warning: format string is not a string literal [-Wformat-nonliteral]
    
    a b  
    3434 
    3535/*** global variables defined in .c file *********************************************************/ 
    3636 
    37 extern const char *STR_E_NOTFOUND; 
    38 extern const char *STR_E_UNKNOWN_TYPE; 
    39 extern const char *STR_E_RPL_NOT_EQ_TO_FOUND; 
    40 extern const char *STR_E_RPL_INVALID_TOKEN; 
     37#define STR_E_NOTFOUND "Search string not found" 
     38#define STR_E_UNKNOWN_TYPE "Not implemented yet" 
     39#define STR_E_RPL_NOT_EQ_TO_FOUND "Num of replace tokens not equal to num of found tokens" 
     40#define STR_E_RPL_INVALID_TOKEN "Invalid token number %d" 
    4141 
    4242/*** declarations of public functions ************************************************************/ 
    4343 
  • lib/search/lib.c

    diff -ruN a/lib/search/lib.c b/lib/search/lib.c
    a b  
    4141 
    4242/*** global variables ****************************************************************************/ 
    4343 
    44 const char *STR_E_NOTFOUND = N_("Search string not found"); 
    45 const char *STR_E_UNKNOWN_TYPE = N_("Not implemented yet"); 
    46 const char *STR_E_RPL_NOT_EQ_TO_FOUND = 
    47 N_("Num of replace tokens not equal to num of found tokens"); 
    48 const char *STR_E_RPL_INVALID_TOKEN = N_("Invalid token number %d"); 
    49  
    5044/*** file scope macro definitions ****************************************************************/ 
    5145 
    5246/*** file scope type declarations ****************************************************************/ 
  • lib/tty/tty.h

    a b  
    120120extern void tty_print_alt_char (int c, gboolean single); 
    121121extern void tty_print_anychar (int c); 
    122122extern void tty_print_string (const char *s); 
    123 extern void tty_printf (const char *s, ...); 
     123extern void tty_printf (const char *s, ...) __attribute__((format(printf, 1, 2))); 
    124124 
    125125extern void tty_print_one_vline (gboolean single); 
    126126extern void tty_print_one_hline (gboolean single); 
  • lib/vfs/direntry.c

    a b  
    696696vfs_s_print_stats (const char *fs_name, const char *action, 
    697697                   const char *file_name, off_t have, off_t need) 
    698698{ 
    699     static const char *i18n_percent_transf_format = NULL; 
    700     static const char *i18n_transf_format = NULL; 
    701  
    702     if (i18n_percent_transf_format == NULL) 
    703     { 
    704         i18n_percent_transf_format = "%s: %s: %s %3d%% (%" PRIuMAX " %s"; 
    705         i18n_transf_format = "%s: %s: %s %" PRIuMAX " %s"; 
    706     } 
    707  
    708699    if (need) 
    709         vfs_print_message (i18n_percent_transf_format, fs_name, action, 
     700        vfs_print_message ("%s: %s: %s %3d%% (%" PRIuMAX " %s", fs_name, action, 
    710701                           file_name, (int) ((double) have * 100 / need), (uintmax_t) have, 
    711702                           _("bytes transferred")); 
    712703    else 
    713         vfs_print_message (i18n_transf_format, fs_name, action, file_name, (uintmax_t) have, 
     704        vfs_print_message ("%s: %s: %s %" PRIuMAX " %s", fs_name, action, file_name, (uintmax_t) have, 
    714705                           _("bytes transferred")); 
    715706} 
    716707 
  • lib/vfs/interface.c

    a b  
    817817    const char *sys_tmp; 
    818818    struct passwd *pwd; 
    819819    struct stat st; 
    820     const char *error = NULL; 
     820    gboolean found_error = FALSE; 
    821821 
    822822    /* Check if already correctly initialized */ 
    823823    if (tmpdir && lstat (tmpdir, &st) == 0 && S_ISDIR (st.st_mode) && 
     
    844844        { 
    845845            /* Sanity check for existing directory */ 
    846846            if (!S_ISDIR (st.st_mode)) 
    847                 error = _("%s is not a directory\n"); 
     847            { 
     848                fprintf (stderr, _("%s is not a directory\n"), buffer); 
     849                found_error = TRUE; 
     850            } 
    848851            else if (st.st_uid != getuid ()) 
    849                 error = _("Directory %s is not owned by you\n"); 
     852            { 
     853                fprintf (stderr, _("Directory %s is not owned by you\n"), buffer); 
     854                found_error = TRUE; 
     855            } 
    850856            else if (((st.st_mode & 0777) != 0700) && (chmod (buffer, 0700) != 0)) 
    851                 error = _("Cannot set correct permissions for directory %s\n"); 
     857            { 
     858                fprintf (stderr, _("Cannot set correct permissions for directory %s\n"), buffer); 
     859                found_error = TRUE; 
     860            } 
    852861        } 
    853862        else 
    854863        { 
    855864            fprintf (stderr, 
    856865                     _("Cannot create temporary directory %s: %s\n"), 
    857866                     buffer, unix_error_string (errno)); 
    858             error = ""; 
     867            found_error = TRUE; 
    859868        } 
    860869    } 
    861870 
    862     if (error != NULL) 
     871    if (found_error) 
    863872    { 
    864873        int test_fd; 
    865874        char *fallback_prefix; 
    866875        gboolean fallback_ok = FALSE; 
    867876        vfs_path_t *test_vpath; 
    868877 
    869         if (*error) 
    870             fprintf (stderr, error, buffer); 
    871  
    872878        /* Test if sys_tmp is suitable for temporary files */ 
    873879        fallback_prefix = g_strdup_printf ("%s/mctest", sys_tmp); 
    874880        test_fd = mc_mkstemps (&test_vpath, fallback_prefix, NULL); 
     
    889895        { 
    890896            fprintf (stderr, _("Temporary files will be created in %s\n"), sys_tmp); 
    891897            g_snprintf (buffer, sizeof (buffer), "%s", sys_tmp); 
    892             error = NULL; 
     898            found_error = FALSE; 
    893899        } 
    894900        else 
    895901        { 
     
    904910 
    905911    tmpdir = buffer; 
    906912 
    907     if (!error) 
     913    if (!found_error) 
    908914        g_setenv ("MC_TMPDIR", tmpdir, TRUE); 
    909915 
    910916    return tmpdir; 
  • lib/strutil.h

    a b  
    217217 
    218218/* printf function for str_buffer, append result of printf at the end of buffer 
    219219 */ 
    220 void str_printf (GString *, const char *, ...); 
     220void str_printf (GString *, const char *, ...) __attribute__((format(printf, 2, 3))); 
    221221 
    222222/* add standard replacement character in terminal encoding 
    223223 */ 
  • lib/widget/gauge.c

    a b  
    115115                tty_setcolor (GAUGE_COLOR); 
    116116                tty_printf ("%*s", columns, ""); 
    117117                tty_setcolor (h->color[DLG_COLOR_NORMAL]); 
    118                 tty_printf ("] %3d%%", 100 * columns / gauge_len, percentage); 
     118                tty_printf ("%*s] %3d%%", 100 * columns / gauge_len, "", percentage); 
    119119            } 
    120120        } 
    121121        return MSG_HANDLED; 
  • lib/widget/label.h

    a b  
    2828 
    2929WLabel *label_new (int y, int x, const char *text); 
    3030void label_set_text (WLabel * label, const char *text); 
    31 void label_set_textv (WLabel * label, const char *format, ...); 
     31void label_set_textv (WLabel * label, const char *format, ...) __attribute__((format(printf, 2, 3))); 
    3232 
    3333/*** inline functions ****************************************************************************/ 
    3434 
  • lib/util.h

    a b  
    246246char *mc_build_filename (const char *first_element, ...); 
    247247char *mc_build_filenamev (const char *first_element, va_list args); 
    248248 
    249 void mc_propagate_error (GError ** dest, int code, const char *format, ...); 
    250 void mc_replace_error (GError ** dest, int code, const char *format, ...); 
     249void mc_propagate_error (GError ** dest, int code, const char *format, ...) __attribute__((format(printf, 3, 4))); 
     250void mc_replace_error (GError ** dest, int code, const char *format, ...) __attribute__((format(printf, 3, 4))); 
    251251 
    252252gboolean mc_time_elapsed (guint64 * timestamp, guint64 delay); 
    253253 
  • lib/serialize.c

    a b  
    5050 
    5151/*** file scope functions ************************************************************************/ 
    5252/* --------------------------------------------------------------------------------------------- */ 
    53  
     53__attribute__((format(printf, 2, 3))) 
    5454static void 
    5555prepend_error_message (GError ** error, const char *format, ...) 
    5656{ 
  • src/filemanager/hotlist.c

    a b  
    15581558add2hotlist_cmd (void) 
    15591559{ 
    15601560    char *lc_prompt; 
    1561     const char *cp = N_("Label for \"%s\":"); 
    15621561    int l; 
    15631562    char *label_string, *label; 
    15641563 
    1565 #ifdef ENABLE_NLS 
    1566     cp = _(cp); 
    1567 #endif 
    1568  
    1569     l = str_term_width1 (cp); 
     1564    l = str_term_width1 (_("Label for \"%s\":")); 
    15701565    label_string = vfs_path_to_str_flags (current_panel->cwd_vpath, 0, VPF_STRIP_PASSWORD); 
    1571     lc_prompt = g_strdup_printf (cp, str_trunc (label_string, COLS - 2 * UX - (l + 8))); 
     1566    lc_prompt = g_strdup_printf (_("Label for \"%s\":"), str_trunc (label_string, COLS - 2 * UX - (l + 8))); 
    15721567    label = 
    15731568        input_dialog (_("Add to hotlist"), lc_prompt, MC_HISTORY_HOTLIST_ADD, label_string, 
    15741569                      INPUT_COMPLETE_NONE); 
  • src/filemanager/info.c

    a b  
    105105{ 
    106106    Widget *w = WIDGET (info); 
    107107    static int i18n_adjust = 0; 
    108     static const char *file_label; 
    109108    GString *buff; 
    110109    struct stat st; 
    111110 
     
    133132    if (i18n_adjust == 0) 
    134133    { 
    135134        /* This printf pattern string is used as a reference for size */ 
    136         file_label = _("File: %s"); 
    137         i18n_adjust = str_term_width1 (file_label) + 2; 
     135        i18n_adjust = str_term_width1 (_("File: %s")) + 2; 
    138136    } 
    139137 
    140138    tty_setcolor (NORMAL_COLOR); 
     
    252250 
    253251            widget_move (w, 3, 2); 
    254252            fname = current_panel->dir.list[current_panel->selected].fname; 
    255             str_printf (buff, file_label, str_trunc (fname, w->cols - i18n_adjust)); 
     253            str_printf (buff, _("File: %s"), str_trunc (fname, w->cols - i18n_adjust)); 
    256254            tty_print_string (buff->str); 
    257255        } 
    258256 
  • src/consaver/cons.saver.c

    a b  
    163163    struct stat st; 
    164164    uid_t uid, euid; 
    165165    char *buffer, *tty_name, console_name[16], vcsa_name[16]; 
    166     const char *p, *q; 
    167166    struct winsize winsz; 
    168167 
    169168    close (STDERR_FILENO); 
     
    198197    { 
    199198        /* devfs */ 
    200199    case 'v': 
    201         p = "/dev/vc/%d"; 
    202         q = "/dev/vcc/a%d"; 
     200        snprintf (console_name, sizeof (console_name), "/dev/vc/%d", console_minor); 
     201        snprintf (vcsa_name, sizeof (vcsa_name), "/dev/vcc/a%d", console_minor); 
    203202        break; 
    204203        /* /dev/ttyN */ 
    205204    case 't': 
    206         p = "/dev/tty%d"; 
    207         q = "/dev/vcsa%d"; 
     205        snprintf (console_name, sizeof (console_name), "/dev/tty%d", console_minor); 
     206        snprintf (vcsa_name, sizeof (vcsa_name), "/dev/vcsa%d", console_minor); 
    208207        break; 
    209208    default: 
    210209        die (); 
    211210    } 
    212211 
    213     snprintf (console_name, sizeof (console_name), p, console_minor); 
    214212    if (strncmp (console_name, tty_name, sizeof (console_name)) != 0) 
    215213        die (); 
    216214 
    217215    if (seteuid (euid) < 0) 
    218216        die (); 
    219217 
    220     snprintf (vcsa_name, sizeof (vcsa_name), q, console_minor); 
    221218    vcsa_fd = open (vcsa_name, O_RDWR); 
    222219    if (vcsa_fd < 0) 
    223220        die (); 
  • src/vfs/fish/fish.c

    a b  
    235235 
    236236/* --------------------------------------------------------------------------------------------- */ 
    237237 
     238__attribute__((format(printf, 4, 5))) 
    238239static int 
    239240fish_command (struct vfs_class *me, struct vfs_s_super *super, int wait_reply, const char *fmt, ...) 
    240241{ 
     
    383384static gboolean 
    384385fish_info (struct vfs_class *me, struct vfs_s_super *super) 
    385386{ 
    386     if (fish_command (me, super, NONE, SUP->scr_info) == COMPLETE) 
     387    if (fish_command (me, super, NONE, "%s", SUP->scr_info) == COMPLETE) 
    387388    { 
    388389        while (TRUE) 
    389390        { 
  • src/filemanager/file.c

    a b  
    702702{ 
    703703    if (ctx->recursive_result < RECURSIVE_ALWAYS) 
    704704    { 
    705         const char *msg; 
    706705        char *text; 
    707706 
    708         msg = mode == Foreground 
    709             ? _("Directory \"%s\" not empty.\nDelete it recursively?") 
    710             : _("Background process:\nDirectory \"%s\" not empty.\nDelete it recursively?"); 
    711         text = g_strdup_printf (msg, path_trunc (s, 30)); 
     707        if (mode == Foreground) 
     708            text = g_strdup_printf (_("Directory \"%s\" not empty.\nDelete it recursively?"), path_trunc (s, 30)); 
     709        else 
     710            text = g_strdup_printf (_("Background process:\nDirectory \"%s\" not empty.\nDelete it recursively?"), path_trunc (s, 30)); 
    712711 
    713712        if (safe_delete) 
    714713            query_set_sel (1);