Skip to content

Commit

Permalink
Correct format string specifiers
Browse files Browse the repository at this point in the history
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]
  • Loading branch information
vincent committed Jul 1, 2016
1 parent 9703fea commit 0f22680
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion libnetutil/netutil.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions ncat/ncat_connect.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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
Expand All @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions ncat/ncat_proxy.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion osscan2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions output.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1879,23 +1879,23 @@ 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();
}
if (FPR->osscan_closedtcpport > 0) {
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();
}
if (FPR->osscan_closedudpport > 0) {
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();
}
Expand Down
4 changes: 2 additions & 2 deletions tcpip.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 0f22680

Please sign in to comment.