Patchwork [Open-FCoE,1/2] fcoemon: Add attributes to allow format-string parameter checking

login
register
mail settings
Submitter Mark Rustad
Date March 11, 2013, 5:52 p.m.
Message ID <20130311175205.10622.66164.stgit@host1-mdrustad.localdomain>
Download mbox | patch
Permalink /patch/10/
State Accepted
Headers show

Comments

Mark Rustad - March 11, 2013, 5:52 p.m.
Add format attributes to the static function declarations
of the functions print_result and print_err so that their
parameters can be checked against the given format strings.
Also add format attributes to the prototypes for sa_log,
sa_log_debug and sa_log_err. The format attribute on the
prototype for assert_failed was changed to use __format__
and __printf__ to avoid any possible name clash with a
symbol definition in the future.

Signed-off-by: Mark Rustad <mark.d.rustad@intel.com>
Tested-By: Marcus Dennis <marcusx.e.dennis@intel.com>
---

 Makefile.am             |    2 +-
 fcnsq.c                 |    2 ++
 fcping.c                |    2 ++
 include/fcoemon_utils.h |    7 +++++--
 4 files changed, 10 insertions(+), 3 deletions(-)

Patch

diff --git a/Makefile.am b/Makefile.am
index 1fcd8b7..6c78b7c 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -5,7 +5,7 @@  sbin_PROGRAMS = fcoeadm fcoemon fcping fipvlan fcnsq fcrls
 AM_CPPFLAGS = -I${srcdir}/include -I${builddir}/include
 ## pass the sysconfdir into the C proprocessor
 AM_CPPFLAGS += -DSYSCONFDIR="\"${sysconfdir}\""
-AM_CFLAGS = -Wall
+AM_CFLAGS = -Wall -Wformat=2
 
 ## rules for building fcoeadm
 fcoeadm_SOURCES = fcoeadm.c fcoeadm_display.c
diff --git a/fcnsq.c b/fcnsq.c
index e5abeb9..1d52f85 100644
--- a/fcnsq.c
+++ b/fcnsq.c
@@ -45,6 +45,7 @@  typedef __u64 u64;
 
 static bool quiet = false;
 
+__attribute__((__format__(__printf__, 2, 3)))
 static int print_result(const char *prefix, const char *format, ...)
 {
 	va_list ap;
@@ -58,6 +59,7 @@  static int print_result(const char *prefix, const char *format, ...)
 	return rc;
 }
 
+__attribute__((__format__(__printf__, 1, 2)))
 static int print_err(const char *format, ...)
 {
 	va_list ap;
diff --git a/fcping.c b/fcping.c
index 0b93012..bc51d5f 100644
--- a/fcping.c
+++ b/fcping.c
@@ -158,7 +158,9 @@  static struct fp_stats fp_stats;
 		p[7] = (u_char) (v) & 0xFF;		\
 	} while (0)
 
+__attribute__((__format__(__printf__, 2, 3)))
 static void sa_log_func(const char *func, const char *format, ...);
+__attribute__((__format__(__printf__, 3, 4)))
 static void sa_log_err(int, const char *func, const char *format, ...);
 static void sa_log_output(const char *buf);
 
diff --git a/include/fcoemon_utils.h b/include/fcoemon_utils.h
index a8ad27b..fb79ace 100644
--- a/include/fcoemon_utils.h
+++ b/include/fcoemon_utils.h
@@ -42,8 +42,11 @@ 
 
 #define ARRAY_SIZE(a)	(sizeof(a) / sizeof((a)[0]))
 
+__attribute__((__format__(__printf__, 1, 2)))
 void sa_log(const char *format, ...);
+__attribute__((__format__(__printf__, 1, 2)))
 void sa_log_debug(const char *format, ...);
+__attribute__((__format__(__printf__, 3, 4)))
 void sa_log_err(int, const char *func, const char *format, ...);
 
 /*
@@ -65,8 +68,8 @@  extern u_int sa_log_flags;          /* timestamp and other option flags */
 extern int sa_log_time_delta_min;   /* minimum diff to print in millisec */
 extern char *sa_log_prefix;         /* string to print before any message */
 
-extern void assert_failed(const char *s, ...)
-    __attribute__ ((format(printf, 1, 2)));
+__attribute__((__format__(__printf__, 1, 2)))
+extern void assert_failed(const char *s, ...);
 
 #ifndef UNLIKELY
 #define UNLIKELY(_x) (_x)