changeset 5208:6e53055c9989 draft

Fix compile warnings with prior.
author Roy Marples <roy@marples.name>
date Tue, 12 May 2020 10:58:31 +0100
parents 84b63f09c8a4
children baab981d3929
files src/dhcp-common.c src/dhcp.c src/dhcp6.c src/if-options.c src/privsep-root.c src/privsep-root.h
diffstat 6 files changed, 25 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/src/dhcp-common.c	Tue May 12 10:26:35 2020 +0100
+++ b/src/dhcp-common.c	Tue May 12 10:58:31 2020 +0100
@@ -983,7 +983,7 @@
 #ifdef PRIVSEP
 	if (ctx->options & DHCPCD_PRIVSEP &&
 	    !(ctx->options & DHCPCD_PRIVSEPROOT))
-		return ps_root_filemtime(ctx, file, time);
+		return (int)ps_root_filemtime(ctx, file, time);
 #else
 	UNUSED(ctx);
 #endif
@@ -998,7 +998,7 @@
 #ifdef PRIVSEP
 	if (ctx->options & DHCPCD_PRIVSEP &&
 	    !(ctx->options & DHCPCD_PRIVSEPROOT))
-		return ps_root_unlink(ctx, file);
+		return (int)ps_root_unlink(ctx, file);
 #else
 	UNUSED(ctx);
 #endif
--- a/src/dhcp.c	Tue May 12 10:26:35 2020 +0100
+++ b/src/dhcp.c	Tue May 12 10:58:31 2020 +0100
@@ -1150,7 +1150,8 @@
 	} buf;
 	struct dhcp_state *state = D_STATE(ifp);
 	struct bootp *lease;
-	ssize_t bytes;
+	ssize_t sbytes;
+	size_t bytes;
 	uint8_t type;
 #ifdef AUTH
 	const uint8_t *auth;
