From e217f88289b9601e3a9a8d13477f867bcb83b5e2 Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Sun, 5 Aug 2018 15:59:44 -0700 Subject: Add PRIsize, to use as the print format for size_t, and use it. size_t may be bigger than unsigned long, so don't just cast to unsigned long and print with %lu". (In practice, the value is unlikely to be bigger, but this is cleaner.) We could use %zu on UN*X, as we require C99 support and C99 requires support for z as a size modifier, but MSVC doesn't support z as a size modifier until Visual Studio 2017. --- sf-pcapng.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'sf-pcapng.c') diff --git a/sf-pcapng.c b/sf-pcapng.c index 970c675c..06c896ac 100644 --- a/sf-pcapng.c +++ b/sf-pcapng.c @@ -261,9 +261,8 @@ 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 %lu bytes, only got %lu", - (unsigned long)bytes_to_read, - (unsigned long)amt_read); + "truncated dump file; tried to read %" PRIsize " bytes, only got %" PRIsize, + bytes_to_read, amt_read); } return (-1); } @@ -311,9 +310,9 @@ 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 < %lu", + "block in pcapng dump file has a length of %u < %" PRIsize, bhdr.total_length, - (unsigned long)(sizeof(struct block_header) + sizeof(struct block_trailer))); + sizeof(struct block_header) + sizeof(struct block_trailer)); return (-1); } @@ -831,9 +830,9 @@ pcap_ng_check_header(bpf_u_int32 magic, FILE *fp, u_int precision, char *errbuf, */ 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 < %lu", + "Section Header Block in pcapng dump file has a length of %u < %" PRIsize, total_length, - (unsigned long)(sizeof(*bhdrp) + sizeof(*shbp) + sizeof(struct block_trailer))); + sizeof(*bhdrp) + sizeof(*shbp) + sizeof(struct block_trailer)); *err = 1; return (NULL); } -- cgit v1.2.1