From e0a6d2f1081c682a243bb805103d28ddc2afedbe Mon Sep 17 00:00:00 2001 From: krw Date: Sat, 8 Apr 2017 20:16:04 +0000 Subject: [PATCH] Reduce the overburden of signed vs unsigned comparisons by sprinkling 'int' -> 'unsigned int' (and visa versa) where obvious. Steal a couple of 'unsigned' -> u_int32_t from reyk@'s dhcrelay tweaks. No intentional functional change. --- sbin/dhclient/clparse.c | 19 +++++++++++-------- sbin/dhclient/conflex.c | 5 +++-- sbin/dhclient/dhclient.c | 7 ++++--- sbin/dhclient/dhcpd.h | 8 ++++---- sbin/dhclient/kroute.c | 5 ++--- sbin/dhclient/options.c | 11 +++++++---- sbin/dhclient/packet.c | 8 ++++---- sbin/dhclient/parse.c | 6 +++--- 8 files changed, 38 insertions(+), 31 deletions(-) diff --git a/sbin/dhclient/clparse.c b/sbin/dhclient/clparse.c index a1bfc389138..69afbe44a51 100644 --- a/sbin/dhclient/clparse.c +++ b/sbin/dhclient/clparse.c @@ -1,4 +1,4 @@ -/* $OpenBSD: clparse.c,v 1.109 2017/04/04 13:01:20 krw Exp $ */ +/* $OpenBSD: clparse.c,v 1.110 2017/04/08 20:16:04 krw Exp $ */ /* Parser for dhclient config and lease files. */ @@ -64,7 +64,8 @@ void parse_client_statement(FILE *, struct interface_info *); int parse_X(FILE *, u_int8_t *, int); int parse_option_list(FILE *, u_int8_t *, size_t); void parse_interface_declaration(FILE *, struct interface_info *); -void parse_client_lease_statement(FILE *, int, struct interface_info *); +void parse_client_lease_statement(FILE *, unsigned int, + struct interface_info *); void parse_client_lease_declaration(FILE *, struct client_lease *, struct interface_info *); int parse_option_decl(FILE *, struct option_data *); @@ -359,9 +360,10 @@ parse_X(FILE *cfile, u_int8_t *buf, int max) int parse_option_list(FILE *cfile, u_int8_t *list, size_t sz) { - int ix, i, j; - int token; - char *val; + unsigned int ix, j; + int i; + int token; + char *val; memset(list, DHO_PAD, sz); ix = 0; @@ -465,7 +467,7 @@ parse_interface_declaration(FILE *cfile, struct interface_info *ifi) * client-lease-declarations client-lease-declaration */ void -parse_client_lease_statement(FILE *cfile, int is_static, +parse_client_lease_statement(FILE *cfile, unsigned int is_static, struct interface_info *ifi) { struct client_state *client = ifi->client; @@ -553,7 +555,8 @@ parse_client_lease_declaration(FILE *cfile, struct client_lease *lease, struct interface_info *ifi) { char *val; - int len, token; + unsigned int len; + int token; token = next_token(&val, cfile); @@ -632,7 +635,7 @@ parse_option_decl(FILE *cfile, struct option_data *options) u_int8_t buf[4]; u_int8_t cidr[5]; u_int8_t hunkbuf[1024]; - int hunkix = 0; + unsigned int hunkix = 0; char *fmt; struct in_addr ip_addr; u_int8_t *dp; diff --git a/sbin/dhclient/conflex.c b/sbin/dhclient/conflex.c index 4200b7a70dc..e52f204b338 100644 --- a/sbin/dhclient/conflex.c +++ b/sbin/dhclient/conflex.c @@ -1,4 +1,4 @@ -/* $OpenBSD: conflex.c,v 1.36 2017/04/03 18:23:36 krw Exp $ */ +/* $OpenBSD: conflex.c,v 1.37 2017/04/08 20:16:04 krw Exp $ */ /* Lexical scanner for dhclient config file. */ @@ -279,7 +279,8 @@ read_string(FILE *cfile) static int read_num_or_name(int c, FILE *cfile) { - int i, rv, xdigits; + unsigned int i, xdigits; + int rv; xdigits = isxdigit(c) ? 1 : 0; diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c index b00745de022..fa9c077221d 100644 --- a/sbin/dhclient/dhclient.c +++ b/sbin/dhclient/dhclient.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dhclient.c,v 1.409 2017/04/08 17:00:10 krw Exp $ */ +/* $OpenBSD: dhclient.c,v 1.410 2017/04/08 20:16:04 krw Exp $ */ /* * Copyright 2004 Henning Brauer @@ -2276,7 +2276,8 @@ get_ifname(struct interface_info *ifi, char *arg) { struct ifgroupreq ifgr; struct ifg_req *ifg; - int s, len; + unsigned int len; + int s; if (strcmp(arg, "egress") == 0) { s = socket(AF_INET, SOCK_DGRAM, 0); @@ -2867,7 +2868,7 @@ void add_classless_static_routes(struct option_data *opt, struct in_addr iface) { struct in_addr dest, netmask, gateway; - int bits, bytes, i; + unsigned int i, bits, bytes; i = 0; while (i < opt->len) { diff --git a/sbin/dhclient/dhcpd.h b/sbin/dhclient/dhcpd.h index e18593fdeda..9f905209af5 100644 --- a/sbin/dhclient/dhcpd.h +++ b/sbin/dhclient/dhcpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: dhcpd.h,v 1.168 2017/04/08 18:54:52 krw Exp $ */ +/* $OpenBSD: dhcpd.h,v 1.169 2017/04/08 20:16:04 krw Exp $ */ /* * Copyright (c) 2004 Henning Brauer @@ -204,7 +204,7 @@ int peek_token(char **, FILE *); extern int warnings_occurred; void skip_to_semi(FILE *); int parse_semi(FILE *); -char *parse_string(FILE *, int *); +char *parse_string(FILE *, unsigned int *); int parse_ip_addr(FILE *, struct in_addr *); int parse_cidr(FILE *, unsigned char *); void parse_ethernet(FILE *, struct ether_addr *); @@ -255,8 +255,8 @@ void routehandler(struct interface_info *); void assemble_eh_header(struct interface_info *, struct ether_header *); ssize_t decode_hw_header(unsigned char *, int, struct ether_addr *); ssize_t decode_udp_ip_header(unsigned char *, int, struct sockaddr_in *, - int); -u_int32_t checksum(unsigned char *, unsigned, u_int32_t); + u_int32_t); +u_int32_t checksum(unsigned char *, u_int32_t, u_int32_t); u_int32_t wrapsum(u_int32_t); /* clparse.c */ diff --git a/sbin/dhclient/kroute.c b/sbin/dhclient/kroute.c index 1d53f814b51..3c90ee1c06b 100644 --- a/sbin/dhclient/kroute.c +++ b/sbin/dhclient/kroute.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kroute.c,v 1.86 2017/04/05 18:22:31 krw Exp $ */ +/* $OpenBSD: kroute.c,v 1.87 2017/04/08 20:16:04 krw Exp $ */ /* * Copyright 2012 Kenneth R Westerback @@ -544,8 +544,7 @@ resolv_conf_priority(struct interface_info *ifi) struct sockaddr_rtlabel *sa_rl; pid_t pid; ssize_t len; - u_int32_t seq; - int s, rslt, iovcnt = 0; + int s, seq, rslt, iovcnt = 0; rslt = 0; diff --git a/sbin/dhclient/options.c b/sbin/dhclient/options.c index 51ea475ecff..77cd61bda44 100644 --- a/sbin/dhclient/options.c +++ b/sbin/dhclient/options.c @@ -1,4 +1,4 @@ -/* $OpenBSD: options.c,v 1.86 2017/04/08 18:54:52 krw Exp $ */ +/* $OpenBSD: options.c,v 1.87 2017/04/08 20:16:04 krw Exp $ */ /* DHCP options parsing and reassembly. */ @@ -255,7 +255,8 @@ pretty_print_classless_routes(unsigned char *src, size_t srclen) static char string[8196]; char bitsbuf[5]; /* to hold "/nn " */ struct in_addr net, gateway; - int bits, bytes, rslt; + unsigned int bytes; + int bits, rslt; memset(string, 0, sizeof(string)); @@ -297,7 +298,8 @@ int expand_search_domain_name(unsigned char *src, size_t srclen, int *offset, unsigned char *domain_search) { - int domain_name_len, i, label_len, pointer, pointed_len; + unsigned int i; + int domain_name_len, label_len, pointer, pointed_len; char *cursor; cursor = domain_search + strlen(domain_search); @@ -379,7 +381,8 @@ char * pretty_print_domain_search(unsigned char *src, size_t srclen) { static char domain_search[DHCP_DOMAIN_SEARCH_LEN]; - int offset, len, expanded_len, domains; + unsigned int offset; + int len, expanded_len, domains; unsigned char *cursor; memset(domain_search, 0, sizeof(domain_search)); diff --git a/sbin/dhclient/packet.c b/sbin/dhclient/packet.c index 9479a7a82c6..9c8f1ee3f62 100644 --- a/sbin/dhclient/packet.c +++ b/sbin/dhclient/packet.c @@ -1,4 +1,4 @@ -/* $OpenBSD: packet.c,v 1.33 2017/03/08 14:19:00 krw Exp $ */ +/* $OpenBSD: packet.c,v 1.34 2017/04/08 20:16:04 krw Exp $ */ /* Packet assembly code, originally contributed by Archie Cobbs. */ @@ -60,9 +60,9 @@ #include "log.h" u_int32_t -checksum(unsigned char *buf, unsigned nbytes, u_int32_t sum) +checksum(unsigned char *buf, u_int32_t nbytes, u_int32_t sum) { - int i; + unsigned int i; /* Checksum all the pairs of bytes first. */ for (i = 0; i < (nbytes & ~1U); i += 2) { @@ -117,7 +117,7 @@ decode_hw_header(unsigned char *buf, int bufix, struct ether_addr *from) ssize_t decode_udp_ip_header(unsigned char *buf, int bufix, struct sockaddr_in *from, - int buflen) + u_int32_t buflen) { struct ip *ip; struct udphdr *udp; diff --git a/sbin/dhclient/parse.c b/sbin/dhclient/parse.c index 828ab6c8f0b..51328276d7f 100644 --- a/sbin/dhclient/parse.c +++ b/sbin/dhclient/parse.c @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.c,v 1.48 2017/04/03 19:59:39 krw Exp $ */ +/* $OpenBSD: parse.c,v 1.49 2017/04/08 20:16:04 krw Exp $ */ /* Common parser code for dhcpd and dhclient. */ @@ -129,7 +129,7 @@ parse_semi(FILE *cfile) } char * -parse_string(FILE *cfile, int *len) +parse_string(FILE *cfile, unsigned int *len) { static char unvisbuf[1500]; char *val, *s; @@ -424,7 +424,7 @@ void parse_warn(char *msg) { static char spaces[81]; - int i; + unsigned int i; log_warnx("%s line %d: %s", tlname, lexline, msg); log_warnx("%s", token_line); -- 2.20.1