mirror of
https://github.com/obgm/libcoap.git
synced 2026-11-30 02:07:09 +03:00
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.
This commit is contained in:
1 parent
641b5c174d
commit
9783d4ed91
1 file changed
+1
-1
+1
-1
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user