From bc8dbfc9fdd9081c26959061c238d4c4a76b7d41 Mon Sep 17 00:00:00 2001 From: thorkill Date: Mon, 29 Jun 2015 23:30:18 +0200 Subject: [PATCH] Proper struct initialization Detected by clang -Wmissing-field-initializers --- src/linux/device.c | 3 +- src/net.c | 16 +++++++--- src/net_setup.c | 6 +++- src/netutl.c | 15 +++++++-- src/node.c | 4 ++- src/protocol.c | 5 ++- src/protocol_edge.c | 6 +++- src/protocol_subnet.c | 11 +++++-- src/route.c | 13 ++++++-- src/splay_tree.c | 9 ++++-- src/sptps_speed.c | 2 +- src/tincctl.c | 74 +++++++++++++++++++++---------------------- 12 files changed, 105 insertions(+), 59 deletions(-) diff --git a/src/linux/device.c b/src/linux/device.c index a06e6daf..6504f47b 100644 --- a/src/linux/device.c +++ b/src/linux/device.c @@ -65,7 +65,8 @@ static bool setup_device(void) { fcntl(device_fd, F_SETFD, FD_CLOEXEC); #endif - struct ifreq ifr = {{{0}}}; + struct ifreq ifr; + memset(&ifr, 0x0, sizeof(struct ifreq)); get_config_string(lookup_config(config_tree, "DeviceType"), &type); diff --git a/src/net.c b/src/net.c index 55f63cd3..cc01c75b 100644 --- a/src/net.c +++ b/src/net.c @@ -447,11 +447,17 @@ int main_loop(void) { timeout_add(&periodictimer, periodic_handler, &periodictimer, &(struct timeval){pingtimeout, rand() % 100000}); #ifndef HAVE_MINGW - signal_t sighup = {0}; - signal_t sigterm = {0}; - signal_t sigquit = {0}; - signal_t sigint = {0}; - signal_t sigalrm = {0}; + signal_t sighup; + signal_t sigterm; + signal_t sigquit; + signal_t sigint; + signal_t sigalrm; + + memset(&sighup, 0x0, sizeof(signal_t)); + memset(&sigterm, 0x0, sizeof(signal_t)); + memset(&sigquit, 0x0, sizeof(signal_t)); + memset(&sigint, 0x0, sizeof(signal_t)); + memset(&sigalrm, 0x0, sizeof(signal_t)); signal_add(&sighup, sighup_handler, &sighup, SIGHUP); signal_add(&sigterm, sigterm_handler, &sigterm, SIGTERM); diff --git a/src/net_setup.c b/src/net_setup.c index a389b4a6..ad3c9d0f 100644 --- a/src/net_setup.c +++ b/src/net_setup.c @@ -687,7 +687,11 @@ static bool add_listen_address(char *address, bool bindto) { *address = 0; } - struct addrinfo *ai, hint = {0}; + struct addrinfo *ai, hint; + ai = NULL; + + memset(&hint, 0x0, sizeof(struct addrinfo)); + hint.ai_family = addressfamily; hint.ai_socktype = SOCK_STREAM; hint.ai_protocol = IPPROTO_TCP; diff --git a/src/netutl.c b/src/netutl.c index 2eebb644..e06bc409 100644 --- a/src/netutl.c +++ b/src/netutl.c @@ -33,9 +33,13 @@ bool hostnames = false; Return NULL on failure. */ struct addrinfo *str2addrinfo(const char *address, const char *service, int socktype) { - struct addrinfo *ai, hint = {0}; + struct addrinfo *ai, hint; int err; + ai = NULL; + + memset(&hint, 0x0, sizeof(struct addrinfo)); + hint.ai_family = addressfamily; hint.ai_socktype = socktype; @@ -53,10 +57,15 @@ struct addrinfo *str2addrinfo(const char *address, const char *service, int sock } sockaddr_t str2sockaddr(const char *address, const char *port) { - struct addrinfo *ai, hint = {0}; - sockaddr_t result = {{0}}; + struct addrinfo *ai, hint; + sockaddr_t result; int err; + ai = NULL; + + memset(&hint, 0x0, sizeof(struct addrinfo)); + memset(&result, 0x0, sizeof(sockaddr_t)); + hint.ai_family = AF_UNSPEC; hint.ai_flags = AI_NUMERICHOST; hint.ai_socktype = SOCK_STREAM; diff --git a/src/node.c b/src/node.c index fb4b7eb4..f055753b 100644 --- a/src/node.c +++ b/src/node.c @@ -130,7 +130,9 @@ void node_del(node_t *n) { } node_t *lookup_node(char *name) { - node_t n = {NULL}; + node_t n; + + memset(&n, 0x0, sizeof(node_t)); n.name = name; diff --git a/src/protocol.c b/src/protocol.c index f533a932..497c6d8d 100644 --- a/src/protocol.c +++ b/src/protocol.c @@ -179,7 +179,10 @@ static void age_past_requests(void *data) { } bool seen_request(const char *request) { - past_request_t *new, p = {NULL}; + past_request_t *new, p; + new = NULL; + + memset(&p, 0x0, sizeof(past_request_t)); p.request = request; diff --git a/src/protocol_edge.c b/src/protocol_edge.c index d9475c3d..ff73cc40 100644 --- a/src/protocol_edge.c +++ b/src/protocol_edge.c @@ -70,12 +70,16 @@ bool add_edge_h(connection_t *c, const char *request) { char to_port[MAX_STRING_SIZE]; char address_local[MAX_STRING_SIZE]; char port_local[MAX_STRING_SIZE]; - sockaddr_t address, local_address = {{0}}; + sockaddr_t address, local_address; uint32_t options; int weight; + memset(&address, 0x0, sizeof(sockaddr_t)); + memset(&local_address, 0x0, sizeof(sockaddr_t)); + int parameter_count = sscanf(request, "%*d %*x "MAX_STRING" "MAX_STRING" "MAX_STRING" "MAX_STRING" %x %d "MAX_STRING" "MAX_STRING, from_name, to_name, to_address, to_port, &options, &weight, address_local, port_local); + if (parameter_count != 6 && parameter_count != 8) { logger(DEBUG_ALWAYS, LOG_ERR, "Got bad %s from %s (%s)", "ADD_EDGE", c->name, c->hostname); diff --git a/src/protocol_subnet.c b/src/protocol_subnet.c index 06dafbc7..d69386e8 100644 --- a/src/protocol_subnet.c +++ b/src/protocol_subnet.c @@ -45,7 +45,11 @@ bool add_subnet_h(connection_t *c, const char *request) { char subnetstr[MAX_STRING_SIZE]; char name[MAX_STRING_SIZE]; node_t *owner; - subnet_t s = {NULL}, *new, *old; + subnet_t s, *new, *old; + new = NULL; + old = NULL; + + memset(&s, 0x0, sizeof(subnet_t)); if(sscanf(request, "%*d %*x " MAX_STRING " " MAX_STRING, name, subnetstr) != 2) { logger(DEBUG_ALWAYS, LOG_ERR, "Got bad %s from %s (%s)", "ADD_SUBNET", c->name, @@ -155,7 +159,10 @@ bool del_subnet_h(connection_t *c, const char *request) { char subnetstr[MAX_STRING_SIZE]; char name[MAX_STRING_SIZE]; node_t *owner; - subnet_t s = {NULL}, *find; + subnet_t s, *find; + find = NULL; + + memset(&s, 0x0, sizeof(subnet_t)); if(sscanf(request, "%*d %*x " MAX_STRING " " MAX_STRING, name, subnetstr) != 2) { logger(DEBUG_ALWAYS, LOG_ERR, "Got bad %s from %s (%s)", "DEL_SUBNET", c->name, diff --git a/src/route.c b/src/route.c index 27851469..3a3dbc8f 100644 --- a/src/route.c +++ b/src/route.c @@ -251,13 +251,17 @@ static void learn_mac(mac_t *address) { /* RFC 792 */ static void route_ipv4_unreachable(node_t *source, vpn_packet_t *packet, length_t ether_size, uint8_t type, uint8_t code) { - struct ip ip = {0}; - struct icmp icmp = {0}; + struct ip ip; + struct icmp icmp; struct in_addr ip_src; struct in_addr ip_dst; uint32_t oldlen; + + memset(&ip, 0x0, sizeof(struct ip)); + memset(&icmp, 0x0, sizeof(struct icmp)); + if(ratelimit(3)) return; @@ -445,9 +449,12 @@ static void route_ipv4(node_t *source, vpn_packet_t *packet) { static void route_ipv6_unreachable(node_t *source, vpn_packet_t *packet, length_t ether_size, uint8_t type, uint8_t code) { struct ip6_hdr ip6; - struct icmp6_hdr icmp6 = {0}; + struct icmp6_hdr icmp6; uint16_t checksum; + memset(&ip6, 0x0, sizeof(struct ip6_hdr)); + memset(&icmp6, 0x0, sizeof(struct icmp6_hdr)); + struct { struct in6_addr ip6_src; /* source address */ struct in6_addr ip6_dst; /* destination address */ diff --git a/src/splay_tree.c b/src/splay_tree.c index bd0f06b6..e86ddd50 100644 --- a/src/splay_tree.c +++ b/src/splay_tree.c @@ -25,10 +25,13 @@ /* Splay operation */ static splay_node_t *splay_top_down(splay_tree_t *tree, const void *data, int *result) { - splay_node_t left = {NULL}, right = {NULL}; - splay_node_t *leftbottom = &left, *rightbottom = &right, *child, *grandchild; + splay_node_t left, right; + splay_node_t *leftbottom = &left, *rightbottom = &right, *child = NULL, *grandchild = NULL; splay_node_t *root = tree->root; - int c; + int c = -1; + + memset(&left, 0x0, sizeof(splay_node_t)); + memset(&right, 0x0, sizeof(splay_node_t)); if(!root) { if(result) diff --git a/src/sptps_speed.c b/src/sptps_speed.c index bde3d697..00f005ec 100644 --- a/src/sptps_speed.c +++ b/src/sptps_speed.c @@ -139,7 +139,7 @@ int main(int argc, char *argv[]) { return 1; } - struct pollfd pfd[2] = {{fd[0], POLLIN}, {fd[1], POLLIN}}; + struct pollfd pfd[2] = {{fd[0], POLLIN, NULL}, {fd[1], POLLIN, NULL}}; fprintf(stderr, "SPTPS/TCP authenticate for %lg seconds: ", duration); for(clock_start(); clock_countto(duration);) { diff --git a/src/tincctl.c b/src/tincctl.c index be42012e..b2714636 100644 --- a/src/tincctl.c +++ b/src/tincctl.c @@ -2326,46 +2326,46 @@ static const struct { int (*function)(int argc, char *argv[]); bool hidden; } commands[] = { - {"start", cmd_start}, - {"stop", cmd_stop}, - {"restart", cmd_restart}, - {"reload", cmd_reload}, - {"dump", cmd_dump}, - {"list", cmd_dump}, - {"purge", cmd_purge}, - {"debug", cmd_debug}, - {"retry", cmd_retry}, - {"connect", cmd_connect}, - {"disconnect", cmd_disconnect}, - {"top", cmd_top}, - {"pcap", cmd_pcap}, - {"log", cmd_log}, - {"pid", cmd_pid}, + {"start", cmd_start, false}, + {"stop", cmd_stop, false}, + {"restart", cmd_restart, false}, + {"reload", cmd_reload, false}, + {"dump", cmd_dump, false}, + {"list", cmd_dump, false}, + {"purge", cmd_purge, false}, + {"debug", cmd_debug, false}, + {"retry", cmd_retry, false}, + {"connect", cmd_connect, false}, + {"disconnect", cmd_disconnect, false}, + {"top", cmd_top, false}, + {"pcap", cmd_pcap, false}, + {"log", cmd_log, false}, + {"pid", cmd_pid, false}, {"config", cmd_config, true}, - {"add", cmd_config}, - {"del", cmd_config}, - {"get", cmd_config}, - {"set", cmd_config}, - {"init", cmd_init}, - {"generate-keys", cmd_generate_keys}, + {"add", cmd_config, false}, + {"del", cmd_config, false}, + {"get", cmd_config, false}, + {"set", cmd_config, false}, + {"init", cmd_init, false}, + {"generate-keys", cmd_generate_keys, false}, #ifndef DISABLE_LEGACY - {"generate-rsa-keys", cmd_generate_rsa_keys}, + {"generate-rsa-keys", cmd_generate_rsa_keys, false}, #endif - {"generate-ed25519-keys", cmd_generate_ed25519_keys}, - {"help", cmd_help}, - {"version", cmd_version}, - {"info", cmd_info}, - {"edit", cmd_edit}, - {"export", cmd_export}, - {"export-all", cmd_export_all}, - {"import", cmd_import}, - {"exchange", cmd_exchange}, - {"exchange-all", cmd_exchange_all}, - {"invite", cmd_invite}, - {"join", cmd_join}, - {"network", cmd_network}, - {"fsck", cmd_fsck}, - {NULL, NULL}, + {"generate-ed25519-keys", cmd_generate_ed25519_keys, false}, + {"help", cmd_help, false}, + {"version", cmd_version, false}, + {"info", cmd_info, false}, + {"edit", cmd_edit, false}, + {"export", cmd_export, false}, + {"export-all", cmd_export_all, false}, + {"import", cmd_import, false}, + {"exchange", cmd_exchange, false}, + {"exchange-all", cmd_exchange_all, false}, + {"invite", cmd_invite, false}, + {"join", cmd_join, false}, + {"network", cmd_network, false}, + {"fsck", cmd_fsck, false}, + {NULL, NULL, NULL}, }; #ifdef HAVE_READLINE