Seven casts, a couple of tweaks and CFLAGS+=-Wsign-compare for the
authorkrw <krw@openbsd.org>
Sun, 9 Apr 2017 20:44:13 +0000 (20:44 +0000)
committerkrw <krw@openbsd.org>
Sun, 9 Apr 2017 20:44:13 +0000 (20:44 +0000)
win.

No intentional functional change.

sbin/dhclient/Makefile
sbin/dhclient/conflex.c
sbin/dhclient/dhclient.c
sbin/dhclient/kroute.c
sbin/dhclient/options.c
sbin/dhclient/parse.c

index 1ff3bf1..685425f 100644 (file)
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.18 2017/04/06 22:41:39 krw Exp $
+# $OpenBSD: Makefile,v 1.19 2017/04/09 20:44:13 krw Exp $
 #
 # Copyright (c) 1996, 1997 The Internet Software Consortium.
 # All rights reserved.
@@ -45,5 +45,6 @@ CFLAGS+=-Wall
 CFLAGS+=-Wstrict-prototypes -Wmissing-prototypes
 CFLAGS+=-Wmissing-declarations
 CFLAGS+=-Wshadow -Wpointer-arith -Wcast-qual
+CFLAGS+=-Wsign-compare
 
 .include <bsd.prog.mk>
index e52f204..cc16636 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: conflex.c,v 1.37 2017/04/08 20:16:04 krw Exp $        */
+/*     $OpenBSD: conflex.c,v 1.38 2017/04/09 20:44:13 krw Exp $        */
 
 /* Lexical scanner for dhclient config file. */
 
@@ -128,7 +128,7 @@ get_char(FILE *cfile)
                        lpos = 1;
                        cur_line[0] = 0;
                } else if (c != EOF) {
-                       if (lpos < sizeof(line1)) {
+                       if ((unsigned int)lpos < sizeof(line1)) {
                                cur_line[lpos - 1] = c;
                                cur_line[lpos] = 0;
                        }
index fa9c077..6daa095 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: dhclient.c,v 1.410 2017/04/08 20:16:04 krw Exp $      */
+/*     $OpenBSD: dhclient.c,v 1.411 2017/04/09 20:44:13 krw Exp $      */
 
 /*
  * Copyright 2004 Henning Brauer <henning@openbsd.org>
@@ -256,9 +256,11 @@ routehandler(struct interface_info *ifi)
        do {
                n = read(routefd, rtmmsg, 2048);
        } while (n == -1 && errno == EINTR);
+       if (n == -1)
+               goto done;
 
        rtm = (struct rt_msghdr *)rtmmsg;
-       if (n < sizeof(rtm->rtm_msglen) || n < rtm->rtm_msglen ||
+       if ((size_t)n < sizeof(rtm->rtm_msglen) || n < rtm->rtm_msglen ||
            rtm->rtm_version != RTM_VERSION)
                goto done;
 
@@ -268,7 +270,7 @@ routehandler(struct interface_info *ifi)
                    rtm->rtm_priority != RTP_PROPOSAL_DHCLIENT)
                        goto done;
                if ((rtm->rtm_flags & RTF_PROTO3) != 0) {
-                       if (rtm->rtm_seq == client->xid) {
+                       if (rtm->rtm_seq == (int32_t)client->xid) {
                                client->flags |= IN_CHARGE;
                                goto done;
                        } else if ((client->flags & IN_CHARGE) != 0) {
@@ -620,7 +622,7 @@ main(int argc, char *argv[])
        } else if (fstat(tailfd, &sb) == -1) {
                fatal("Cannot stat /etc/resolv.conf.tail");
        } else {
-               if (sb.st_size > 0 && sb.st_size < SIZE_MAX) {
+               if (sb.st_size > 0 && sb.st_size < LLONG_MAX) {
                        config->resolv_tail = calloc(1, sb.st_size + 1);
                        if (config->resolv_tail == NULL) {
                                fatalx("no memory for resolv.conf.tail "
@@ -2591,7 +2593,7 @@ priv_write_file(char *path, int flags, mode_t mode,
        n = write(fd, contents, sz);
        if (n == -1)
                log_warn("Couldn't write contents to '%s'", path);
-       else if (n < sz)
+       else if ((size_t)n < sz)
                log_warnx("Short contents write to '%s' (%zd vs %zu)", path,
                    n, sz);
 
index 3c90ee1..5686aea 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: kroute.c,v 1.87 2017/04/08 20:16:04 krw Exp $ */
+/*     $OpenBSD: kroute.c,v 1.88 2017/04/09 20:44:13 krw Exp $ */
 
 /*
  * Copyright 2012 Kenneth R Westerback <krw@openbsd.org>
@@ -638,14 +638,8 @@ create_route_label(struct sockaddr_rtlabel *label)
        len = snprintf(label->sr_label, sizeof(label->sr_label), "DHCLIENT %d",
            (int)getpid());
 
-       if (len == -1) {
-               log_warn("creating route label");
-               return (1);
-       }
-
-       if (len >= sizeof(label->sr_label)) {
-               log_warnx("creating route label: label too long (%d vs %zu)",
-                   len, sizeof(label->sr_label));
+       if (len == -1 || (unsigned int)len >= sizeof(label->sr_label)) {
+               log_warn("could not create route label");
                return (1);
        }
 
index 77cd61b..62c1bca 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: options.c,v 1.87 2017/04/08 20:16:04 krw Exp $        */
+/*     $OpenBSD: options.c,v 1.88 2017/04/09 20:44:13 krw Exp $        */
 
 /* DHCP options parsing and reassembly. */
 
@@ -270,7 +270,7 @@ pretty_print_classless_routes(unsigned char *src, size_t srclen)
                    bytes > sizeof(net.s_addr))
                        return (NULL);
                rslt = snprintf(bitsbuf, sizeof(bitsbuf), "/%d ", bits);
-               if (rslt == -1 || rslt >= sizeof(bitsbuf))
+               if (rslt == -1 || (unsigned int)rslt >= sizeof(bitsbuf))
                        return (NULL);
 
                memset(&net, 0, sizeof(net));
@@ -286,8 +286,8 @@ pretty_print_classless_routes(unsigned char *src, size_t srclen)
                        strlcat(string, ", ", sizeof(string));
                strlcat(string, inet_ntoa(net), sizeof(string));
                strlcat(string, bitsbuf, sizeof(string));
-               rslt = strlcat(string, inet_ntoa(gateway), sizeof(string));
-               if (rslt >= sizeof(string))
+               if (strlcat(string, inet_ntoa(gateway), sizeof(string)) >=
+                   sizeof(string))
                        return (NULL);
        }
 
index 5132827..082f15f 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: parse.c,v 1.49 2017/04/08 20:16:04 krw Exp $  */
+/*     $OpenBSD: parse.c,v 1.50 2017/04/09 20:44:13 krw Exp $  */
 
 /* Common parser code for dhcpd and dhclient. */
 
@@ -428,9 +428,9 @@ parse_warn(char *msg)
 
        log_warnx("%s line %d: %s", tlname, lexline, msg);
        log_warnx("%s", token_line);
-       if (lexchar < sizeof(spaces)) {
+       if ((unsigned int)lexchar < sizeof(spaces)) {
                memset(spaces, 0, sizeof(spaces));
-               for (i = 0; i < lexchar - 1; i++) {
+               for (i = 0; (int)i < lexchar - 1; i++) {
                        if (token_line[i] == '\t')
                                spaces[i] = '\t';
                        else