diff options
author | NIIBE Yutaka <gniibe@fsij.org> | 2019-02-26 02:34:03 +0100 |
---|---|---|
committer | NIIBE Yutaka <gniibe@fsij.org> | 2019-02-26 02:34:03 +0100 |
commit | 72efb7840258808cd892b90d871ea1cc1c31d7f5 (patch) | |
tree | 79d0e99b53b3310459c0e3a9ec4f16c3c42a6bc2 /dirmngr/dns.c | |
parent | libdns: Avoid using compound literals (2). (diff) | |
download | gnupg2-72efb7840258808cd892b90d871ea1cc1c31d7f5.tar.xz gnupg2-72efb7840258808cd892b90d871ea1cc1c31d7f5.zip |
libdns: Avoid using compound literals (3).
* dirmngr/dns.h (dns_p_new): Remove.
* dirmngr/dns.c (dns_hosts_query): Use dns_p_init with automatic
variable.
(dns_hints_query, dns_res_glue, parse_packet, query_hosts)
(send_query, show_hints, echo_port): Likewise.
--
Implicit automatic allocation by compound literals is confusing
for C90 code.
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
Diffstat (limited to 'dirmngr/dns.c')
-rw-r--r-- | dirmngr/dns.c | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/dirmngr/dns.c b/dirmngr/dns.c index 92084d112..6acb4faa2 100644 --- a/dirmngr/dns.c +++ b/dirmngr/dns.c @@ -5278,7 +5278,8 @@ error: struct dns_packet *dns_hosts_query(struct dns_hosts *hosts, struct dns_packet *Q, int *error_) { - struct dns_packet *P = dns_p_new(512); + union { unsigned char b[dns_p_calcsize((512))]; struct dns_packet p; } _P = { 0 }; + struct dns_packet *P = dns_p_init(&_P.p, 512); struct dns_packet *A = 0; struct dns_rr rr; struct dns_hosts_entry *ent; @@ -6839,6 +6840,7 @@ unsigned dns_hints_grep(struct sockaddr **sa, socklen_t *sa_len, unsigned lim, s struct dns_packet *dns_hints_query(struct dns_hints *hints, struct dns_packet *Q, int *error_) { + union { unsigned char b[dns_p_calcsize((512))]; struct dns_packet p; } _P = { 0 }; struct dns_packet *A, *P; struct dns_rr rr; char zone[DNS_D_MAXNAME + 1]; @@ -6856,7 +6858,7 @@ struct dns_packet *dns_hints_query(struct dns_hints *hints, struct dns_packet *Q else if (zlen >= sizeof zone) goto toolong; - P = dns_p_new(512); + P = dns_p_init(&_P.p, 512); dns_header(P)->qr = 1; if ((error = dns_rr_copy(P, &rr, Q))) @@ -8461,7 +8463,8 @@ error: static struct dns_packet *dns_res_glue(struct dns_resolver *R, struct dns_packet *Q) { - struct dns_packet *P = dns_p_new(512); + union { unsigned char b[dns_p_calcsize((512))]; struct dns_packet p; } _P = { 0 }; + struct dns_packet *P = dns_p_init(&_P.p, 512); char qname[DNS_D_MAXNAME + 1]; size_t qlen; enum dns_type qtype; @@ -10586,8 +10589,10 @@ static void print_packet(struct dns_packet *P, FILE *fp) { static int parse_packet(int argc DNS_NOTUSED, char *argv[] DNS_NOTUSED) { - struct dns_packet *P = dns_p_new(512); - struct dns_packet *Q = dns_p_new(512); + union { unsigned char b[dns_p_calcsize((512))]; struct dns_packet p; } _P = { 0 }; + union { unsigned char b[dns_p_calcsize((512))]; struct dns_packet p; } _Q = { 0 }; + struct dns_packet *P = dns_p_init(&_P.p, 512); + struct dns_packet *Q = dns_p_init(&_Q.p, 512); enum dns_section section; struct dns_rr rr; int error; @@ -10787,7 +10792,8 @@ static int show_hosts(int argc DNS_NOTUSED, char *argv[] DNS_NOTUSED) { static int query_hosts(int argc, char *argv[]) { - struct dns_packet *Q = dns_p_new(512); + union { unsigned char b[dns_p_calcsize((512))]; struct dns_packet p; } _Q = { 0 }; + struct dns_packet *Q = dns_p_init(&_Q.p, 512); struct dns_packet *A; char qname[DNS_D_MAXNAME + 1]; size_t qlen; @@ -10905,7 +10911,8 @@ static int dump_random(int argc, char *argv[]) { static int send_query(int argc, char *argv[]) { - struct dns_packet *A, *Q = dns_p_new(512); + union { unsigned char b[dns_p_calcsize((512))]; struct dns_packet p; } _Q = { 0 }; + struct dns_packet *A, *Q = dns_p_init(&_Q.p, 512); char host[INET6_ADDRSTRLEN + 1]; struct sockaddr_storage ss; struct dns_socket *so; @@ -10999,9 +11006,10 @@ static int show_hints(int argc, char *argv[]) { if (0 == strcmp(how, "plain")) { dns_hints_dump(hints, stdout); } else { + union { unsigned char b[dns_p_calcsize((512))]; struct dns_packet p; } _P = { 0 }; struct dns_packet *query, *answer; - query = dns_p_new(512); + query = dns_p_init(&_P.p, 512); if ((error = dns_p_push(query, DNS_S_QUESTION, who, strlen(who), DNS_T_A, DNS_C_IN, 0, 0))) panic("%s: %s", who, dns_strerror(error)); @@ -11160,7 +11168,8 @@ static int echo_port(int argc DNS_NOTUSED, char *argv[] DNS_NOTUSED) { panic("127.0.0.1:5353: %s", dns_strerror(errno)); for (;;) { - struct dns_packet *pkt = dns_p_new(512); + union { unsigned char b[dns_p_calcsize((512))]; struct dns_packet p; } _P = { 0 }; + struct dns_packet *pkt = dns_p_init(&_P.p, 512); struct sockaddr_storage ss; socklen_t slen = sizeof ss; ssize_t count; |