Skip to content

Commit

Permalink
clang scan-build: fix various build warning
Browse files Browse the repository at this point in the history
arping: fix dereference of null pointer.
clockdiff: fix assigned value is garbage or undefined warnings.
ninfod: fix dead assignment and use of uninitialized argument value.
ping: fix dead assignment.
rarpd: fix uninitialized argument value.
rdisc: fix uninitialized argument value.
tracepath: fix dereference of null pointer.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
  • Loading branch information
kerolasa committed Feb 2, 2019
1 parent 6811953 commit dc69f8d
Show file tree
Hide file tree
Showing 8 changed files with 9 additions and 10 deletions.
2 changes: 1 addition & 1 deletion arping.c
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ static int event_loop(struct run_state *ctl)
uint64_t exp, total_expires = 1;

unsigned char packet[4096];
struct sockaddr_storage from;
struct sockaddr_storage from = { 0 };
socklen_t addr_len = sizeof(from);

/* signalfd */
Expand Down
4 changes: 2 additions & 2 deletions clockdiff.c
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ static int measure(struct run_state *ctl)
.min1 = 0x7fffffff,
.min2 = 0x7fffffff
};
unsigned char opacket[64];
unsigned char opacket[64] = { 0 };
struct icmphdr *oicp = (struct icmphdr *)opacket;

mv.ip = (struct iphdr *)mv.packet;
Expand Down Expand Up @@ -527,7 +527,7 @@ int main(int argc, char **argv)
if (connect(ctl.sock_raw, (struct sockaddr *)&ctl.server, sizeof(ctl.server)) == -1)
error(1, errno, "connect");
if (ctl.ip_opt_len) {
struct sockaddr_in myaddr;
struct sockaddr_in myaddr = { 0 };
socklen_t addrlen = sizeof(myaddr);
unsigned char rspace[ctl.ip_opt_len];

Expand Down
1 change: 0 additions & 1 deletion ninfod/ni_ifaddrs.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ static int nl_getmsg(int sd, uint32_t seq, struct nlmsghdr **nlhp, int *done)
}
if (read_size == 0)
break;
nh = (struct nlmsghdr *) buff;
for (nh = (struct nlmsghdr *) buff; NLMSG_OK(nh, read_size); nh = (struct nlmsghdr *) NLMSG_NEXT(nh, read_size)) {
if ((pid_t) nh->nlmsg_pid != pid || nh->nlmsg_seq != seq)
continue;
Expand Down
2 changes: 1 addition & 1 deletion ninfod/ninfod.c
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ int main (int argc, char **argv)

init_core(0);

p = malloc(sizeof(*p));
p = calloc(1, sizeof(*p));
if (!p) {
DEBUG(LOG_WARNING, "%s(): failed to allocate packet context; sleep 1 sec.\n",
__func__);
Expand Down
2 changes: 0 additions & 2 deletions ping6_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -721,8 +721,6 @@ int ping6_run(int argc, char **argv, struct addrinfo *ai, struct socket_st *sock
if (!(packet = (unsigned char *)malloc((unsigned int)packlen)))
error(2, errno, _("memory allocation failed"));

hold = 1;

/* Estimate memory eaten by single packet. It is rough estimate.
* Actually, for small datalen's it depends on kernel side a lot. */
hold = datalen+8;
Expand Down
2 changes: 1 addition & 1 deletion rarpd.c
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ void arp_advise(int ifindex, unsigned char *lladdr, int lllen, uint32_t ipaddr)
void serve_it(int fd)
{
unsigned char buf[1024];
struct sockaddr_ll sll;
struct sockaddr_ll sll = { 0 };
socklen_t sll_len = sizeof(sll);
struct arphdr *a = (struct arphdr*)buf;
struct rarp_map *rmap;
Expand Down
2 changes: 1 addition & 1 deletion rdisc.c
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ char *sendaddress, *recvaddress;

int main(int argc, char **argv)
{
struct sockaddr_in from;
struct sockaddr_in from = { 0 };
char **av = argv;
struct sockaddr_in *to = &whereto;
struct sockaddr_in joinaddr;
Expand Down
4 changes: 3 additions & 1 deletion tracepath.c
Original file line number Diff line number Diff line change
Expand Up @@ -518,8 +518,10 @@ int main(int argc, char **argv)
sprintf(pbuf, "%u", ctl.base_port);

status = getaddrinfo(argv[0], pbuf, &hints, &result);
if (status)
if (status || !result) {
error(1, 0, "%s: %s", argv[0], gai_strerror(status));
abort();
}

for (ctl.ai = result; ctl.ai; ctl.ai = ctl.ai->ai_next) {
if (ctl.ai->ai_family != AF_INET6 && ctl.ai->ai_family != AF_INET)
Expand Down

0 comments on commit dc69f8d

Please sign in to comment.