From 9783d4ed913c6134f3b25fff7c93671158db9769 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Thu, 28 Mar 2019 16:01:46 +0800 Subject: [PATCH] coap_debug.c: fix format warning when compiling with GCC 8 When compiling libcoap with format truncation warnings enabled, GCC warns about the potential issue with "%u.%02u" format string, since the first argument may produce more than one byte of output: error: '%02u' directive output may be truncated writing 2 bytes into a region of size between 0 and 3 [-Werror=format-truncation=] The first argument (class) is limited to 3 bits according to the specification. Mask the higher bits to fix the warning. --- src/coap_debug.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coap_debug.c b/src/coap_debug.c index 109c0a76..39731ad9 100644 --- a/src/coap_debug.c +++ b/src/coap_debug.c @@ -291,7 +291,7 @@ msg_code_string(uint16_t c) { } else if (c >= 224 && c - 224 < (int)(sizeof(signals)/sizeof(const char *))) { return signals[c-224]; } else { - snprintf(buf, sizeof(buf), "%u.%02u", c >> 5, c & 0x1f); + snprintf(buf, sizeof(buf), "%u.%02u", (c >> 5) & 0x7, c & 0x1f); return buf; } }