From 7ea6b55ab42e1a1b5cd09367f4d1bf2078c93a5d Mon Sep 17 00:00:00 2001 From: Denis Ovsienko Date: Fri, 15 Sep 2017 17:12:34 +0100 Subject: [PATCH] ICMP: Make a few cppcheck-inspired fixups. [print-icmp.c:402]: (warning) %d in format string (no. 2) requires 'int' but the argument type is 'unsigned int'. [print-icmp.c:560]: (style) The scope of the variable 'sum' can be reduced. [print-icmp.c:560]: (style) The scope of the variable 'icmp_sum' can be reduced. [print-icmp.c:509]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'. [print-icmp.c:517]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'. --- print-icmp.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/print-icmp.c b/print-icmp.c index 366094ef..0a949518 100644 --- a/print-icmp.c +++ b/print-icmp.c @@ -400,7 +400,7 @@ icmp_print(netdissect_options *ndo, const u_char *bp, u_int plen, const u_char * default: (void)snprintf(buf, sizeof(buf), - "%s protocol %d port %d unreachable", + "%s protocol %u port %u unreachable", ipaddr_string(ndo, &oip->ip_dst), oip->ip_p, dport); break; @@ -506,7 +506,7 @@ icmp_print(netdissect_options *ndo, const u_char *bp, u_int plen, const u_char * break; default: - (void)snprintf(buf, sizeof(buf), "time exceeded-#%d", + (void)snprintf(buf, sizeof(buf), "time exceeded-#%u", dp->icmp_code); break; } @@ -515,11 +515,11 @@ icmp_print(netdissect_options *ndo, const u_char *bp, u_int plen, const u_char * case ICMP_PARAMPROB: if (dp->icmp_code) (void)snprintf(buf, sizeof(buf), - "parameter problem - code %d", dp->icmp_code); + "parameter problem - code %u", dp->icmp_code); else { ND_TCHECK(dp->icmp_pptr); (void)snprintf(buf, sizeof(buf), - "parameter problem - octet %d", dp->icmp_pptr); + "parameter problem - octet %u", dp->icmp_pptr); } break; @@ -557,14 +557,14 @@ icmp_print(netdissect_options *ndo, const u_char *bp, u_int plen, const u_char * } ND_PRINT((ndo, "ICMP %s, length %u", str, plen)); if (ndo->ndo_vflag && !fragmented) { /* don't attempt checksumming if this is a frag */ - uint16_t sum, icmp_sum; - if (ND_TTEST2(*bp, plen)) { + uint16_t sum; + vec[0].ptr = (const uint8_t *)(const void *)dp; vec[0].len = plen; sum = in_cksum(vec, 1); if (sum != 0) { - icmp_sum = EXTRACT_16BITS(&dp->icmp_cksum); + uint16_t icmp_sum = EXTRACT_16BITS(&dp->icmp_cksum); ND_PRINT((ndo, " (wrong icmp cksum %x (->%x)!)", icmp_sum, in_cksum_shouldbe(icmp_sum, sum))); -- 2.39.5