Skip to contentSkip to conversation

cld: check parameters for HAIL_LOG

PATCH Applied Colin McCabe 2 participants 2 messages Jan 4, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cld: check parameters for HAIL_LOG

Another attempt at escaping the overly-aggressive spam filters...

GCC has a nifty ability to typecheck varargs functions that follow the printf conventions. This change uses that in HAIL_LOG. If you build with -Wall, gcc can now give warnings about HAIL_LOG invocations where there are too many or too few arguments, or arguments of the wrong types.

For non-GCC compilers, don't do anything (yet).

---
 include/hail_log.h |    9 ++++++++-
 1 files changed, 8 insertions(+), 1 deletions(-)
include/hail_log.h +8 -1
index d6794b4..88074a3 100644
@@ -3,8 +3,15 @@
 
 #include <stdbool.h>
 
+#ifdef __GNUC__
+#define ATTR_PRINTF(x,y) __attribute__((format(printf, x, y)))
+#else
+#define ATTR_PRINTF(x,y)
+#endif
+
 struct hail_log {
-	void (*func)(int prio, const char *fmt, ...);
+	void (*func)(int prio, const char *fmt, ...)
+		ATTR_PRINTF(2,3);
 	bool verbose;
 };
 
Signature · 1 line
1.6.2.5
Applied
#1 lore raw
Quoted 7 lines · Colin McCabe

Another attempt at escaping the overly-aggressive spam filters...

GCC has a nifty ability to typecheck varargs functions that follow the printf conventions. This change uses that in HAIL_LOG. If you build with -Wall, gcc can now give warnings about HAIL_LOG invocations where there are too many or too few arguments, or arguments of the wrong types.

Quoted 6 lines

For non-GCC compilers, don't do anything (yet).

---
  include/hail_log.h |    9 ++++++++-
  1 files changed, 8 insertions(+), 1 deletions(-)

applied