Ticket #3473: mc-3473-cleanup-format_nonliteral-warning.patch
File mc-3473-cleanup-format_nonliteral-warning.patch, 13.5 KB (added by and, 9 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 34 34 35 35 /*** global variables defined in .c file *********************************************************/ 36 36 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" 41 41 42 42 /*** declarations of public functions ************************************************************/ 43 43 -
lib/search/lib.c
diff -ruN a/lib/search/lib.c b/lib/search/lib.c
a b 41 41 42 42 /*** global variables ****************************************************************************/ 43 43 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 50 44 /*** file scope macro definitions ****************************************************************/ 51 45 52 46 /*** file scope type declarations ****************************************************************/ -
lib/tty/tty.h
a b 120 120 extern void tty_print_alt_char (int c, gboolean single); 121 121 extern void tty_print_anychar (int c); 122 122 extern void tty_print_string (const char *s); 123 extern void tty_printf (const char *s, ...) ;123 extern void tty_printf (const char *s, ...) __attribute__((format(printf, 1, 2))); 124 124 125 125 extern void tty_print_one_vline (gboolean single); 126 126 extern void tty_print_one_hline (gboolean single); -
lib/vfs/direntry.c
a b 696 696 vfs_s_print_stats (const char *fs_name, const char *action, 697 697 const char *file_name, off_t have, off_t need) 698 698 { 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 708 699 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, 710 701 file_name, (int) ((double) have * 100 / need), (uintmax_t) have, 711 702 _("bytes transferred")); 712 703 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, 714 705 _("bytes transferred")); 715 706 } 716 707 -
lib/vfs/interface.c
a b 817 817 const char *sys_tmp; 818 818 struct passwd *pwd; 819 819 struct stat st; 820 const char *error = NULL;820 gboolean found_error = FALSE; 821 821 822 822 /* Check if already correctly initialized */ 823 823 if (tmpdir && lstat (tmpdir, &st) == 0 && S_ISDIR (st.st_mode) && … … 844 844 { 845 845 /* Sanity check for existing directory */ 846 846 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 } 848 851 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 } 850 856 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 } 852 861 } 853 862 else 854 863 { 855 864 fprintf (stderr, 856 865 _("Cannot create temporary directory %s: %s\n"), 857 866 buffer, unix_error_string (errno)); 858 error = "";867 found_error = TRUE; 859 868 } 860 869 } 861 870 862 if ( error != NULL)871 if (found_error) 863 872 { 864 873 int test_fd; 865 874 char *fallback_prefix; 866 875 gboolean fallback_ok = FALSE; 867 876 vfs_path_t *test_vpath; 868 877 869 if (*error)870 fprintf (stderr, error, buffer);871 872 878 /* Test if sys_tmp is suitable for temporary files */ 873 879 fallback_prefix = g_strdup_printf ("%s/mctest", sys_tmp); 874 880 test_fd = mc_mkstemps (&test_vpath, fallback_prefix, NULL); … … 889 895 { 890 896 fprintf (stderr, _("Temporary files will be created in %s\n"), sys_tmp); 891 897 g_snprintf (buffer, sizeof (buffer), "%s", sys_tmp); 892 error = NULL;898 found_error = FALSE; 893 899 } 894 900 else 895 901 { … … 904 910 905 911 tmpdir = buffer; 906 912 907 if (! error)913 if (!found_error) 908 914 g_setenv ("MC_TMPDIR", tmpdir, TRUE); 909 915 910 916 return tmpdir; -
lib/strutil.h
a b 217 217 218 218 /* printf function for str_buffer, append result of printf at the end of buffer 219 219 */ 220 void str_printf (GString *, const char *, ...) ;220 void str_printf (GString *, const char *, ...) __attribute__((format(printf, 2, 3))); 221 221 222 222 /* add standard replacement character in terminal encoding 223 223 */ -
lib/widget/gauge.c
a b 115 115 tty_setcolor (GAUGE_COLOR); 116 116 tty_printf ("%*s", columns, ""); 117 117 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); 119 119 } 120 120 } 121 121 return MSG_HANDLED; -
lib/widget/label.h
a b 28 28 29 29 WLabel *label_new (int y, int x, const char *text); 30 30 void label_set_text (WLabel * label, const char *text); 31 void label_set_textv (WLabel * label, const char *format, ...) ;31 void label_set_textv (WLabel * label, const char *format, ...) __attribute__((format(printf, 2, 3))); 32 32 33 33 /*** inline functions ****************************************************************************/ 34 34 -
lib/util.h
a b 246 246 char *mc_build_filename (const char *first_element, ...); 247 247 char *mc_build_filenamev (const char *first_element, va_list args); 248 248 249 void mc_propagate_error (GError ** dest, int code, const char *format, ...) ;250 void mc_replace_error (GError ** dest, int code, const char *format, ...) ;249 void mc_propagate_error (GError ** dest, int code, const char *format, ...) __attribute__((format(printf, 3, 4))); 250 void mc_replace_error (GError ** dest, int code, const char *format, ...) __attribute__((format(printf, 3, 4))); 251 251 252 252 gboolean mc_time_elapsed (guint64 * timestamp, guint64 delay); 253 253 -
lib/serialize.c
a b 50 50 51 51 /*** file scope functions ************************************************************************/ 52 52 /* --------------------------------------------------------------------------------------------- */ 53 53 __attribute__((format(printf, 2, 3))) 54 54 static void 55 55 prepend_error_message (GError ** error, const char *format, ...) 56 56 { -
src/filemanager/hotlist.c
a b 1558 1558 add2hotlist_cmd (void) 1559 1559 { 1560 1560 char *lc_prompt; 1561 const char *cp = N_("Label for \"%s\":");1562 1561 int l; 1563 1562 char *label_string, *label; 1564 1563 1565 #ifdef ENABLE_NLS 1566 cp = _(cp); 1567 #endif 1568 1569 l = str_term_width1 (cp); 1564 l = str_term_width1 (_("Label for \"%s\":")); 1570 1565 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))); 1572 1567 label = 1573 1568 input_dialog (_("Add to hotlist"), lc_prompt, MC_HISTORY_HOTLIST_ADD, label_string, 1574 1569 INPUT_COMPLETE_NONE); -
src/filemanager/info.c
a b 105 105 { 106 106 Widget *w = WIDGET (info); 107 107 static int i18n_adjust = 0; 108 static const char *file_label;109 108 GString *buff; 110 109 struct stat st; 111 110 … … 133 132 if (i18n_adjust == 0) 134 133 { 135 134 /* 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; 138 136 } 139 137 140 138 tty_setcolor (NORMAL_COLOR); … … 252 250 253 251 widget_move (w, 3, 2); 254 252 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)); 256 254 tty_print_string (buff->str); 257 255 } 258 256 -
src/consaver/cons.saver.c
a b 163 163 struct stat st; 164 164 uid_t uid, euid; 165 165 char *buffer, *tty_name, console_name[16], vcsa_name[16]; 166 const char *p, *q;167 166 struct winsize winsz; 168 167 169 168 close (STDERR_FILENO); … … 198 197 { 199 198 /* devfs */ 200 199 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); 203 202 break; 204 203 /* /dev/ttyN */ 205 204 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); 208 207 break; 209 208 default: 210 209 die (); 211 210 } 212 211 213 snprintf (console_name, sizeof (console_name), p, console_minor);214 212 if (strncmp (console_name, tty_name, sizeof (console_name)) != 0) 215 213 die (); 216 214 217 215 if (seteuid (euid) < 0) 218 216 die (); 219 217 220 snprintf (vcsa_name, sizeof (vcsa_name), q, console_minor);221 218 vcsa_fd = open (vcsa_name, O_RDWR); 222 219 if (vcsa_fd < 0) 223 220 die (); -
src/vfs/fish/fish.c
a b 235 235 236 236 /* --------------------------------------------------------------------------------------------- */ 237 237 238 __attribute__((format(printf, 4, 5))) 238 239 static int 239 240 fish_command (struct vfs_class *me, struct vfs_s_super *super, int wait_reply, const char *fmt, ...) 240 241 { … … 383 384 static gboolean 384 385 fish_info (struct vfs_class *me, struct vfs_s_super *super) 385 386 { 386 if (fish_command (me, super, NONE, SUP->scr_info) == COMPLETE)387 if (fish_command (me, super, NONE, "%s", SUP->scr_info) == COMPLETE) 387 388 { 388 389 while (TRUE) 389 390 { -
src/filemanager/file.c
a b 702 702 { 703 703 if (ctx->recursive_result < RECURSIVE_ALWAYS) 704 704 { 705 const char *msg;706 705 char *text; 707 706 708 msg = mode == Foreground709 ? _("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)); 712 711 713 712 if (safe_delete) 714 713 query_set_sel (1);