[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[RP] [PATCH] add __attribute__ ((format, ...)) with gcc

From: Bernhard R. Link
Subject: [RP] [PATCH] add __attribute__ ((format, ...)) with gcc
Date: Tue, 25 Mar 2014 00:31:24 +0100
User-agent: Mutt/1.5.23 (2014-03-12)

This allows gcc to check if the variadic arguments fit the format
descriptor given.

 src/actions.h   |  2 +-
 src/bar.h       |  2 +-
 src/globals.h   |  6 ------
 src/ratpoison.h | 11 ++++++++++-
 src/sbuf.h      |  4 ++--
 5 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/src/actions.h b/src/actions.h
index 837d64f..ac7e697 100644
--- a/src/actions.h
+++ b/src/actions.h
@@ -225,7 +225,7 @@ void del_frame_undo (rp_frame_undo *u);
 rp_keymap *find_keymap (const char *name);
 void init_user_commands(void);
 void initialize_default_keybindings (void);
-cmdret *cmdret_new (int success, const char *fmt, ...);
+cmdret *cmdret_new (int success, const char *fmt, ...) PRINTFFORMAT(2,3);
 void cmdret_free (cmdret *ret);
 void keymap_free (rp_keymap *map);
 void free_user_commands (void);
diff --git a/src/bar.h b/src/bar.h
index 005501a..e358182 100644
--- a/src/bar.h
+++ b/src/bar.h
@@ -33,7 +33,7 @@ int bar_x (rp_screen *s, int width);
 void message (char *s);
 void marked_message (char *s, int mark_start, int mark_end);
-void marked_message_printf (int mark_start, int mark_end, const char *fmt, 
+void marked_message_printf (int mark_start, int mark_end, const char *fmt, 
 void redraw_last_message (void);
 void show_last_message (void);
 void free_bar (void);
diff --git a/src/globals.h b/src/globals.h
index c273c3f..e0aabaf 100644
--- a/src/globals.h
+++ b/src/globals.h
@@ -70,12 +70,6 @@
 #define STYLE_NORMAL  0
 #define STYLE_INVERSE 1
-#ifdef __GNUC__
-#define UNUSED __attribute__ ((unused))
-#define UNUSED
 /* The list of groups. */
 extern struct list_head rp_groups;
diff --git a/src/ratpoison.h b/src/ratpoison.h
index 69b35c8..80188e8 100644
--- a/src/ratpoison.h
+++ b/src/ratpoison.h
@@ -33,6 +33,15 @@
 #include <X11/Xlocale.h>
 #include <fcntl.h>
+/* Macros to improve gcc warning generation without disturbing other compilers 
+#ifdef __GNUC__
+#define UNUSED __attribute__ ((unused))
+#define PRINTFFORMAT(f, n) __attribute__ ((format (printf, f, n)))
+#define UNUSED
+#define PRINTFFORMAT(f, n)
 /* Helper macro for error and debug reporting. */
 #define PRINT_LINE(type) printf (PACKAGE ":%s:%d: %s: ",__FILE__,  __LINE__, 
@@ -92,7 +101,7 @@ void fatal (const char *msg);
 void *xmalloc (size_t size);
 void *xrealloc (void *ptr, size_t size);
 char *xstrdup (const char *s);
-char *xsprintf (const char *fmt, ...);
+char *xsprintf (const char *fmt, ...) PRINTFFORMAT(1,2);
 char *xvsprintf (const char *fmt, va_list ap);
 int str_comp (char *s1, char *s2, size_t len);
 char *strtok_ws (char *s);
diff --git a/src/sbuf.h b/src/sbuf.h
index 23132d4..d0dbf66 100644
--- a/src/sbuf.h
+++ b/src/sbuf.h
@@ -42,8 +42,8 @@ char *sbuf_nconcat (struct sbuf *b, const char *str, int len);
 char *sbuf_copy (struct sbuf *b, const char *str);
 char *sbuf_clear (struct sbuf *b);
 char *sbuf_get (struct sbuf *b);
-char *sbuf_printf (struct sbuf *b, const char *fmt, ...);
-char *sbuf_printf_concat (struct sbuf *b, const char *fmt, ...);
+char *sbuf_printf (struct sbuf *b, const char *fmt, ...) PRINTFFORMAT(2,3);
+char *sbuf_printf_concat (struct sbuf *b, const char *fmt, ...) 
 void  sbuf_chop (struct sbuf *b);
 #endif /* ! _RATPOISON_SBUF_H */

        Bernhard R. Link
F8AC 04D5 0B9B 064B 3383  C3DA AFFC 96D1 151D FFDC

reply via email to

[Prev in Thread] Current Thread [Next in Thread]