From: Guy Harris Date: Tue, 20 Mar 2018 19:54:08 +0000 (-0700) Subject: Squelch warnings. X-Git-Tag: libpcap-1.9-bp~207 X-Git-Url: https://git.tcpdump.org/libpcap/commitdiff_plain/fb7711f29bde3e906db5e07bb24c351253e99559?ds=sidebyside Squelch warnings. 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. --- diff --git a/etherent.c b/etherent.c index f9bb99c2..5930eae2 100644 --- a/etherent.c +++ b/etherent.c @@ -38,20 +38,19 @@ #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 */