]> The Tcpdump Group git mirrors - libpcap/commitdiff
Squelch some compiler narrowing warnings.
authorGuy Harris <[email protected]>
Sun, 27 Sep 2015 22:30:28 +0000 (15:30 -0700)
committerGuy Harris <[email protected]>
Sun, 27 Sep 2015 22:30:28 +0000 (15:30 -0700)
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.

gencode.c
pcap-win32.c
pcap.c
sf-pcap.c

index 8e2e2967ad6b690d8eae1984630d860f9d29e0b5..70072d3ca4523b3ad3ee8c15b78b65051d8b3e20 100644 (file)
--- 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);
index 35a034cff7644619b8be61342bf40d307d69ed37..7c749889abf04012cb667e19350ba6d43fee1dcf 100644 (file)
@@ -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 b07fd450dbe3c5294d98a4e69d2f11dac1b03283..388802db9cf83653f9422054c427f4531b68ac0a 100644 (file)
--- 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,
index 86b9aec69639799733733c7f624a194f256b0e4a..8d6e89a8698b0c25d0209f389838e27b0a6da308 100644 (file)
--- 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);