From ea35cfaa616096dd1d770fbda5a735108e1725f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Pokorn=C3=BD?= Date: Wed, 3 Feb 2016 15:30:39 +0100 Subject: [PATCH 1/2] build: avoid too keen -Wsuggest-attribute=format warning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With gcc 5.3.1 20151207: > log.c: In function 'cs_format': > log.c:182:2: warning: function might be possible candidate for > 'gnu_printf' format attribute [-Wsuggest-attribute=format] > len = vsnprintf(str, QB_LOG_MAX_LEN, cs->format, ap_copy); > ^ We certainly don't want to disable that warning globally so make use of diagnostic pragmas for GCC instead in one instance that we cannot annotate properly. Signed-off-by: Jan Pokorný --- configure.ac | 6 ++++++ lib/log.c | 9 +++++++++ 2 files changed, 15 insertions(+) diff --git a/configure.ac b/configure.ac index b8742e0..50e1549 100644 --- a/configure.ac +++ b/configure.ac @@ -488,6 +488,12 @@ for j in $WARNLIST; do fi done +# warnings suppression +if test x"$GCC" = xyes && cc_supports_flag -Wsuggest-attribute=format; then + AC_DEFINE([HAVE_GCC_SUGGEST_ATTRIBUTE_FORMAT], [], + [gcc supports -Wsuggest-attribute=format]) +fi + # --- coverage --- if test "x${enable_coverage}" = xyes && \ cc_supports_flag -ftest-coverage && \ diff --git a/lib/log.c b/lib/log.c index 3336af9..b6eb3ce 100644 --- a/lib/log.c +++ b/lib/log.c @@ -172,6 +172,12 @@ _cs_matches_filter_(struct qb_log_callsite *cs, * @param[in] cs Callsite containing format to use * @param[in] ap Variable arguments for format */ +#ifdef HAVE_GCC_SUGGEST_ATTRIBUTE_FORMAT +/* suppress suggestion that we currently can do nothing better about + as the format specification is hidden in cs argument */ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wsuggest-attribute=format" +#endif static inline void cs_format(char *str, struct qb_log_callsite *cs, va_list ap) { @@ -188,6 +194,9 @@ cs_format(char *str, struct qb_log_callsite *cs, va_list ap) str[len - 1] = '\0'; } } +#ifdef HAVE_GCC_SUGGEST_ATTRIBUTE_FORMAT +#pragma GCC diagnostic pop +#endif void qb_log_real_va_(struct qb_log_callsite *cs, va_list ap) From 736e2c8153aa93025491849fa956fa7a3124d495 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Pokorn=C3=BD?= Date: Wed, 3 Feb 2016 15:36:55 +0100 Subject: [PATCH 2/2] includes: format __attribute__ func. annotations in qblog.h MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jan Pokorný --- include/qb/qblog.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/include/qb/qblog.h b/include/qb/qblog.h index 042d7a0..870cbae 100644 --- a/include/qb/qblog.h +++ b/include/qb/qblog.h @@ -296,7 +296,8 @@ void qb_log_from_external_source(const char *function, uint8_t priority, uint32_t lineno, uint32_t tags, - ...); + ...) + __attribute__ ((format (printf, 3, 7))); /** * Get or create a callsite at the give position. @@ -323,7 +324,8 @@ void qb_log_from_external_source_va(const char *function, uint8_t priority, uint32_t lineno, uint32_t tags, - va_list ap); + va_list ap) + __attribute__ ((format (printf, 3, 0))); /** * This is the function to generate a log message if you want to