diff --git a/src/linux/device.c b/src/linux/device.c index 6504f47b..a06e6daf 100644 --- a/src/linux/device.c +++ b/src/linux/device.c @@ -65,8 +65,7 @@ static bool setup_device(void) { fcntl(device_fd, F_SETFD, FD_CLOEXEC); #endif - struct ifreq ifr; - memset(&ifr, 0x0, sizeof(struct ifreq)); + struct ifreq ifr = {{{0}}}; get_config_string(lookup_config(config_tree, "DeviceType"), &type); diff --git a/src/net.c b/src/net.c index cc01c75b..55f63cd3 100644 --- a/src/net.c +++ b/src/net.c @@ -447,17 +447,11 @@ int main_loop(void) { timeout_add(&periodictimer, periodic_handler, &periodictimer, &(struct timeval){pingtimeout, rand() % 100000}); #ifndef HAVE_MINGW - 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_t sighup = {0}; + signal_t sigterm = {0}; + signal_t sigquit = {0}; + signal_t sigint = {0}; + signal_t sigalrm = {0}; 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 ad3c9d0f..a389b4a6 100644 --- a/src/net_setup.c +++ b/src/net_setup.c @@ -687,11 +687,7 @@ static bool add_listen_address(char *address, bool bindto) { *address = 0; } - struct addrinfo *ai, hint; - ai = NULL; - - memset(&hint, 0x0, sizeof(struct addrinfo)); - + struct addrinfo *ai, hint = {0}; 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 e06bc409..2eebb644 100644 --- a/src/netutl.c +++ b/src/netutl.c @@ -33,13 +33,9 @@ bool hostnames = false; Return NULL on failure. */ struct addrinfo *str2addrinfo(const char *address, const char *service, int socktype) { - struct addrinfo *ai, hint; + struct addrinfo *ai, hint = {0}; int err; - ai = NULL; - - memset(&hint, 0x0, sizeof(struct addrinfo)); - hint.ai_family = addressfamily; hint.ai_socktype = socktype; @@ -57,15 +53,10 @@ struct addrinfo *str2addrinfo(const char *address, const char *service, int sock } sockaddr_t str2sockaddr(const char *address, const char *port) { - struct addrinfo *ai, hint; - sockaddr_t result; + struct addrinfo *ai, hint = {0}; + sockaddr_t result = {{0}}; 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 f055753b..fb4b7eb4 100644 --- a/src/node.c +++ b/src/node.c @@ -130,9 +130,7 @@ void node_del(node_t *n) { } node_t *lookup_node(char *name) { - node_t n; - - memset(&n, 0x0, sizeof(node_t)); + node_t n = {NULL}; n.name = name; diff --git a/src/protocol.c b/src/protocol.c index 497c6d8d..f533a932 100644 --- a/src/protocol.c +++ b/src/protocol.c @@ -179,10 +179,7 @@ static void age_past_requests(void *data) { } bool seen_request(const char *request) { - past_request_t *new, p; - new = NULL; - - memset(&p, 0x0, sizeof(past_request_t)); + past_request_t *new, p = {NULL}; p.request = request; diff --git a/src/protocol_edge.c b/src/protocol_edge.c index ff73cc40..d9475c3d 100644 --- a/src/protocol_edge.c +++ b/src/protocol_edge.c @@ -70,16 +70,12 @@ 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; + sockaddr_t address, local_address = {{0}}; 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 d69386e8..06dafbc7 100644 --- a/src/protocol_subnet.c +++ b/src/protocol_subnet.c @@ -45,11 +45,7 @@ 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, *new, *old; - new = NULL; - old = NULL; - - memset(&s, 0x0, sizeof(subnet_t)); + subnet_t s = {NULL}, *new, *old; 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, @@ -159,10 +155,7 @@ 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, *find; - find = NULL; - - memset(&s, 0x0, sizeof(subnet_t)); + subnet_t s = {NULL}, *find; 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 3a3dbc8f..27851469 100644 --- a/src/route.c +++ b/src/route.c @@ -251,17 +251,13 @@ 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; - struct icmp icmp; + struct ip ip = {0}; + struct icmp icmp = {0}; 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; @@ -449,12 +445,9 @@ 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; + struct icmp6_hdr icmp6 = {0}; 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 e86ddd50..bd0f06b6 100644 --- a/src/splay_tree.c +++ b/src/splay_tree.c @@ -25,13 +25,10 @@ /* Splay operation */ static splay_node_t *splay_top_down(splay_tree_t *tree, const void *data, int *result) { - splay_node_t left, right; - splay_node_t *leftbottom = &left, *rightbottom = &right, *child = NULL, *grandchild = NULL; + splay_node_t left = {NULL}, right = {NULL}; + splay_node_t *leftbottom = &left, *rightbottom = &right, *child, *grandchild; splay_node_t *root = tree->root; - int c = -1; - - memset(&left, 0x0, sizeof(splay_node_t)); - memset(&right, 0x0, sizeof(splay_node_t)); + int c; if(!root) { if(result) diff --git a/src/sptps_speed.c b/src/sptps_speed.c index 00f005ec..bde3d697 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, NULL}, {fd[1], POLLIN, NULL}}; + struct pollfd pfd[2] = {{fd[0], POLLIN}, {fd[1], POLLIN}}; 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 b2714636..be42012e 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, 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}, + {"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}, {"config", cmd_config, true}, - {"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}, + {"add", cmd_config}, + {"del", cmd_config}, + {"get", cmd_config}, + {"set", cmd_config}, + {"init", cmd_init}, + {"generate-keys", cmd_generate_keys}, #ifndef DISABLE_LEGACY - {"generate-rsa-keys", cmd_generate_rsa_keys, false}, + {"generate-rsa-keys", cmd_generate_rsa_keys}, #endif - {"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}, + {"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}, }; #ifdef HAVE_READLINE