]> The Tcpdump Group git mirrors - libpcap/commitdiff
Squelch warnings.
authorGuy Harris <[email protected]>
Tue, 20 Mar 2018 19:54:08 +0000 (12:54 -0700)
committerGuy Harris <[email protected]>
Tue, 20 Mar 2018 19:54:08 +0000 (12:54 -0700)
xdtoi turns an (unsigned) 8-bit character from a string into a hex digit
value, which is also an unsigned 8-bit byte value; make it take a u_char
as an argument and return a u_char, and make the octet value accumulated
in pcap_next_etherent() a u_char as well.

Use a size_t variable for a size.

etherent.c

index f9bb99c2dc40d5267c5dae3e281ceb78e71877dd..5930eae28e4a3618d1db5fd51638f36f8ca0a4c4 100644 (file)
 #include "os-proto.h"
 #endif
 
-static inline int xdtoi(int);
 static inline int skip_space(FILE *);
 static inline int skip_line(FILE *);
 
 /* Hex digit to integer. */
-static inline int
-xdtoi(int c)
+static inline u_char
+xdtoi(u_char c)
 {
        if (isdigit(c))
-               return c - '0';
+               return (u_char)(c - '0');
        else if (islower(c))
-               return c - 'a' + 10;
+               return (u_char)(c - 'a' + 10);
        else
-               return c - 'A' + 10;
+               return (u_char)(c - 'A' + 10);
 }
 
 static inline int
@@ -81,8 +80,10 @@ skip_line(FILE *f)
 struct pcap_etherent *
 pcap_next_etherent(FILE *fp)
 {
-       register int c, d, i;
+       register int c, i;
+       u_char d;
        char *bp;
+       size_t namesize;
        static struct pcap_etherent e;
 
        memset((char *)&e, 0, sizeof(e));
@@ -148,14 +149,14 @@ pcap_next_etherent(FILE *fp)
 
                /* pick up name */
                bp = e.name;
-               /* Use 'd' to prevent buffer overflow. */
-               d = sizeof(e.name) - 1;
+               /* Use 'namesize' to prevent buffer overflow. */
+               namesize = sizeof(e.name) - 1;
                do {
                        *bp++ = c;
                        c = getc(fp);
                        if (c == EOF)
                                return (NULL);
-               } while (!isspace(c) && --d > 0);
+               } while (!isspace(c) && --namesize != 0);
                *bp = '\0';
 
                /* Eat trailing junk */