From dd52040479f9c6a1a41febcd027b860ca8cb5b13 Mon Sep 17 00:00:00 2001 From: Kenneth R Westerback Date: Mon, 14 Aug 2017 22:13:00 +0000 Subject: Try for consistency in sizeof() usage. No intentional functional change. --- sbin/dhclient/clparse.c | 6 +++--- sbin/dhclient/dhclient.c | 33 ++++++++++++++++----------------- sbin/dhclient/kroute.c | 10 +++++----- 3 files changed, 24 insertions(+), 25 deletions(-) (limited to 'sbin/dhclient') diff --git a/sbin/dhclient/clparse.c b/sbin/dhclient/clparse.c index 1cad50dc153..3235181e7ed 100644 --- a/sbin/dhclient/clparse.c +++ b/sbin/dhclient/clparse.c @@ -1,4 +1,4 @@ -/* $OpenBSD: clparse.c,v 1.124 2017/07/14 16:21:03 krw Exp $ */ +/* $OpenBSD: clparse.c,v 1.125 2017/08/14 22:12:59 krw Exp $ */ /* Parser for dhclient config and lease files. */ @@ -505,7 +505,7 @@ parse_client_lease_statement(FILE *cfile, char *name) return NULL; } - lease = calloc(1, sizeof(struct client_lease)); + lease = calloc(1, sizeof(*lease)); if (lease == NULL) fatalx("no memory for lease."); @@ -777,7 +777,7 @@ parse_reject_statement(FILE *cfile) if (parse_ip_addr(cfile, &addr) == 0) return; - elem = malloc(sizeof(struct reject_elem)); + elem = malloc(sizeof(*elem)); if (elem == NULL) fatalx("no memory for reject address!"); diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c index d4304c323f1..00c9a6628be 100644 --- a/sbin/dhclient/dhclient.c +++ b/sbin/dhclient/dhclient.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dhclient.c,v 1.493 2017/08/13 17:57:32 krw Exp $ */ +/* $OpenBSD: dhclient.c,v 1.494 2017/08/14 22:12:59 krw Exp $ */ /* * Copyright 2004 Henning Brauer @@ -509,7 +509,7 @@ main(int argc, char *argv[]) log_init(log_perror, LOG_DAEMON); - ifi = calloc(1, sizeof(struct interface_info)); + ifi = calloc(1, sizeof(*ifi)); if (ifi == NULL) fatalx("ifi calloc"); if ((ioctlfd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) @@ -547,11 +547,11 @@ main(int argc, char *argv[]) fork_privchld(ifi, socket_fd[0], socket_fd[1]); close(socket_fd[0]); - if ((unpriv_ibuf = malloc(sizeof(struct imsgbuf))) == NULL) + if ((unpriv_ibuf = malloc(sizeof(*unpriv_ibuf))) == NULL) fatalx("no memory for unpriv_ibuf"); imsg_init(unpriv_ibuf, socket_fd[1]); - config = calloc(1, sizeof(struct client_config)); + config = calloc(1, sizeof(*config)); if (config == NULL) fatalx("config calloc"); @@ -1152,7 +1152,7 @@ packet_to_lease(struct interface_info *ifi, struct option_data *options) char *pretty, *buf, *name; int i; - lease = calloc(1, sizeof(struct client_lease)); + lease = calloc(1, sizeof(*lease)); if (lease == NULL) { log_warnx("lease declined: no memory for lease."); return NULL; @@ -1586,7 +1586,7 @@ make_request(struct interface_info *ifi, struct client_lease * lease) ifi->requested_address = lease->address; i = DHO_DHCP_REQUESTED_ADDRESS; options[i].data = (char *)&lease->address.s_addr; - options[i].len = sizeof(in_addr_t); + options[i].len = sizeof(lease->address.s_addr); } /* Send any options requested in the config file. */ @@ -1661,7 +1661,7 @@ make_decline(struct interface_info *ifi, struct client_lease *lease) /* Send back the address we're declining. */ i = DHO_DHCP_REQUESTED_ADDRESS; options[i].data = (char *)&lease->address.s_addr; - options[i].len = sizeof(in_addr_t); + options[i].len = sizeof(lease->address.s_addr); /* Send the uid if the user supplied one. */ i = DHO_DHCP_CLIENT_IDENTIFIER; @@ -1841,11 +1841,11 @@ lease_as_proposal(struct client_lease *lease) log_warnx("MS_CLASSLESS_STATIC_ROUTES too long"); } else { opt = &lease->options[DHO_ROUTERS]; - if (opt->len >= sizeof(struct in_addr)) { - proposal->rtstatic_len = 1 + sizeof(struct in_addr); + if (opt->len >= sizeof(in_addr_t)) { + proposal->rtstatic_len = 1 + sizeof(in_addr_t); proposal->rtstatic[0] = 0; memcpy(&proposal->rtstatic[1], opt->data, - sizeof(struct in_addr)); + sizeof(in_addr_t)); proposal->addrs |= RTA_STATIC; } } @@ -1872,12 +1872,12 @@ lease_as_proposal(struct client_lease *lease) if (lease->options[DHO_DOMAIN_NAME_SERVERS].len != 0) { int servers; opt = &lease->options[DHO_DOMAIN_NAME_SERVERS]; - servers = opt->len / sizeof(struct in_addr); + servers = opt->len / sizeof(in_addr_t); if (servers > MAXNS) servers = MAXNS; if (servers > 0) { proposal->addrs |= RTA_DNS; - proposal->rtdns_len = servers * sizeof(struct in_addr); + proposal->rtdns_len = servers * sizeof(in_addr_t); memcpy(proposal->rtdns, opt->data, proposal->rtdns_len); } } @@ -2113,7 +2113,7 @@ fork_privchld(struct interface_info *ifi, int fd, int fd2) close(fd2); - if ((priv_ibuf = malloc(sizeof(struct imsgbuf))) == NULL) + if ((priv_ibuf = malloc(sizeof(*priv_ibuf))) == NULL) fatalx("no memory for priv_ibuf"); imsg_init(priv_ibuf, fd); @@ -2197,9 +2197,8 @@ get_ifname(struct interface_info *ifi, int ioctlfd, char *arg) fatal("ioctl SIOCGIFGMEMB"); arg = NULL; - for (ifg = ifgr.ifgr_groups; - ifg && len >= sizeof(struct ifg_req); ifg++) { - len -= sizeof(struct ifg_req); + for (ifg = ifgr.ifgr_groups; ifg && len >= sizeof(*ifg); ifg++) { + len -= sizeof(*ifg); if (arg != NULL) fatalx("too many interfaces in group egress"); arg = ifg->ifgrq_member; @@ -2348,7 +2347,7 @@ clone_lease(struct client_lease *oldlease) struct client_lease *newlease; int i; - newlease = calloc(1, sizeof(struct client_lease)); + newlease = calloc(1, sizeof(*newlease)); if (newlease == NULL) goto cleanup; diff --git a/sbin/dhclient/kroute.c b/sbin/dhclient/kroute.c index 851bce83b1f..6db356bf9ef 100644 --- a/sbin/dhclient/kroute.c +++ b/sbin/dhclient/kroute.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kroute.c,v 1.137 2017/08/12 16:57:38 krw Exp $ */ +/* $OpenBSD: kroute.c,v 1.138 2017/08/14 22:12:59 krw Exp $ */ /* * Copyright 2012 Kenneth R Westerback @@ -179,7 +179,7 @@ set_routes(struct in_addr addr, struct in_addr addrmask, uint8_t *rtstatic, bits = rtstatic[i++]; bytes = (bits + 7) / 8; - if (bytes > sizeof(struct in_addr)) + if (bytes > sizeof(netmask.s_addr)) return; else if (i + bytes > rtstatic_len) return; @@ -195,8 +195,8 @@ set_routes(struct in_addr addr, struct in_addr addrmask, uint8_t *rtstatic, if (i + sizeof(gateway) > rtstatic_len) return; - memcpy(&gateway, &rtstatic[i], sizeof(gateway)); - i += sizeof(gateway); + memcpy(&gateway.s_addr, &rtstatic[i], sizeof(gateway.s_addr)); + i += sizeof(gateway.s_addr); if (gateway.s_addr == INADDR_ANY) { /* @@ -681,7 +681,7 @@ set_resolv_conf(char *name, uint8_t *rtsearch, unsigned int rtsearch_len, if (rtdns_len != 0) { addr = (struct in_addr *)rtdns; - servers = rtdns_len / sizeof(struct in_addr); + servers = rtdns_len / sizeof(addr->s_addr); if (servers > MAXNS) servers = MAXNS; for (i = 0; i < servers; i++) { -- cgit v1.2.3