[PATCH] Add GNU printf format attribute specifier for make_message()

Colin King colin.king at canonical.com
Wed Mar 18 23:59:33 UTC 2020


From: Colin Ian King <colin.king at canonical.com>

Use the printf format attribute specifier to add a little more
type checking.  Wrap this with a FWTS_FORMAT macro so that we
can no-op this for older compilers that don't support this
feature.

Signed-off-by: Colin Ian King <colin.king at canonical.com>
---
 src/lib/include/fwts.h | 8 ++++++++
 src/opal/reserv_mem.c  | 2 ++
 2 files changed, 10 insertions(+)

diff --git a/src/lib/include/fwts.h b/src/lib/include/fwts.h
index 7a05befc..7effe818 100644
--- a/src/lib/include/fwts.h
+++ b/src/lib/include/fwts.h
@@ -142,6 +142,14 @@
 #define OPTIMIZE0
 #endif
 
+/* print format attribute */
+#if ((defined(__GNUC__) && NEED_GNUC(3,2,0)) || \
+     (defined(__clang__) && NEED_CLANG(3, 7, 0)))
+#define FWTS_FORMAT(func, a, b) __attribute__((format(func, a, b)))
+#else
+#define FWTS_FORMAT(func, a, b)
+#endif
+
 #define FWTS_UNUSED(var)	(void)var
 
 #define FWTS_JSON_DATA_PATH	DATAROOTDIR "/fwts"
diff --git a/src/opal/reserv_mem.c b/src/opal/reserv_mem.c
index f243fb2e..82293c91 100644
--- a/src/opal/reserv_mem.c
+++ b/src/opal/reserv_mem.c
@@ -87,6 +87,8 @@ static int get_config(fwts_framework *fw,
 	return FWTS_OK;
 }
 
+static char *make_message(const char *fmt, ...) FWTS_FORMAT(printf, 1, 2);
+
 static char *make_message(const char *fmt, ...)
 {
 	char *p;
-- 
2.25.1




More information about the fwts-devel mailing list