From: Francois-Xavier Le Bail Date: Fri, 9 Aug 2019 07:53:24 +0000 (+0200) Subject: Use %zu as the print format for size_t X-Git-Tag: libpcap-1.10-bp~462 X-Git-Url: https://git.tcpdump.org/libpcap/commitdiff_plain/f773b1c56122feaff9e9ecabbde3326b7c081233 Use %zu as the print format for size_t C99 support it and also Visual Studio VS 2015 and after. No more need for PRIsize format. --- diff --git a/pcap/pcap-inttypes.h b/pcap/pcap-inttypes.h index 8b1eb8b9..af2c23c8 100644 --- a/pcap/pcap-inttypes.h +++ b/pcap/pcap-inttypes.h @@ -106,23 +106,12 @@ #define PRIu64 "llu" #endif #endif - - /* - * MSVC's support library doesn't support %zu to print a size_t until - * Visual Studio 2017, but supports %Iu earlier, so use that. - */ - #define PRIsize "Iu" #elif defined(__MINGW32__) || !defined(_WIN32) /* * Compiler is MinGW or target is UN*X or MS-DOS. Just use * . */ #include - - /* - * Assume the support library supports %zu; it's required by C99. - */ - #define PRIsize "zu" #endif #endif /* pcap/pcap-inttypes.h */ diff --git a/savefile.c b/savefile.c index a3db8ff4..415e6844 100644 --- a/savefile.c +++ b/savefile.c @@ -395,7 +395,7 @@ pcap_fopen_offline_with_tstamp_precision(FILE *fp, u_int precision, errno, "error reading dump file"); } else { pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE, - "truncated dump file; tried to read %" PRIsize " file header bytes, only got %" PRIsize, + "truncated dump file; tried to read %zu file header bytes, only got %zu", sizeof(magic), amt_read); } return (NULL); diff --git a/sf-pcap.c b/sf-pcap.c index c48faf5d..cb980ce7 100644 --- a/sf-pcap.c +++ b/sf-pcap.c @@ -195,7 +195,7 @@ pcap_check_header(const uint8_t *magic, FILE *fp, u_int precision, char *errbuf, errno, "error reading dump file"); } else { pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE, - "truncated dump file; tried to read %" PRIsize " file header bytes, only got %" PRIsize, + "truncated dump file; tried to read %zu file header bytes, only got %zu", sizeof(hdr), amt_read); } *err = 1; @@ -462,7 +462,7 @@ pcap_next_packet(pcap_t *p, struct pcap_pkthdr *hdr, u_char **data) } else { if (amt_read != 0) { pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE, - "truncated dump file; tried to read %" PRIsize " header bytes, only got %" PRIsize, + "truncated dump file; tried to read %zu header bytes, only got %zu", ps->hdrsize, amt_read); return (-1); } @@ -622,7 +622,7 @@ pcap_next_packet(pcap_t *p, struct pcap_pkthdr *hdr, u_char **data) * the read finished. */ pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE, - "truncated dump file; tried to read %u captured bytes, only got %" PRIsize, + "truncated dump file; tried to read %u captured bytes, only got %zu", p->snapshot, amt_read); } return (-1); @@ -646,7 +646,7 @@ pcap_next_packet(pcap_t *p, struct pcap_pkthdr *hdr, u_char **data) "error reading dump file"); } else { pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE, - "truncated dump file; tried to read %u captured bytes, only got %" PRIsize, + "truncated dump file; tried to read %u captured bytes, only got %zu", hdr->caplen, bytes_read); } return (-1); @@ -698,7 +698,7 @@ pcap_next_packet(pcap_t *p, struct pcap_pkthdr *hdr, u_char **data) "error reading dump file"); } else { pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE, - "truncated dump file; tried to read %u captured bytes, only got %" PRIsize, + "truncated dump file; tried to read %u captured bytes, only got %zu", hdr->caplen, amt_read); } return (-1); diff --git a/sf-pcapng.c b/sf-pcapng.c index 997ad904..92d00f80 100644 --- a/sf-pcapng.c +++ b/sf-pcapng.c @@ -266,7 +266,7 @@ read_bytes(FILE *fp, void *buf, size_t bytes_to_read, int fail_on_eof, if (amt_read == 0 && !fail_on_eof) return (0); /* EOF */ pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE, - "truncated dump file; tried to read %" PRIsize " bytes, only got %" PRIsize, + "truncated dump file; tried to read %zu bytes, only got %zu", bytes_to_read, amt_read); } return (-1); @@ -302,7 +302,7 @@ read_block(FILE *fp, pcap_t *p, struct block_cursor *cursor, char *errbuf) if (bhdr.total_length < sizeof(struct block_header) + sizeof(struct block_trailer)) { pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE, - "block in pcapng dump file has a length of %u < %" PRIsize, + "block in pcapng dump file has a length of %u < %zu", bhdr.total_length, sizeof(struct block_header) + sizeof(struct block_trailer)); return (-1); @@ -316,7 +316,7 @@ read_block(FILE *fp, pcap_t *p, struct block_cursor *cursor, char *errbuf) * No. Report that as an error. */ pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE, - "block in pcapng dump file has a length of %u that is not a multiple of 4" PRIsize, + "block in pcapng dump file has a length of %u that is not a multiple of 4", bhdr.total_length); return (-1); } @@ -858,7 +858,7 @@ pcap_ng_check_header(const uint8_t *magic, FILE *fp, u_int precision, */ if (total_length < sizeof(*bhdrp) + sizeof(*shbp) + sizeof(struct block_trailer)) { pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE, - "Section Header Block in pcapng dump file has a length of %u < %" PRIsize, + "Section Header Block in pcapng dump file has a length of %u < %zu", total_length, sizeof(*bhdrp) + sizeof(*shbp) + sizeof(struct block_trailer)); *err = 1;