Skip to content

Commit aae379f

Browse files
junqingzoucarlescufi
authored andcommitted
net: mqtt: Debug logging of pointers
Cast pointer to `void *` for `%p` parameter. Otherwise lots of warnings in the log like below: `<wrn> cbprintf_package: (unsigned) char * used for %p argument. It's recommended to cast it to void * because it may cause misbehavior in certain configurations. String:"%s: (%p): >> length:0x%08x cur:%p, end:%p" argument:3` Signed-off-by: Jun Qing Zou <[email protected]>
1 parent d7ca015 commit aae379f

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

subsys/net/lib/mqtt/mqtt_decoder.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ LOG_MODULE_REGISTER(net_mqtt_dec, CONFIG_MQTT_LOG_LEVEL);
2929
*/
3030
static int unpack_uint8(struct buf_ctx *buf, uint8_t *val)
3131
{
32-
NET_DBG(">> cur:%p, end:%p", buf->cur, buf->end);
32+
NET_DBG(">> cur:%p, end:%p", (void *)buf->cur, (void *)buf->end);
3333

3434
if ((buf->end - buf->cur) < sizeof(uint8_t)) {
3535
return -EINVAL;
@@ -55,7 +55,7 @@ static int unpack_uint8(struct buf_ctx *buf, uint8_t *val)
5555
*/
5656
static int unpack_uint16(struct buf_ctx *buf, uint16_t *val)
5757
{
58-
NET_DBG(">> cur:%p, end:%p", buf->cur, buf->end);
58+
NET_DBG(">> cur:%p, end:%p", (void *)buf->cur, (void *)buf->end);
5959

6060
if ((buf->end - buf->cur) < sizeof(uint16_t)) {
6161
return -EINVAL;
@@ -85,7 +85,7 @@ static int unpack_utf8_str(struct buf_ctx *buf, struct mqtt_utf8 *str)
8585
uint16_t utf8_strlen;
8686
int err_code;
8787

88-
NET_DBG(">> cur:%p, end:%p", buf->cur, buf->end);
88+
NET_DBG(">> cur:%p, end:%p", (void *)buf->cur, (void *)buf->end);
8989

9090
err_code = unpack_uint16(buf, &utf8_strlen);
9191
if (err_code != 0) {
@@ -126,7 +126,7 @@ static int unpack_utf8_str(struct buf_ctx *buf, struct mqtt_utf8 *str)
126126
static int unpack_data(uint32_t length, struct buf_ctx *buf,
127127
struct mqtt_binstr *str)
128128
{
129-
NET_DBG(">> cur:%p, end:%p", buf->cur, buf->end);
129+
NET_DBG(">> cur:%p, end:%p", (void *)buf->cur, (void *)buf->end);
130130

131131
if ((buf->end - buf->cur) < length) {
132132
return -EINVAL;

subsys/net/lib/mqtt/mqtt_encoder.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ static int pack_uint8(uint8_t val, struct buf_ctx *buf)
4949
return -ENOMEM;
5050
}
5151

52-
NET_DBG(">> val:%02x cur:%p, end:%p", val, buf->cur, buf->end);
52+
NET_DBG(">> val:%02x cur:%p, end:%p", val, (void *)buf->cur, (void *)buf->end);
5353

5454
/* Pack value. */
5555
*(buf->cur++) = val;
@@ -73,7 +73,7 @@ static int pack_uint16(uint16_t val, struct buf_ctx *buf)
7373
return -ENOMEM;
7474
}
7575

76-
NET_DBG(">> val:%04x cur:%p, end:%p", val, buf->cur, buf->end);
76+
NET_DBG(">> val:%04x cur:%p, end:%p", val, (void *)buf->cur, (void *)buf->end);
7777

7878
/* Pack value. */
7979
*(buf->cur++) = (val >> 8) & 0xFF;
@@ -99,7 +99,7 @@ static int pack_utf8_str(const struct mqtt_utf8 *str, struct buf_ctx *buf)
9999
}
100100

101101
NET_DBG(">> str_size:%08x cur:%p, end:%p",
102-
(uint32_t)GET_UT8STR_BUFFER_SIZE(str), buf->cur, buf->end);
102+
(uint32_t)GET_UT8STR_BUFFER_SIZE(str), (void *)buf->cur, (void *)buf->end);
103103

104104
/* Pack length followed by string. */
105105
(void)pack_uint16(str->size, buf);
@@ -140,7 +140,7 @@ static uint8_t packet_length_encode(uint32_t length, struct buf_ctx *buf)
140140
uint8_t encoded_bytes = 0U;
141141

142142
NET_DBG(">> length:0x%08x cur:%p, end:%p", length,
143-
(buf == NULL) ? 0 : buf->cur, (buf == NULL) ? 0 : buf->end);
143+
(buf == NULL) ? 0 : (void *)buf->cur, (buf == NULL) ? 0 : (void *)buf->end);
144144

145145
do {
146146
encoded_bytes++;

0 commit comments

Comments
 (0)