From 93c8471233550b59623da5818ced35c5746ced4f Mon Sep 17 00:00:00 2001 From: Jon Shallow Date: Mon, 12 Feb 2018 15:28:24 +0000 Subject: [PATCH 1/2] debug.h: Add in parameter format checking to coap_log_impl() for GNUC For GNUC. make the function void coap_log_impl(coap_log_t level, const char *format, ...) __attribute__ ((format(printf, 2, 3))); --- include/coap/debug.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/coap/debug.h b/include/coap/debug.h index f475ad72..bebed8a5 100644 --- a/include/coap/debug.h +++ b/include/coap/debug.h @@ -57,7 +57,12 @@ const char *coap_package_version(void); * COAP_DEBUG_FD (for @p level >= @c LOG_WARNING). The text is output only when * @p level is below or equal to the log level that set by coap_set_log_level(). */ +#if (defined(__GNUC__)) +void coap_log_impl(coap_log_t level, + const char *format, ...) __attribute__ ((format(printf, 2, 3))); +#else void coap_log_impl(coap_log_t level, const char *format, ...); +#endif #ifndef coap_log #define coap_log(level, ...) do { if ((level)<=coap_get_log_level()) coap_log_impl((level), __VA_ARGS__); } while(0) From 64aa7ca30cb4225652f445a3652bce1ea1a6d8d9 Mon Sep 17 00:00:00 2001 From: Jon Shallow Date: Mon, 12 Feb 2018 15:28:58 +0000 Subject: [PATCH 2/2] coap_io.c: Fix coap_log warning message Adding in '__attribute__ ((format(printf, 2, 3))' causes coap_log(LOG_DEBUG, coap_socket_strerror()); to give a warning in coap_run_once --- src/coap_io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coap_io.c b/src/coap_io.c index 9af6d98e..f435f47b 100644 --- a/src/coap_io.c +++ b/src/coap_io.c @@ -1169,7 +1169,7 @@ coap_run_once(coap_context_t *ctx, unsigned timeout_ms) { #else if (errno != EINTR) { #endif - coap_log(LOG_DEBUG, coap_socket_strerror()); + coap_log(LOG_DEBUG, "%s", coap_socket_strerror()); return -1; } }