From: Roy Marples Date: Tue, 12 May 2020 09:58:31 +0000 (+0100) Subject: Fix compile warnings with prior. X-Git-Tag: v9.1.0~77 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b5672cc1ac480308cdb0942cd1880dd13b5039ae;p=thirdparty%2Fdhcpcd.git Fix compile warnings with prior. --- diff --git a/src/dhcp-common.c b/src/dhcp-common.c index b3e9c1e0..daf9dd3f 100644 --- a/src/dhcp-common.c +++ b/src/dhcp-common.c @@ -983,7 +983,7 @@ dhcp_filemtime(struct dhcpcd_ctx *ctx, const char *file, time_t *time) #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 @@ dhcp_unlink(struct dhcpcd_ctx *ctx, const char *file) #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 diff --git a/src/dhcp.c b/src/dhcp.c index d9683a93..6417f7f5 100644 --- a/src/dhcp.c +++ b/src/dhcp.c @@ -1150,7 +1150,8 @@ read_lease(struct interface *ifp, struct bootp **bootp) } 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 @@ read_lease(struct interface *ifp, struct bootp **bootp) 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 @@ out: return 0; } memcpy(*bootp, buf.buf, bytes); - return (size_t)bytes; + return bytes; } static const struct dhcp_opt * diff --git a/src/dhcp6.c b/src/dhcp6.c index f46ba424..6bc3e627 100644 --- a/src/dhcp6.c +++ b/src/dhcp6.c @@ -2632,7 +2632,7 @@ dhcp6_readlease(struct interface *ifp, int validate) 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 @@ dhcp6_readlease(struct interface *ifp, int validate) 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 @@ auth: 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: diff --git a/src/if-options.c b/src/if-options.c index 4ed38a98..329a3b2e 100644 --- a/src/if-options.c +++ b/src/if-options.c @@ -2271,9 +2271,9 @@ get_line(char ** __restrict buf, ssize_t * __restrict buflen) 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 @@ read_config(struct dhcpcd_ctx *ctx, 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 @@ read_config(struct dhcpcd_ctx *ctx, 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; diff --git a/src/privsep-root.c b/src/privsep-root.c index 0bcaf500..fb3c3253 100644 --- a/src/privsep-root.c +++ b/src/privsep-root.c @@ -228,7 +228,7 @@ ps_root_dowritefile(mode_t mode, void *data, size_t len) 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 @@ ps_root_recvmsgcb(void *arg, struct ps_msghdr *psm, struct msghdr *msg) } 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 @@ ps_root_writefile(struct dhcpcd_ctx *ctx, const char *file, mode_t mode, return ps_root_readerror(ctx, NULL, 0); } -int +ssize_t ps_root_filemtime(struct dhcpcd_ctx *ctx, const char *file, time_t *time) { diff --git a/src/privsep-root.h b/src/privsep-root.h index a5fdb252..d1a1b54b 100644 --- a/src/privsep-root.h +++ b/src/privsep-root.h @@ -37,7 +37,7 @@ int ps_root_stop(struct dhcpcd_ctx *ctx); 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);