From 393d56401a826b2ff50d0f694c6f930413605522 Mon Sep 17 00:00:00 2001 From: Roy Marples Date: Sat, 30 May 2020 09:51:49 +0000 Subject: [PATCH] Fix some clang analyzer issues --- src/arp.c | 2 +- src/common.c | 2 ++ src/dhcp.c | 4 ++-- src/dhcpcd.c | 5 +++-- src/if.c | 7 ++++++- src/script.c | 2 +- 6 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/arp.c b/src/arp.c index 0e057aca..db1e188c 100644 --- a/src/arp.c +++ b/src/arp.c @@ -538,7 +538,7 @@ arp_new(struct interface *ifp, const struct in_addr *addr) } TAILQ_INIT(&state->arp_states); } else { - if (addr && (astate = arp_find(ifp, addr))) + if ((astate = arp_find(ifp, addr)) != NULL) return astate; } diff --git a/src/common.c b/src/common.c index ddab3042..2586c41c 100644 --- a/src/common.c +++ b/src/common.c @@ -160,6 +160,8 @@ get_line(char ** __restrict buf, ssize_t * __restrict buflen) do { p = *buf; + if (*buf == NULL) + return NULL; c = memchr(*buf, '\n', (size_t)*buflen); if (c == NULL) { c = memchr(*buf, '\0', (size_t)*buflen); diff --git a/src/dhcp.c b/src/dhcp.c index a7f60205..1bad22ca 100644 --- a/src/dhcp.c +++ b/src/dhcp.c @@ -3753,7 +3753,7 @@ static int dhcp_init(struct interface *ifp) { struct dhcp_state *state; - const struct if_options *ifo; + struct if_options *ifo; uint8_t len; char buf[(sizeof(ifo->clientid) - 1) * 3]; @@ -3824,7 +3824,7 @@ dhcp_init(struct interface *ifp) * at device start. */ return 0; - if (ifo->options & DHCPCD_CLIENTID) + if (ifo->options & DHCPCD_CLIENTID && state->clientid != NULL) logdebugx("%s: using ClientID %s", ifp->name, hwaddr_ntoa(state->clientid + 1, state->clientid[0], buf, sizeof(buf))); diff --git a/src/dhcpcd.c b/src/dhcpcd.c index 459f24c0..0842e6d0 100644 --- a/src/dhcpcd.c +++ b/src/dhcpcd.c @@ -1267,7 +1267,8 @@ dhcpcd_handlehwaddr(struct interface *ifp, loginfox("%s: new hardware address: %s", ifp->name, hwaddr_ntoa(hwaddr, hwlen, buf, sizeof(buf))); ifp->hwlen = hwlen; - memcpy(ifp->hwaddr, hwaddr, hwlen); + if (hwaddr != NULL) + memcpy(ifp->hwaddr, hwaddr, hwlen); } static void @@ -2062,7 +2063,7 @@ printpidfile: #ifdef USE_SIGNALS for (si = 0; si < dhcpcd_signals_ignore_len; si++) - signal(dhcpcd_signals_ignore[i], SIG_IGN); + signal(dhcpcd_signals_ignore[si], SIG_IGN); /* Save signal mask, block and redirect signals to our handler */ if (eloop_signal_set_cb(ctx.eloop, diff --git a/src/if.c b/src/if.c index 69e9ccb4..acf8dcac 100644 --- a/src/if.c +++ b/src/if.c @@ -686,10 +686,15 @@ if_nametospec(const char *ifname, struct if_spec *spec) errno = e; return -1; } - *ep-- = '\0'; + *ep = '\0'; +#ifdef __sun + ep--; +#endif } else { spec->lun = -1; +#ifdef __sun ep = spec->drvname + strlen(spec->drvname) - 1; +#endif } strlcpy(spec->devname, spec->drvname, sizeof(spec->devname)); diff --git a/src/script.c b/src/script.c index e592f6f0..d14a8f79 100644 --- a/src/script.c +++ b/src/script.c @@ -719,7 +719,7 @@ script_runreason(const struct interface *ifp, const char *reason) } #endif - status = script_run(ctx, argv); + script_run(ctx, argv); send_listeners: /* Send to our listeners */ -- 2.47.3