@@ -1162,25 +1163,26 @@
 
 	if (state->leasefile[0] == '\0') {
 		logdebugx("reading standard input");
-		bytes = read(fileno(stdin), buf.buf, sizeof(buf.buf));
+		sbytes = read(fileno(stdin), buf.buf, sizeof(buf.buf));
 	} else {
 		logdebugx("%s: reading lease `%s'",
 		    ifp->name, state->leasefile);
-		bytes = dhcp_readfile(ifp->ctx, state->leasefile,
+		sbytes = dhcp_readfile(ifp->ctx, state->leasefile,
 		    buf.buf, sizeof(buf.buf));
 	}
-	if (bytes == -1) {
+	if (sbytes == -1) {
 		if (errno != ENOENT)
 			logerr("%s: %s", ifp->name, state->leasefile);
 		return 0;
 	}
+	bytes = (size_t)sbytes;
 
 	/* Ensure the packet is at lease BOOTP sized
 	 * with a vendor area of 4 octets
 	 * (it should be more, and our read packet enforces this so this
 	 * code should not be needed, but of course people could
 	 * scribble whatever in the stored lease file. */
-	if ((size_t)bytes < DHCP_MIN_LEN) {
+	if (bytes < DHCP_MIN_LEN) {
 		logerrx("%s: %s: truncated lease", ifp->name, __func__);
 		return 0;
 	}
@@ -1224,7 +1226,7 @@
 		return 0;
 	}
 	memcpy(*bootp, buf.buf, bytes);
-	return (size_t)bytes;
+	return bytes;
 }
 
 static const struct dhcp_opt *
--- a/src/dhcp6.c	Tue May 12 10:26:35 2020 +0100
+++ b/src/dhcp6.c	Tue May 12 10:58:31 2020 +0100
@@ -2632,7 +2632,7 @@
 	state->acquired.tv_sec -= now - mtime;
 
 	/* Check to see if the lease is still valid */
-	fd = dhcp6_validatelease(ifp, &buf.dhcp6, bytes, NULL,
+	fd = dhcp6_validatelease(ifp, &buf.dhcp6, (size_t)bytes, NULL,
 	    &state->acquired);
 	if (fd == -1)
 		goto ex;
@@ -2649,10 +2649,10 @@
 auth:
 #ifdef AUTH
 	/* Authenticate the message */
-	o = dhcp6_findmoption(&buf.dhcp6, bytes, D6_OPTION_AUTH, &ol);
+	o = dhcp6_findmoption(&buf.dhcp6, (size_t)bytes, D6_OPTION_AUTH, &ol);
 	if (o) {
 		if (dhcp_auth_validate(&state->auth, &ifp->options->auth,
-		    buf.buf, bytes, 6, buf.dhcp6.type, o, ol) == NULL)
+		    buf.buf, (size_t)bytes, 6, buf.dhcp6.type, o, ol) == NULL)
 		{
 			logerr("%s: authentication failed", ifp->name);
 			bytes = 0;
@@ -2673,14 +2673,14 @@
 
 out:
 	free(state->new);
-	state->new = malloc(bytes);
+	state->new = malloc((size_t)bytes);
 	if (state->new == NULL) {
 		logerr(__func__);
 		goto ex;
 	}
 
-	memcpy(state->new, buf.buf, bytes);
-	state->new_len = bytes;
+	memcpy(state->new, buf.buf, (size_t)bytes);
+	state->new_len = (size_t)bytes;
 	return bytes;
 
 ex:
--- a/src/if-options.c	Tue May 12 10:26:35 2020 +0100
+++ b/src/if-options.c	Tue May 12 10:58:31 2020 +0100
@@ -2271,9 +2271,9 @@
 
 	do {
 		p = *buf;
-		c = memchr(*buf, '\n', *buflen);
+		c = memchr(*buf, '\n', (size_t)*buflen);
 		if (c == NULL) {
-			c = memchr(*buf, '\0', *buflen);
+			c = memchr(*buf, '\0', (size_t)*buflen);
 			if (c == NULL)
 				return NULL;
 			*buflen = c - *buf;
@@ -2342,7 +2342,7 @@
 	char buf[UDPLEN_MAX], *bp; /* 64k max config file size */
 	char *line, *option, *p;
 	ssize_t buflen;
-	ssize_t vlen;
+	size_t vlen;
 	int skip, have_profile, new_block, had_block;
 #if !defined(INET) || !defined(INET6)
 	size_t i;
@@ -2415,7 +2415,8 @@
 			buf[buflen] = '\0';
 		}
 #else
-		buflen = strlcpy(buf, dhcpcd_embedded_conf, sizeof(buf));
+		buflen = (ssize_t)strlcpy(buf, dhcpcd_embedded_conf,
+		    sizeof(buf));
 		if ((size_t)buflen >= sizeof(buf)) {
 			logerrx("%s: embedded config too big", __func__);
 			return ifo;
--- a/src/privsep-root.c	Tue May 12 10:26:35 2020 +0100
+++ b/src/privsep-root.c	Tue May 12 10:58:31 2020 +0100
@@ -228,7 +228,7 @@
 		return -1;
 	}
 	nc++;
-	return writefile(file, mode, nc, len - (nc - file));
+	return writefile(file, mode, nc, len - (size_t)(nc - file));
 }
 
 static ssize_t
@@ -317,7 +317,7 @@
 		}
 		break;
 	case PS_WRITEFILE:
-		err = ps_root_dowritefile(psm->ps_flags, data, len);
+		err = ps_root_dowritefile((mode_t)psm->ps_flags, data, len);
 		break;
 	case PS_FILEMTIME:
 		err = filemtime(data, &mtime);
@@ -547,7 +547,7 @@
 	return ps_root_readerror(ctx, NULL, 0);
 }
 
-int
+ssize_t
 ps_root_filemtime(struct dhcpcd_ctx *ctx, const char *file, time_t *time)
 {
 
--- a/src/privsep-root.h	Tue May 12 10:26:35 2020 +0100
+++ b/src/privsep-root.h	Tue May 12 10:58:31 2020 +0100
@@ -37,7 +37,7 @@
 ssize_t ps_root_readerror(struct dhcpcd_ctx *, void *, size_t);
 ssize_t ps_root_ioctl(struct dhcpcd_ctx *, ioctl_request_t, void *, size_t);
 ssize_t ps_root_unlink(struct dhcpcd_ctx *, const char *);
-int ps_root_filemtime(struct dhcpcd_ctx *, const char *, time_t *);
+ssize_t ps_root_filemtime(struct dhcpcd_ctx *, const char *, time_t *);
 ssize_t ps_root_readfile(struct dhcpcd_ctx *, const char *, void *, size_t);
 ssize_t ps_root_writefile(struct dhcpcd_ctx *, const char *, mode_t,
     const void *, size_t);