On Fri, Jan 09, 2015 at 05:45:17PM -0500, Ted Unangst wrote:
> On Fri, Jan 09, 2015 at 15:45, Brent Cook wrote:
> > From: Brent Cook <[email protected]>
> >
> > Yeah yeah, a pointer is a pointer (except when it isn't :). I think this
> > looks nicer, since idx2peer is really the thing we're allocating to.
>
> what about the bzero ten lines later?
>
> I think the sizeof(*idx2peer) idiom is also a little nicer. and you
> can change the other reallocarray too.
>
Good point, might as well fix them all.
This updates all of the applicable sizeof(struct blah) references to use
sizeof(thing). No binary change on 32 or 64-bit.
Index: client.c
===================================================================
RCS file: /cvs/src/usr.sbin/ntpd/client.c,v
retrieving revision 1.97
diff -u -p -u -p -r1.97 client.c
--- client.c 9 Jan 2015 23:44:07 -0000 1.97
+++ client.c 12 Jan 2015 14:56:01 -0000
@@ -49,7 +49,7 @@ set_deadline(struct ntp_peer *p, time_t
int
client_peer_init(struct ntp_peer *p)
{
- if ((p->query = calloc(1, sizeof(struct ntp_query))) == NULL)
+ if ((p->query = calloc(1, sizeof(*(p->query)))) == NULL)
fatal("client_peer_init calloc");
p->query->fd = -1;
p->query->msg.status = MODE_CLIENT | (NTP_VERSION << 3);
Index: config.c
===================================================================
RCS file: /cvs/src/usr.sbin/ntpd/config.c,v
retrieving revision 1.22
diff -u -p -u -p -r1.22 config.c
--- config.c 10 Jan 2015 13:47:05 -0000 1.22
+++ config.c 12 Jan 2015 14:56:01 -0000
@@ -42,7 +42,7 @@ host(const char *s, struct ntp_addr **hn
struct ntp_addr *h = NULL;
if (!strcmp(s, "*"))
- if ((h = calloc(1, sizeof(struct ntp_addr))) == NULL)
+ if ((h = calloc(1, sizeof(*h))) == NULL)
fatal(NULL);
/* IPv4 address? */
@@ -66,14 +66,14 @@ host_v4(const char *s)
struct sockaddr_in *sa_in;
struct ntp_addr *h;
- bzero(&ina, sizeof(struct in_addr));
+ bzero(&ina, sizeof(ina));
if (inet_pton(AF_INET, s, &ina) != 1)
return (NULL);
- if ((h = calloc(1, sizeof(struct ntp_addr))) == NULL)
+ if ((h = calloc(1, sizeof(*h))) == NULL)
fatal(NULL);
sa_in = (struct sockaddr_in *)&h->ss;
- sa_in->sin_len = sizeof(struct sockaddr_in);
+ sa_in->sin_len = sizeof(*sa_in);
sa_in->sin_family = AF_INET;
sa_in->sin_addr.s_addr = ina.s_addr;
@@ -92,10 +92,10 @@ host_v6(const char *s)
hints.ai_socktype = SOCK_DGRAM; /*dummy*/
hints.ai_flags = AI_NUMERICHOST;
if (getaddrinfo(s, "0", &hints, &res) == 0) {
- if ((h = calloc(1, sizeof(struct ntp_addr))) == NULL)
+ if ((h = calloc(1, sizeof(*h))) == NULL)
fatal(NULL);
sa_in6 = (struct sockaddr_in6 *)&h->ss;
- sa_in6->sin6_len = sizeof(struct sockaddr_in6);
+ sa_in6->sin6_len = sizeof(*sa_in6);
sa_in6->sin6_family = AF_INET6;
memcpy(&sa_in6->sin6_addr,
&((struct sockaddr_in6 *)res->ai_addr)->sin6_addr,
@@ -134,17 +134,17 @@ host_dns(const char *s, struct ntp_addr
if (res->ai_family != AF_INET &&
res->ai_family != AF_INET6)
continue;
- if ((h = calloc(1, sizeof(struct ntp_addr))) == NULL)
+ if ((h = calloc(1, sizeof(*h))) == NULL)
fatal(NULL);
h->ss.ss_family = res->ai_family;
if (res->ai_family == AF_INET) {
sa_in = (struct sockaddr_in *)&h->ss;
- sa_in->sin_len = sizeof(struct sockaddr_in);
+ sa_in->sin_len = sizeof(*sa_in);
sa_in->sin_addr.s_addr = ((struct sockaddr_in *)
res->ai_addr)->sin_addr.s_addr;
} else {
sa_in6 = (struct sockaddr_in6 *)&h->ss;
- sa_in6->sin6_len = sizeof(struct sockaddr_in6);
+ sa_in6->sin6_len = sizeof(*sa_in6);
memcpy(&sa_in6->sin6_addr, &((struct sockaddr_in6 *)
res->ai_addr)->sin6_addr, sizeof(struct in6_addr));
}
@@ -164,7 +164,7 @@ new_peer(void)
{
struct ntp_peer *p;
- if ((p = calloc(1, sizeof(struct ntp_peer))) == NULL)
+ if ((p = calloc(1, sizeof(*p))) == NULL)
fatal("new_peer calloc");
p->id = ++maxid;
@@ -176,7 +176,7 @@ new_sensor(char *device)
{
struct ntp_conf_sensor *s;
- if ((s = calloc(1, sizeof(struct ntp_conf_sensor))) == NULL)
+ if ((s = calloc(1, sizeof(*s))) == NULL)
fatal("new_sensor calloc");
if ((s->device = strdup(device)) == NULL)
fatal("new_sensor strdup");
Index: control.c
===================================================================
RCS file: /cvs/src/usr.sbin/ntpd/control.c,v
retrieving revision 1.4
diff -u -p -u -p -r1.4 control.c
--- control.c 9 Jan 2015 07:35:37 -0000 1.4
+++ control.c 12 Jan 2015 14:56:01 -0000
@@ -121,7 +121,7 @@ control_accept(int listenfd)
session_socket_blockmode(connfd, BM_NONBLOCK);
- if ((ctl_conn = calloc(1, sizeof(struct ctl_conn))) == NULL) {
+ if ((ctl_conn = calloc(1, sizeof(*ctl_conn))) == NULL) {
log_warn("control_accept");
close(connfd);
return (0);
Index: ntp.c
===================================================================
RCS file: /cvs/src/usr.sbin/ntpd/ntp.c,v
retrieving revision 1.125
diff -u -p -u -p -r1.125 ntp.c
--- ntp.c 9 Jan 2015 07:35:37 -0000 1.125
+++ ntp.c 12 Jan 2015 14:56:01 -0000
@@ -156,10 +156,10 @@ ntp_main(int pipe_prnt[2], int fd_ctl, s
signal(SIGHUP, SIG_IGN);
signal(SIGCHLD, SIG_DFL);
- if ((ibuf_main = malloc(sizeof(struct imsgbuf))) == NULL)
+ if ((ibuf_main = malloc(sizeof(*ibuf_main))) == NULL)
fatal(NULL);
imsg_init(ibuf_main, pipe_prnt[1]);
- if ((ibuf_dns = malloc(sizeof(struct imsgbuf))) == NULL)
+ if ((ibuf_dns = malloc(sizeof(*ibuf_dns))) == NULL)
fatal(NULL);
imsg_init(ibuf_dns, pipe_dns[0]);
@@ -200,7 +200,7 @@ ntp_main(int pipe_prnt[2], int fd_ctl, s
while (ntp_quit == 0) {
if (peer_cnt > idx2peer_elms) {
if ((newp = reallocarray(idx2peer, peer_cnt,
- sizeof(void *))) == NULL) {
+ sizeof(*idx2peer))) == NULL) {
/* panic for now */
log_warn("could not resize idx2peer from %u -> "
"%u entries", idx2peer_elms, peer_cnt);
@@ -213,7 +213,7 @@ ntp_main(int pipe_prnt[2], int fd_ctl, s
new_cnt = PFD_MAX + peer_cnt + listener_cnt + ctl_cnt;
if (new_cnt > pfd_elms) {
if ((newp = reallocarray(pfd, new_cnt,
- sizeof(struct pollfd))) == NULL) {
+ sizeof(*pfd))) == NULL) {
/* panic for now */
log_warn("could not resize pfd from %u -> "
"%u entries", pfd_elms, new_cnt);
@@ -223,8 +223,8 @@ ntp_main(int pipe_prnt[2], int fd_ctl, s
pfd_elms = new_cnt;
}
- bzero(pfd, sizeof(struct pollfd) * pfd_elms);
- bzero(idx2peer, sizeof(void *) * idx2peer_elms);
+ bzero(pfd, sizeof(*pfd) * pfd_elms);
+ bzero(idx2peer, sizeof(*idx2peer) * idx2peer_elms);
nextaction = getmonotime() + 3600;
pfd[PFD_PIPE_MAIN].fd = ibuf_main->fd;
pfd[PFD_PIPE_MAIN].events = POLLIN;
@@ -497,7 +497,7 @@ ntp_dispatch_imsg_dns(void)
p = (u_char *)imsg.data;
while (dlen >= sizeof(struct sockaddr_storage)) {
- if ((h = calloc(1, sizeof(struct ntp_addr))) ==
+ if ((h = calloc(1, sizeof(*h))) ==
NULL)
fatal(NULL);
memcpy(&h->ss, p, sizeof(h->ss));
@@ -627,7 +627,7 @@ priv_adjtime(void)
if (offset_cnt == 0)
return (1);
- if ((offsets = calloc(offset_cnt, sizeof(struct ntp_offset *))) == NULL)
+ if ((offsets = calloc(offset_cnt, sizeof(*offsets))) == NULL)
fatal("calloc priv_adjtime");
TAILQ_FOREACH(p, &conf->ntp_peers, entry) {
@@ -644,7 +644,7 @@ priv_adjtime(void)
offsets[i++] = &s->update;
}
- qsort(offsets, offset_cnt, sizeof(struct ntp_offset *), offset_compare);
+ qsort(offsets, offset_cnt, sizeof(*offsets), offset_compare);
i = offset_cnt / 2;
if (offset_cnt % 2 == 0)
Index: ntp_dns.c
===================================================================
RCS file: /cvs/src/usr.sbin/ntpd/ntp_dns.c,v
retrieving revision 1.6
diff -u -p -u -p -r1.6 ntp_dns.c
--- ntp_dns.c 9 Jan 2015 07:35:37 -0000 1.6
+++ ntp_dns.c 12 Jan 2015 14:56:01 -0000
@@ -86,7 +86,7 @@ ntp_dns(int pipe_ntp[2], struct ntpd_con
signal(SIGINT, sighdlr_dns);
signal(SIGHUP, sighdlr_dns);
- if ((ibuf_dns = malloc(sizeof(struct imsgbuf))) == NULL)
+ if ((ibuf_dns = malloc(sizeof(*ibuf_dns))) == NULL)
fatal(NULL);
imsg_init(ibuf_dns, pipe_ntp[1]);
Index: ntpd.c
===================================================================
RCS file: /cvs/src/usr.sbin/ntpd/ntpd.c,v
retrieving revision 1.83
diff -u -p -u -p -r1.83 ntpd.c
--- ntpd.c 9 Jan 2015 07:35:37 -0000 1.83
+++ ntpd.c 12 Jan 2015 14:56:01 -0000
@@ -201,7 +201,7 @@ main(int argc, char *argv[])
close(pipe_chld[1]);
- if ((ibuf = malloc(sizeof(struct imsgbuf))) == NULL)
+ if ((ibuf = malloc(sizeof(*ibuf))) == NULL)
fatal(NULL);
imsg_init(ibuf, pipe_chld[0]);
@@ -588,7 +588,7 @@ ctl_main(int argc, char *argv[])
if (connect(fd, (struct sockaddr *)&sa, sizeof(sa)) == -1)
err(1, "connect: %s", sockname);
- if ((ibuf_ctl = malloc(sizeof(struct imsgbuf))) == NULL)
+ if ((ibuf_ctl = malloc(sizeof(*ibuf_ctl))) == NULL)
err(1, NULL);
imsg_init(ibuf_ctl, fd);
Index: parse.y
===================================================================
RCS file: /cvs/src/usr.sbin/ntpd/parse.y,v
retrieving revision 1.57
diff -u -p -u -p -r1.57 parse.y
--- parse.y 10 Jan 2015 13:47:05 -0000 1.57
+++ parse.y 12 Jan 2015 14:56:01 -0000
@@ -118,13 +118,12 @@ main : LISTEN ON address listen_opts {
for (; h != NULL; h = next) {
next = h->next;
- la = calloc(1, sizeof(struct listen_addr));
+ la = calloc(1, sizeof(*la));
if (la == NULL)
fatal("listen on calloc");
la->fd = -1;
la->rtable = $4.rtable;
- memcpy(&la->sa, &h->ss,
- sizeof(struct sockaddr_storage));
+ memcpy(&la->sa, &h->ss, sizeof(la->sa));
TAILQ_INSERT_TAIL(&conf->listen_addrs, la,
entry);
free(h);
@@ -601,7 +600,7 @@ pushfile(const char *name)
{
struct file *nfile;
- if ((nfile = calloc(1, sizeof(struct file))) == NULL) {
+ if ((nfile = calloc(1, sizeof(*nfile))) == NULL) {
log_warn("malloc");
return (NULL);
}
Index: sensors.c
===================================================================
RCS file: /cvs/src/usr.sbin/ntpd/sensors.c,v
retrieving revision 1.49
diff -u -p -u -p -r1.49 sensors.c
--- sensors.c 9 Jan 2015 07:35:37 -0000 1.49
+++ sensors.c 12 Jan 2015 14:56:01 -0000
@@ -229,14 +229,14 @@ sensor_update(struct ntp_sensor *s)
struct ntp_offset **offsets;
int i;
- if ((offsets = calloc(SENSOR_OFFSETS, sizeof(struct ntp_offset *))) ==
+ if ((offsets = calloc(SENSOR_OFFSETS, sizeof(*offsets))) ==
NULL)
fatal("calloc sensor_update");
for (i = 0; i < SENSOR_OFFSETS; i++)
offsets[i] = &s->offsets[i];
- qsort(offsets, SENSOR_OFFSETS, sizeof(struct ntp_offset *),
+ qsort(offsets, SENSOR_OFFSETS, sizeof(*offsets),
offset_compare);
i = SENSOR_OFFSETS / 2;