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>
This commit is contained in:
NIIBE Yutaka 2019-02-26 10:34:03 +09:00
parent 455ef62d29
commit 72efb78402
2 changed files with 18 additions and 12 deletions

View File

@ -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;

View File

@ -412,9 +412,6 @@ struct dns_packet {
#define dns_p_sizeof(P) dns_p_calcsize((P)->end)
/** takes size of maximum desired payload */
#define dns_p_new(n) (dns_p_init((struct dns_packet *)&(union { unsigned char b[dns_p_calcsize((n))]; struct dns_packet p; }){ { 0 } }, dns_p_calcsize((n))))
/** takes size of entire packet structure as allocated */
DNS_PUBLIC struct dns_packet *dns_p_init(struct dns_packet *, size_t);