changeset 25475:038eb6d9003a v8.2.3274

patch 8.2.3274: macro for printf format check can be simplified Commit: https://github.com/vim/vim/commit/952d9d827e5bfc66a6b1d39956e4e5596b09e2bd Author: Bram Moolenaar <Bram@vim.org> Date: Mon Aug 2 18:07:18 2021 +0200 patch 8.2.3274: macro for printf format check can be simplified Problem: Macro for printf format check can be simplified. Solution: Add ATTRIBUTE_FORMAT_PRINTF(). (Dominique Pell?, issue https://github.com/vim/vim/issues/8635)
author Bram Moolenaar <Bram@vim.org>
date Mon, 02 Aug 2021 18:15:06 +0200
parents c79b2530406a
children 92ccd30e625b
files src/channel.c src/gui_xim.c src/if_mzsch.c src/nbdebug.c src/nbdebug.h src/netbeans.c src/proto.h src/term.c src/version.c src/vim.h src/vim9execute.c
diffstat 11 files changed, 40 insertions(+), 69 deletions(-) [+]
line wrap: on
line diff
--- a/src/channel.c
+++ b/src/channel.c
@@ -229,11 +229,7 @@ ch_log(channel_T *ch, const char *fmt, .
 #endif
 
     static void
-ch_error(channel_T *ch, const char *fmt, ...)
-#ifdef USE_PRINTF_FORMAT_ATTRIBUTE
-    __attribute__((format(printf, 2, 3)))
-#endif
-    ;
+ch_error(channel_T *ch, const char *fmt, ...) ATTRIBUTE_FORMAT_PRINTF(2, 3);
 
     static void
 ch_error(channel_T *ch, const char *fmt, ...)
--- a/src/gui_xim.c
+++ b/src/gui_xim.c
@@ -31,7 +31,9 @@
  * in the "xim.log" file.
  */
 // #define XIM_DEBUG
-#ifdef XIM_DEBUG
+#if defined(XIM_DEBUG) && defined(FEAT_GUI_GTK)
+static void xim_log(char *s, ...) ATTRIBUTE_FORMAT_PRINTF(1, 2);
+
     static void
 xim_log(char *s, ...)
 {
--- a/src/if_mzsch.c
+++ b/src/if_mzsch.c
@@ -139,7 +139,7 @@ static char *string_to_line(Scheme_Objec
 # define OUTPUT_LEN_TYPE long
 #endif
 static void do_output(char *mesg, OUTPUT_LEN_TYPE len);
-static void do_printf(char *format, ...);
+static void do_printf(char *format, ...) ATTRIBUTE_FORMAT_PRINTF(1, 2);
 static void do_flush(void);
 static Scheme_Object *_apply_thunk_catch_exceptions(
 	Scheme_Object *, Scheme_Object **);
--- a/src/nbdebug.c
+++ b/src/nbdebug.c
@@ -32,7 +32,7 @@
 FILE		*nb_debug = NULL;
 u_int		 nb_dlevel = 0;		// nb_debug verbosity level
 
-void		 nbdb(char *, ...);
+void		 nbdb(char *, ...) ATTRIBUTE_FORMAT_PRINTF(1, 2);
 
 static int	 lookup(char *);
 #ifdef USE_NB_ERRORHANDLER
--- a/src/nbdebug.h
+++ b/src/nbdebug.h
@@ -42,11 +42,7 @@ typedef enum {
 } WtWait;
 
 
-void		 nbdbg(char *, ...)
-# ifdef USE_PRINTF_FORMAT_ATTRIBUTE
-   __attribute__((format(printf, 1, 2)))
-# endif
-;
+void		 nbdbg(char *, ...) ATTRIBUTE_FORMAT_PRINTF(1, 2);
 
 void nbdebug_wait(u_int wait_flags, char *wait_var, u_int wait_secs);
 void nbdebug_log_init(char *log_var, char *level_var);
--- a/src/netbeans.c
+++ b/src/netbeans.c
@@ -54,7 +54,7 @@ static void special_keys(char_u *args);
 static int getConnInfo(char *file, char **host, char **port, char **password);
 
 static void nb_init_graphics(void);
-static void coloncmd(char *cmd, ...);
+static void coloncmd(char *cmd, ...) ATTRIBUTE_FORMAT_PRINTF(1, 2);
 static void nb_set_curbuf(buf_T *buf);
 static void nb_parse_cmd(char_u *);
 static int  nb_do_cmd(int, char_u *, int, int, char_u *);
--- a/src/proto.h
+++ b/src/proto.h
@@ -121,52 +121,26 @@ extern int _stricoll(char *a, char *b);
 # endif
 
 // These prototypes cannot be produced automatically.
-int smsg(const char *, ...)
-# ifdef USE_PRINTF_FORMAT_ATTRIBUTE
-    __attribute__((format(printf, 1, 2)))
-# endif
-    ;
+int smsg(const char *, ...) ATTRIBUTE_COLD ATTRIBUTE_FORMAT_PRINTF(1, 2);
+
+int smsg_attr(int, const char *, ...) ATTRIBUTE_FORMAT_PRINTF(2, 3);
 
-int smsg_attr(int, const char *, ...)
-# ifdef USE_PRINTF_FORMAT_ATTRIBUTE
-    __attribute__((format(printf, 2, 3)))
-# endif
-    ;
+int smsg_attr_keep(int, const char *, ...) ATTRIBUTE_FORMAT_PRINTF(2, 3);
 
-int smsg_attr_keep(int, const char *, ...)
-# ifdef USE_PRINTF_FORMAT_ATTRIBUTE
-    __attribute__((format(printf, 2, 3)))
-# endif
-    ;
+// These prototypes cannot be produced automatically.
+int semsg(const char *, ...) ATTRIBUTE_COLD ATTRIBUTE_FORMAT_PRINTF(1, 2);
 
 // These prototypes cannot be produced automatically.
-int semsg(const char *, ...)
-# ifdef USE_PRINTF_FORMAT_ATTRIBUTE
-    __attribute__((format(printf, 1, 2)))
-# endif
-    ;
+void siemsg(const char *, ...) ATTRIBUTE_COLD ATTRIBUTE_FORMAT_PRINTF(1, 2);
 
-// These prototypes cannot be produced automatically.
-void siemsg(const char *, ...)
-# ifdef USE_PRINTF_FORMAT_ATTRIBUTE
-    __attribute__((format(printf, 1, 2)))
-# endif
-    ;
+int vim_snprintf_add(char *, size_t, const char *, ...) ATTRIBUTE_FORMAT_PRINTF(3, 4);
 
-int vim_snprintf_add(char *, size_t, const char *, ...)
-# ifdef USE_PRINTF_FORMAT_ATTRIBUTE
-    __attribute__((format(printf, 3, 4)))
-# endif
-    ;
+int vim_snprintf(char *, size_t, const char *, ...) ATTRIBUTE_FORMAT_PRINTF(3, 4);
 
-int vim_snprintf(char *, size_t, const char *, ...)
-# ifdef USE_PRINTF_FORMAT_ATTRIBUTE
-    __attribute__((format(printf, 3, 4)))
-# endif
-    ;
-
-int vim_vsnprintf(char *str, size_t str_m, const char *fmt, va_list ap);
-int vim_vsnprintf_typval(char *str, size_t str_m, const char *fmt, va_list ap, typval_T *tvs);
+int vim_vsnprintf(char *str, size_t str_m, const char *fmt, va_list ap)
+	ATTRIBUTE_FORMAT_PRINTF(3, 0);
+int vim_vsnprintf_typval(char *str, size_t str_m, const char *fmt, va_list ap, typval_T *tvs)
+	ATTRIBUTE_FORMAT_PRINTF(3, 0);
 
 # include "message.pro"
 # include "misc1.pro"
@@ -284,11 +258,7 @@ void mbyte_im_set_active(int active_arg)
 #  include "channel.pro"
 
 // Not generated automatically, to add extra attribute.
-void ch_log(channel_T *ch, const char *fmt, ...)
-#  ifdef USE_PRINTF_FORMAT_ATTRIBUTE
-    __attribute__((format(printf, 2, 3)))
-#  endif
-    ;
+void ch_log(channel_T *ch, const char *fmt, ...) ATTRIBUTE_FORMAT_PRINTF(2, 3);
 
 # endif
 
--- a/src/term.c
+++ b/src/term.c
@@ -100,7 +100,7 @@ char		*tgetstr(char *, char **);
     // Change this to "if 1" to debug what happens with termresponse.
 #  if 0
 #   define DEBUG_TERMRESPONSE
-static void log_tr(const char *fmt, ...);
+static void log_tr(const char *fmt, ...) ATTRIBUTE_FORMAT_PRINTF(1, 2);
 #   define LOG_TR(msg) log_tr msg
 #  else
 #   define LOG_TR(msg) do { /**/ } while (0)
--- a/src/version.c
+++ b/src/version.c
@@ -756,6 +756,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    3274,
+/**/
     3273,
 /**/
     3272,
--- a/src/vim.h
+++ b/src/vim.h
@@ -2132,8 +2132,21 @@ typedef struct _stat64 stat_T;
 typedef struct stat stat_T;
 #endif
 
-#if defined(__GNUC__) && !defined(__MINGW32__)
-# define USE_PRINTF_FORMAT_ATTRIBUTE
+#if (defined(__GNUC__) || defined(__clang__)) && !defined(__MINGW32__)
+# define ATTRIBUTE_FORMAT_PRINTF(fmt_idx, arg_idx) \
+    __attribute__((format(printf, fmt_idx, arg_idx)))
+#else
+# define ATTRIBUTE_FORMAT_PRINTF(fmt_idx, arg_idx)
+#endif
+
+#if defined(__GNUC__) || defined(__clang__)
+# define likely(x)      __builtin_expect((x), 1)
+# define unlikely(x)    __builtin_expect((x), 0)
+# define ATTRIBUTE_COLD __attribute__((cold))
+#else
+# define unlikely(x)  (x)
+# define likely(x)    (x)
+# define ATTRIBUTE_COLD
 #endif
 
 typedef enum {
--- a/src/vim9execute.c
+++ b/src/vim9execute.c
@@ -22,14 +22,6 @@
 
 #include "vim9.h"
 
-#if defined(__GNUC__) || defined(__clang__)
-# define likely(x)    __builtin_expect((x), 1)
-# define unlikely(x)  __builtin_expect((x), 0)
-#else
-# define unlikely(x)  (x)
-# define likely(x)    (x)
-#endif
-
 // Structure put on ec_trystack when ISN_TRY is encountered.
 typedef struct {
     int	    tcd_frame_idx;	// ec_frame_idx at ISN_TRY