[2938] in BarnOwl Developers

home help back first fref pref prev next nref lref last post

[PATCH] Use G_GNUC_PRINTF to get type-checking on our format strings

daemon@ATHENA.MIT.EDU (David Benjamin)
Sat Feb 26 00:52:27 2011

From: David Benjamin <davidben@MIT.EDU>
To: barnowl-dev@mit.edu
Date: Sat, 26 Feb 2011 00:52:13 -0500

The extra type-checking is nice. Though some preprocessor magic is
needed to get around owl_prototypes.h.
---
 configure.ac |    4 ++++
 fmtext.c     |    2 +-
 functions.c  |    6 +++---
 owl.h        |    3 +++
 4 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/configure.ac b/configure.ac
index 0a200ae..7f1a85e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -130,6 +130,10 @@ dnl Checks for typedefs, structures, and compiler characteristics.
 AX_CFLAGS_WARN_ALL([AM_CFLAGS])
 AX_C_CHECK_FLAG([-Wstrict-prototypes],[],[],[AM_CFLAGS="$AM_CFLAGS -Wstrict-prototypes"])
 
+dnl Shut gcc up about zero-length format strings; the warning's apparently for
+dnl efficiency reasons, which is bogus for custom functions.
+AX_C_CHECK_FLAG([-Wno-format-zero-length],[],[],[AM_CFLAGS="$AM_CFLAGS -Wno-format-zero-length"])
+
 m4_foreach([myflag],
   [[-Wno-pointer-sign],[-Wno-empty-body],[-Wno-unused-value]],
   [AX_C_CHECK_FLAG([myflag],[],[],[LIBFAIM_CFLAGS="$LIBFAIM_CFLAGS myflag"])])
diff --git a/fmtext.c b/fmtext.c
index 1614f2f..2e8636b 100644
--- a/fmtext.c
+++ b/fmtext.c
@@ -55,7 +55,7 @@ void owl_fmtext_append_normal(owl_fmtext *f, const char *text)
 }
 
 /* Append normal, uncolored text specified by format string to 'f' */
-void owl_fmtext_appendf_normal(owl_fmtext *f, const char *fmt, ...)
+void owl_fmtext_appendf_normal(owl_fmtext *f, const char *fmt, ...) G_GNUC_PRINTF_PROTO_ONLY(2, 3)
 {
   va_list ap;
   char *buff;
diff --git a/functions.c b/functions.c
index ddb3eac..efb21d3 100644
--- a/functions.c
+++ b/functions.c
@@ -1201,7 +1201,7 @@ void owl_function_resize(void)
   owl_global_set_resize_pending(&g);
 }
 
-void owl_function_debugmsg(const char *fmt, ...)
+void owl_function_debugmsg(const char *fmt, ...) G_GNUC_PRINTF_PROTO_ONLY(1, 2)
 {
   FILE *file;
   time_t now;
@@ -3341,7 +3341,7 @@ void owl_function_toggleoneline(void)
   owl_mainwin_redisplay(owl_global_get_mainwin(&g));
 }
 
-void owl_function_error(const char *fmt, ...)
+void owl_function_error(const char *fmt, ...) G_GNUC_PRINTF_PROTO_ONLY(1, 2)
 {
   static int in_error = 0;
   va_list ap;
@@ -3409,7 +3409,7 @@ void owl_function_showerrs(void)
   owl_function_popless_fmtext(&fm);
 }
 
-void owl_function_makemsg(const char *fmt, ...)
+void owl_function_makemsg(const char *fmt, ...) G_GNUC_PRINTF_PROTO_ONLY(1, 2)
 {
   va_list ap;
   char *str;
diff --git a/owl.h b/owl.h
index aac5ff3..0cea87b 100644
--- a/owl.h
+++ b/owl.h
@@ -648,7 +648,10 @@ typedef struct _owl_global {
 /* globals */
 extern owl_global g;
 
+#define G_GNUC_PRINTF_PROTO_ONLY(f_idx, a_idx) G_GNUC_PRINTF(f_idx, a_idx)
 #include "owl_prototypes.h"
+#undef G_GNUC_PRINTF_PROTO_ONLY
+#define G_GNUC_PRINTF_PROTO_ONLY(f_idx, a_idx)
 
 /* These were missing from the Zephyr includes before Zephyr 3. */
 #if defined HAVE_LIBZEPHYR && defined ZCONST
-- 
1.7.3.3.399.g06ddf


home help back first fref pref prev next nref lref last post