From: Michael Jeanson Date: Fri, 26 Mar 2021 18:37:35 +0000 (-0400) Subject: fix: add format attribute to relevant functions (-Wsuggest-attribute=format) X-Git-Tag: v2.13.0-rc1~180 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=b1d36dcecece5826b07504fae171e76be800b4ef;p=lttng-ust.git fix: add format attribute to relevant functions (-Wsuggest-attribute=format) Change-Id: Ie0828d4bbf560275cc8e1cd550737f8be2ab0aae Signed-off-by: Michael Jeanson Signed-off-by: Mathieu Desnoyers --- diff --git a/doc/examples/demo-tracef/demo-vtracef.c b/doc/examples/demo-tracef/demo-vtracef.c index 4f219f23..dc094ce4 100644 --- a/doc/examples/demo-tracef/demo-vtracef.c +++ b/doc/examples/demo-tracef/demo-vtracef.c @@ -11,6 +11,7 @@ #include +__attribute__((format(printf, 1, 2))) void print_debug(const char* msg, ...) { va_list ap; diff --git a/doc/examples/demo-tracelog/demo-vtracelog.c b/doc/examples/demo-tracelog/demo-vtracelog.c index 4adaa019..eed8677c 100644 --- a/doc/examples/demo-tracelog/demo-vtracelog.c +++ b/doc/examples/demo-tracelog/demo-vtracelog.c @@ -11,6 +11,7 @@ #include +__attribute__((format(printf, 1, 2))) void print_err(const char* msg, ...) { va_list ap; diff --git a/include/lttng/tracef.h b/include/lttng/tracef.h index df4b4645..2b57ca8c 100644 --- a/include/lttng/tracef.h +++ b/include/lttng/tracef.h @@ -14,9 +14,11 @@ extern "C" { #endif extern +__attribute__((format(printf, 1, 2))) void _lttng_ust_tracef(const char *fmt, ...); extern +__attribute__((format(printf, 1, 0))) void _lttng_ust_vtracef(const char *fmt, va_list ap); #define tracef(fmt, ...) \ diff --git a/include/lttng/tracelog.h b/include/lttng/tracelog.h index 4dfb9d36..e80f2381 100644 --- a/include/lttng/tracelog.h +++ b/include/lttng/tracelog.h @@ -14,8 +14,10 @@ extern "C" { #endif #define TP_TRACELOG_CB_TEMPLATE(level) \ + __attribute__ ((format(printf, 4, 5))) \ extern void _lttng_ust_tracelog_##level(const char *file, \ int line, const char *func, const char *fmt, ...); \ + __attribute__ ((format(printf, 4, 0))) \ extern void _lttng_ust_vtracelog_##level(const char *file, \ int line, const char *func, const char *fmt, va_list ap); diff --git a/liblttng-ust/tracef.c b/liblttng-ust/tracef.c index 54fb735a..0ce6d11f 100644 --- a/liblttng-ust/tracef.c +++ b/liblttng-ust/tracef.c @@ -12,7 +12,7 @@ #define TRACEPOINT_DEFINE #include "lttng-ust-tracef-provider.h" -static inline __attribute__((always_inline)) +static inline __attribute__((always_inline, format(printf, 1, 0))) void __lttng_ust_vtracef(const char *fmt, va_list ap) { char *msg; @@ -28,11 +28,15 @@ end: return; } +__attribute__((format(printf, 1, 0))) +void _lttng_ust_vtracef(const char *fmt, va_list ap); void _lttng_ust_vtracef(const char *fmt, va_list ap) { __lttng_ust_vtracef(fmt, ap); } +__attribute__((format(printf, 1, 2))) +void _lttng_ust_tracef(const char *fmt, ...); void _lttng_ust_tracef(const char *fmt, ...) { va_list ap; diff --git a/liblttng-ust/tracelog.c b/liblttng-ust/tracelog.c index 5dc2ffc5..1f18853f 100644 --- a/liblttng-ust/tracelog.c +++ b/liblttng-ust/tracelog.c @@ -13,7 +13,7 @@ #include "lttng-ust-tracelog-provider.h" #define TRACELOG_CB(level) \ - static inline __attribute__((always_inline)) \ + static inline __attribute__((always_inline, format(printf, 4, 0))) \ void __lttng_ust_vtracelog_##level(const char *file, \ int line, const char *func, \ const char *fmt, va_list ap) \ @@ -32,6 +32,7 @@ return; \ } \ \ + __attribute__ ((format(printf, 4, 0))) \ void _lttng_ust_vtracelog_##level(const char *file, \ int line, const char *func, \ const char *fmt, va_list ap) \ @@ -39,6 +40,7 @@ __lttng_ust_vtracelog_##level(file, line, func, fmt, ap); \ } \ \ + __attribute__ ((format(printf, 4, 5))) \ void _lttng_ust_tracelog_##level(const char *file, \ int line, const char *func, \ const char *fmt, ...) \