From: Guy Harris Date: Sun, 27 Sep 2015 22:30:28 +0000 (-0700) Subject: Squelch some compiler narrowing warnings. X-Git-Tag: libpcap-1.8.0-bp~142 X-Git-Url: https://git.tcpdump.org/libpcap/commitdiff_plain/e5377f60339c3df0d94e6906e457b6602bd81011 Squelch some compiler narrowing warnings. Either use the right types or, if we're forced by an API to stuff 64 bits into a 32-bit bag, cast the problem away. --- diff --git a/gencode.c b/gencode.c index 8e2e2967..70072d3c 100644 --- a/gencode.c +++ b/gencode.c @@ -271,14 +271,14 @@ static struct addrinfo *ai; #define NCHUNKS 16 #define CHUNK0SIZE 1024 struct chunk { - u_int n_left; + size_t n_left; void *m; }; static struct chunk chunks[NCHUNKS]; static int cur_chunk; -static void *newchunk(u_int); +static void *newchunk(size_t); static void freechunks(void); static inline struct block *new_block(int); static inline struct slist *new_stmt(int); @@ -362,8 +362,7 @@ static struct block *gen_ppi_dlt_check(void); static struct block *gen_msg_abbrev(int type); static void * -newchunk(n) - u_int n; +newchunk(size_t n) { struct chunk *cp; int k; @@ -415,7 +414,7 @@ char * sdup(s) register const char *s; { - int n = strlen(s) + 1; + size_t n = strlen(s) + 1; char *cp = newchunk(n); strlcpy(cp, s, n); diff --git a/pcap-win32.c b/pcap-win32.c index 35a034cf..7c749889 100644 --- a/pcap-win32.c +++ b/pcap-win32.c @@ -285,7 +285,7 @@ pcap_oid_get_request_win32(pcap_t *p, bpf_u_int32 oid, void *data, size_t len) * No need to copy the data - we're doing a fetch. */ oid_data_arg->Oid = oid; - oid_data_arg->Length = len; + oid_data_arg->Length = (ULONG)len; /* XXX - check for ridiculously large value? */ if (!PacketRequest(p->adapter, FALSE, oid_data_arg)) { pcap_win32_err_to_str(GetLastError(), errbuf); snprintf(p->errbuf, PCAP_ERRBUF_SIZE, @@ -324,7 +324,7 @@ pcap_oid_set_request_win32(pcap_t *p, bpf_u_int32 oid, const void *data, } oid_data_arg->Oid = oid; - oid_data_arg->Length = len; + oid_data_arg->Length = (ULONG)len; /* XXX - check for ridiculously large value? */ memcpy(oid_data_arg->Data, data, len); if (!PacketRequest(p->adapter, TRUE, oid_data_arg)) { pcap_win32_err_to_str(GetLastError(), errbuf); @@ -410,7 +410,7 @@ pcap_live_dump_win32(pcap_t *p, char *filename, int maxsize, int maxpacks) } /* Set the name of the dump file */ - res = PacketSetDumpName(p->adapter, filename, strlen(filename)); + res = PacketSetDumpName(p->adapter, filename, (int)strlen(filename)); if(res == FALSE){ snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "Error setting kernel dump file name"); @@ -746,7 +746,7 @@ pcap_inject_win32(pcap_t *p, const void *buf, size_t size){ return (-1); } - PacketInitPacket(PacketToSend,(PVOID)buf,size); + PacketInitPacket(PacketToSend, (PVOID)buf, (UINT)size); if(PacketSendPacket(p->adapter,PacketToSend,TRUE) == FALSE){ snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "send error: PacketSendPacket failed"); PacketFreePacket(PacketToSend); @@ -760,7 +760,7 @@ pcap_inject_win32(pcap_t *p, const void *buf, size_t size){ * "pcap_inject()" is expected to return the number of bytes * sent. */ - return (size); + return ((int)size); } static void diff --git a/pcap.c b/pcap.c index b07fd450..388802db 100644 --- a/pcap.c +++ b/pcap.c @@ -1536,7 +1536,7 @@ pcap_setnonblock_fd(pcap_t *p, int nonblock, char *errbuf) void pcap_win32_err_to_str(DWORD error, char *errbuf) { - int errlen; + size_t errlen; char *p; FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, error, 0, errbuf, diff --git a/sf-pcap.c b/sf-pcap.c index 86b9aec6..8d6e89a8 100644 --- a/sf-pcap.c +++ b/sf-pcap.c @@ -497,7 +497,7 @@ pcap_next_packet(pcap_t *p, struct pcap_pkthdr *hdr, u_char **data) * correctly in the savefile header. If the caplen isn't * grossly wrong, try to salvage. */ - bpf_u_int32 bytes_to_discard; + size_t bytes_to_discard; size_t bytes_to_read, bytes_read; char discard_buf[4096]; @@ -729,7 +729,7 @@ pcap_dump_open_append(pcap_t *p, const char *fname) { FILE *f; int linktype; - int amt_read; + size_t amt_read; struct pcap_file_header ph; linktype = dlt_to_linktype(p->linktype);