From: Francois-Xavier Le Bail Date: Fri, 14 Aug 2020 15:22:15 +0000 (+0200) Subject: BGP: Address a -Wformat-truncation= compiler warning X-Git-Tag: tcpdump-4.99-bp~268 X-Git-Url: https://git.tcpdump.org/tcpdump/commitdiff_plain/532ef3e8aaf700fdb5e9dec13d37ed21897bf4f9 BGP: Address a -Wformat-truncation= compiler warning The warning was: ./print-bgp.c: In function 'bgp_vpn_rd_print': ./print-bgp.c:797:65: warning: '%u' directive output may be truncated writing between 1 and 3 bytes into a region of size between 2 and 31 [-Wformat-truncation=] 797 | snprintf(pos, sizeof(rd) - (pos - rd), "%s:%u (%u.%u.%u.%u:%u)", | ^~ ./print-bgp.c:797:48: note: directive argument in the range [0, 255] 797 | snprintf(pos, sizeof(rd) - (pos - rd), "%s:%u (%u.%u.%u.%u:%u)", | ^~~~~~~~~~~~~~~~~~~~~~~~ ./print-bgp.c:797:48: note: directive argument in the range [0, 65535] ./print-bgp.c:797:9: note: 'snprintf' output between 15 and 50 bytes into a destination of size 41 797 | snprintf(pos, sizeof(rd) - (pos - rd), "%s:%u (%u.%u.%u.%u:%u)", | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 798 | as_printf(ndo, astostr, sizeof(astostr), GET_BE_U_4(pptr + 2)), | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 799 | GET_BE_U_2(pptr + 6), GET_U_1(pptr + 2), | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 800 | GET_U_1(pptr + 3), GET_U_1(pptr + 4), | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 801 | GET_U_1(pptr + 5), GET_BE_U_2(pptr + 6)); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --- diff --git a/print-bgp.c b/print-bgp.c index e5512ed8..67643be5 100644 --- a/print-bgp.c +++ b/print-bgp.c @@ -557,7 +557,8 @@ static const struct tok bgp_add_path_recvsend[] = { { 0, NULL }, }; -static char astostr[20]; +/* allocate space for the largest possible string */ +static char astostr[sizeof("xxxxx.xxxxx")]; /* * as_printf @@ -769,7 +770,7 @@ bgp_vpn_rd_print(netdissect_options *ndo, const u_char *pptr) { /* allocate space for the largest possible string */ - static char rd[sizeof("xxxxxxxxxx:xxxxx (xxx.xxx.xxx.xxx:xxxxx)")]; + static char rd[sizeof("xxxxx.xxxxx:xxxxx (xxx.xxx.xxx.xxx:xxxxx)")]; char *pos = rd; /* ok lets load the RD format */