From c23aa713f979d8145471609120713de05052fa5b Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Thu, 22 Nov 2018 11:37:24 +0100 Subject: [PATCH] Try to fix compile warning in mdns.c src/apps/mdns/mdns.c: In function 'mdns_debug_print_answer': src/apps/mdns/mdns.c:796:24: warning: ', rdata = ' directive output may be truncated writing 10 bytes into a region of size between 8 and 15 [-Wformat-truncation=] snprintf(string, 35, "Type = %2d, class = %1d, rdata = ", a->info.type, a->info.klass); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ src/apps/mdns/mdns.c:796:3: note: 'snprintf' output between 31 and 38 bytes into a destination of size 35 snprintf(string, 35, "Type = %2d, class = %1d, rdata = ", a->info.type, a->info.klass); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --- src/apps/mdns/mdns.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/apps/mdns/mdns.c b/src/apps/mdns/mdns.c index 451c679f..d7ef6139 100644 --- a/src/apps/mdns/mdns.c +++ b/src/apps/mdns/mdns.c @@ -788,16 +788,22 @@ mdns_convert_out_to_in_pkt(struct mdns_packet *inpkt, struct mdns_outpacket *out static void mdns_debug_print_answer(struct mdns_packet *pkt, struct mdns_answer *a) { +#ifdef LWIP_DEBUG /* Arbitratry chose for 200 -> don't want to see more then that. It's only * for debug so not that important. */ char string[200]; int i; + int pos; - snprintf(string, 35, "Type = %2d, class = %1d, rdata = ", a->info.type, a->info.klass); - for (i = 0; ((i < a->rd_length) && ((30 + 4*i) < 195)) ; i++) { - snprintf(&string[30 + 4*i], 5, "%3d ", (u8_t)pbuf_get_at(pkt->pbuf, (u16_t)(a->rd_offset + i))); + pos = snprintf(string, sizeof(string), "Type = %2d, class = %1d, rdata = ", a->info.type, a->info.klass); + for (i = 0; ((i < a->rd_length) && ((pos + 4*i) < 195)) ; i++) { + snprintf(&string[pos + 4*i], 5, "%3d ", (u8_t)pbuf_get_at(pkt->pbuf, (u16_t)(a->rd_offset + i))); } LWIP_DEBUGF(MDNS_DEBUG, ("MDNS: %s\n", string)); +#else + LWIP_UNUSED_ARG(pkt); + LWIP_UNUSED_ARG(a); +#endif } /**