From 0f22680426d18d109915631c86ccc8ebc0a03ff6 Mon Sep 17 00:00:00 2001 From: vincent Date: Fri, 1 Jul 2016 11:44:26 +0000 Subject: [PATCH] Correct format string specifiers The formats has been tested and verified on Mac OS X 10.8.5, Mac OS X 10.11.5 and Ubuntu 14.04 LTS, all on x86_64 machines and OSs. It mainly silences warnings. There were no warnings on Ubuntu but a few on Mac OS, so the fix is intended to silence warnings on Mac OS whithout triggering new warnings on other OSs. Example of warnings previously encountered: netutil.cc:2828:74: warning: format specifies type 'unsigned short' but the argument has type 'int' [-Wformat] --- libnetutil/netutil.cc | 2 +- ncat/ncat_connect.c | 6 +++--- ncat/ncat_proxy.c | 4 ++-- osscan2.cc | 2 +- output.cc | 6 +++--- tcpip.cc | 4 ++-- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/libnetutil/netutil.cc b/libnetutil/netutil.cc index 5460a16e24..8ab28dc61e 100644 --- a/libnetutil/netutil.cc +++ b/libnetutil/netutil.cc @@ -2825,7 +2825,7 @@ const char *ippackethdrinfo(const u8 *packet, u32 len, int detail) { case 4: strcpy(icmptype, "Fragmentation required"); - Snprintf(icmpfields, sizeof(icmpfields), "Next-Hop-MTU=%hu", icmppkt->data[2]<<8 | icmppkt->data[3]); + Snprintf(icmpfields, sizeof(icmpfields), "Next-Hop-MTU=%d", icmppkt->data[2]<<8 | icmppkt->data[3]); break; case 5: diff --git a/ncat/ncat_connect.c b/ncat/ncat_connect.c index b5bacc3a11..bb7fc0f1bf 100644 --- a/ncat/ncat_connect.c +++ b/ncat/ncat_connect.c @@ -258,7 +258,7 @@ static void connect_report(nsock_iod nsi) char digest_buf[SHA1_STRING_LENGTH + 1]; char *fp; - loguser("SSL connection to %s:%hu.", inet_socktop(&peer), + loguser("SSL connection to %s:%d.", inet_socktop(&peer), nsock_iod_get_peerport(nsi)); cert = SSL_get_peer_certificate((SSL *)nsock_iod_get_ssl(nsi)); @@ -285,7 +285,7 @@ static void connect_report(nsock_iod nsi) loguser("Connected to %s.\n", peer.un.sun_path); else #endif - loguser("Connected to %s:%hu.\n", inet_socktop(&peer), + loguser("Connected to %s:%d.\n", inet_socktop(&peer), nsock_iod_get_peerport(nsi)); } #else @@ -294,7 +294,7 @@ static void connect_report(nsock_iod nsi) loguser("Connected to %s.\n", peer.un.sun_path); else #endif - loguser("Connected to %s:%hu.\n", inet_socktop(&peer), + loguser("Connected to %s:%d.\n", inet_socktop(&peer), nsock_iod_get_peerport(nsi)); #endif } diff --git a/ncat/ncat_proxy.c b/ncat/ncat_proxy.c index cc0dc55e70..1c29aa277b 100644 --- a/ncat/ncat_proxy.c +++ b/ncat/ncat_proxy.c @@ -492,7 +492,7 @@ static int handle_connect(struct socket_buffer *client_sock, return 400; } if (o.debug > 1) - logdebug("CONNECT to %s:%hu.\n", request->uri.host, request->uri.port); + logdebug("CONNECT to %s:%d.\n", request->uri.host, request->uri.port); rc = resolve(request->uri.host, request->uri.port, &su.storage, &sslen, o.af); if (rc != 0) { @@ -680,7 +680,7 @@ static int do_transaction(struct http_request *request, if (request->uri.port == -1 || request->uri.port == 80) n = Snprintf(buf, sizeof(buf), "%s", request->uri.host); else - n = Snprintf(buf, sizeof(buf), "%s:%hu", request->uri.host, request->uri.port); + n = Snprintf(buf, sizeof(buf), "%s:%d", request->uri.host, request->uri.port); if (n < 0 || n >= sizeof(buf)) { /* Request Entity Too Large. */ return 501; diff --git a/osscan2.cc b/osscan2.cc index 06976518aa..6fb97e6620 100644 --- a/osscan2.cc +++ b/osscan2.cc @@ -3420,7 +3420,7 @@ bool HostOsScan::get_tcpopt_string(struct tcp_hdr *tcp, int mss, char *result, i break; /* Window Scale option has 3 bytes */ *p++ = 'W'; q++; - snprintf(p, length, "%hX", *((u8*)q)); + snprintf(p, length, "%hhX", *((u8*)q)); p += strlen(p); /* max movement of p is 2 (max WScale value is 0xFF) */ q++; length -= 3; diff --git a/output.cc b/output.cc index 4051f6c013..aca513708e 100644 --- a/output.cc +++ b/output.cc @@ -1879,7 +1879,7 @@ void printosscanoutput(Target *currenths) { xml_open_start_tag("portused"); xml_attribute("state", "open"); xml_attribute("proto", "tcp"); - xml_attribute("portid", "%hu", FPR->osscan_opentcpport); + xml_attribute("portid", "%d", FPR->osscan_opentcpport); xml_close_empty_tag(); xml_newline(); } @@ -1887,7 +1887,7 @@ void printosscanoutput(Target *currenths) { xml_open_start_tag("portused"); xml_attribute("state", "closed"); xml_attribute("proto", "tcp"); - xml_attribute("portid", "%hu", FPR->osscan_closedtcpport); + xml_attribute("portid", "%d", FPR->osscan_closedtcpport); xml_close_empty_tag(); xml_newline(); } @@ -1895,7 +1895,7 @@ void printosscanoutput(Target *currenths) { xml_open_start_tag("portused"); xml_attribute("state", "closed"); xml_attribute("proto", "udp"); - xml_attribute("portid", "%hu", FPR->osscan_closedudpport); + xml_attribute("portid", "%d", FPR->osscan_closedudpport); xml_close_empty_tag(); xml_newline(); } diff --git a/tcpip.cc b/tcpip.cc index ec774eafa9..7c7adcac94 100644 --- a/tcpip.cc +++ b/tcpip.cc @@ -1269,7 +1269,7 @@ int readtcppacket(const u8 *packet, int readdata) { log_write(LOG_PLAIN, "URG "); log_write(LOG_PLAIN, "\n"); - log_write(LOG_PLAIN, "ipid: %hu ttl: %hu ", ntohs(ip->ip_id), + log_write(LOG_PLAIN, "ipid: %hu ttl: %hhu ", ntohs(ip->ip_id), ip->ip_ttl); if (tcp->th_flags & (TH_SYN | TH_ACK)) @@ -1329,7 +1329,7 @@ int readudppacket(const u8 *packet, int readdata) { sourcehost, ntohs(udp->uh_sport), inet_ntoa(bullshit2), ntohs(udp->uh_dport), tot_len); - log_write(LOG_PLAIN, "ttl: %hu ", ip->ip_ttl); + log_write(LOG_PLAIN, "ttl: %hhu ", ip->ip_ttl); } } if (readdata && i < tot_len) {