From: Guus Sliepen Date: Sun, 23 Sep 2018 13:33:23 +0000 (+0200) Subject: Fix all warnings when compiling with -Wall -W -pedantic. X-Git-Tag: release-1.0.35~8 X-Git-Url: https://tinc-vpn.org/git/browse?a=commitdiff_plain;h=99763e34d52fcfe76b0bb9c7f3a17ace51cfdbfc;p=tinc Fix all warnings when compiling with -Wall -W -pedantic. --- diff --git a/src/conf.c b/src/conf.c index 4497b0e1..03887991 100644 --- a/src/conf.c +++ b/src/conf.c @@ -204,7 +204,7 @@ bool get_config_address(const config_t *cfg, struct addrinfo **result) { } bool get_config_subnet(const config_t *cfg, subnet_t **result) { - subnet_t subnet = {}; + subnet_t subnet = {0}; if(!cfg) { return false; @@ -432,7 +432,7 @@ bool read_server_config(void) { // And we try to read the ones that end with ".conf" if(l > 5 && !strcmp(".conf", & ep->d_name[ l - 5 ])) { - if(snprintf(fname, sizeof(fname), "%s/%s", dname, ep->d_name) >= sizeof(fname)) { + if((size_t)snprintf(fname, sizeof(fname), "%s/%s", dname, ep->d_name) >= sizeof(fname)) { logger(LOG_ERR, "Pathname too long: %s/%s", dname, ep->d_name); return false; } @@ -578,7 +578,7 @@ FILE *ask_and_open(const char *filename, const char *what) { /* The directory is a relative path or a filename. */ getcwd(directory, sizeof(directory)); - if(snprintf(abspath, sizeof(abspath), "%s/%s", directory, fn) >= sizeof(abspath)) { + if((size_t)snprintf(abspath, sizeof(abspath), "%s/%s", directory, fn) >= sizeof(abspath)) { fprintf(stderr, "Pathname too long: %s/%s\n", directory, fn); return NULL; } diff --git a/src/graph.c b/src/graph.c index 832e0175..3529d011 100644 --- a/src/graph.c +++ b/src/graph.c @@ -274,9 +274,9 @@ static void sssp_bfs(void) { n->mtuevent = NULL; } - xasprintf(&envp[0], "NETNAME=%s", netname ? : ""); - xasprintf(&envp[1], "DEVICE=%s", device ? : ""); - xasprintf(&envp[2], "INTERFACE=%s", iface ? : ""); + xasprintf(&envp[0], "NETNAME=%s", netname ? netname : ""); + xasprintf(&envp[1], "DEVICE=%s", device ? device : ""); + xasprintf(&envp[2], "INTERFACE=%s", iface ? iface : ""); xasprintf(&envp[3], "NODE=%s", n->name); sockaddr2str(&n->address, &address, &port); xasprintf(&envp[4], "REMOTEADDRESS=%s", address); diff --git a/src/net.c b/src/net.c index d20cbffb..37ae1166 100644 --- a/src/net.c +++ b/src/net.c @@ -191,7 +191,7 @@ void tarpit(int fd) { pits[next_pit++] = fd; - if(next_pit >= sizeof pits / sizeof pits[0]) { + if(next_pit >= (int)(sizeof pits / sizeof pits[0])) { next_pit = 0; } } diff --git a/src/net_setup.c b/src/net_setup.c index 5eddb1a7..8c43b396 100644 --- a/src/net_setup.c +++ b/src/net_setup.c @@ -388,8 +388,8 @@ static bool setup_myself(void) { char *address = NULL; char *proxy = NULL; char *space; - char *envp[5] = {}; - struct addrinfo *ai, *aip, hint = {}; + char *envp[5] = {0}; + struct addrinfo *ai, *aip, hint = {0}; bool choice; int i, err; int replaywin_int; @@ -852,9 +852,9 @@ static bool setup_myself(void) { } /* Run tinc-up script to further initialize the tap interface */ - xasprintf(&envp[0], "NETNAME=%s", netname ? : ""); - xasprintf(&envp[1], "DEVICE=%s", device ? : ""); - xasprintf(&envp[2], "INTERFACE=%s", iface ? : ""); + xasprintf(&envp[0], "NETNAME=%s", netname ? netname : ""); + xasprintf(&envp[1], "DEVICE=%s", device ? device : ""); + xasprintf(&envp[2], "INTERFACE=%s", iface ? iface : ""); xasprintf(&envp[3], "NAME=%s", myself->name); #ifdef HAVE_MINGW @@ -1068,7 +1068,7 @@ bool setup_network(void) { void close_network_connections(void) { avl_node_t *node, *next; connection_t *c; - char *envp[5] = {}; + char *envp[5] = {0}; int i; for(node = connection_tree->head; node; node = next) { @@ -1099,9 +1099,9 @@ void close_network_connections(void) { close(listen_socket[i].udp); } - xasprintf(&envp[0], "NETNAME=%s", netname ? : ""); - xasprintf(&envp[1], "DEVICE=%s", device ? : ""); - xasprintf(&envp[2], "INTERFACE=%s", iface ? : ""); + xasprintf(&envp[0], "NETNAME=%s", netname ? netname : ""); + xasprintf(&envp[1], "DEVICE=%s", device ? device : ""); + xasprintf(&envp[2], "INTERFACE=%s", iface ? iface : ""); xasprintf(&envp[3], "NAME=%s", myself->name); exit_requests(); diff --git a/src/netutl.c b/src/netutl.c index 3c2a77df..abe3d876 100644 --- a/src/netutl.c +++ b/src/netutl.c @@ -33,7 +33,7 @@ bool hostnames = false; Return NULL on failure. */ struct addrinfo *str2addrinfo(const char *address, const char *service, int socktype) { - struct addrinfo *ai = NULL, hint = {}; + struct addrinfo *ai = NULL, hint = {0}; int err; hint.ai_family = addressfamily; @@ -55,7 +55,7 @@ struct addrinfo *str2addrinfo(const char *address, const char *service, int sock } sockaddr_t str2sockaddr(const char *address, const char *port) { - struct addrinfo *ai = NULL, hint = {}; + struct addrinfo *ai = NULL, hint = {0}; sockaddr_t result; int err; diff --git a/src/node.c b/src/node.c index 12bc38f7..03be21cd 100644 --- a/src/node.c +++ b/src/node.c @@ -140,7 +140,7 @@ void node_del(node_t *n) { } node_t *lookup_node(char *name) { - node_t n = {}; + node_t n = {0}; n.name = name; @@ -148,7 +148,7 @@ node_t *lookup_node(char *name) { } node_t *lookup_node_udp(const sockaddr_t *sa) { - node_t n = {}; + node_t n = {0}; n.address = *sa; n.name = NULL; diff --git a/src/protocol.c b/src/protocol.c index d04f9ef6..4f74d3b0 100644 --- a/src/protocol.c +++ b/src/protocol.c @@ -193,7 +193,7 @@ void exit_requests(void) { } bool seen_request(char *request) { - past_request_t *new, p = {}; + past_request_t *new, p = {0}; p.request = request; diff --git a/src/protocol_subnet.c b/src/protocol_subnet.c index 01aed64e..2c4d08f8 100644 --- a/src/protocol_subnet.c +++ b/src/protocol_subnet.c @@ -46,7 +46,7 @@ bool add_subnet_h(connection_t *c) { char subnetstr[MAX_STRING_SIZE]; char name[MAX_STRING_SIZE]; node_t *owner; - subnet_t s = {}, *new, *old; + subnet_t s = {0}, *new, *old; if(sscanf(c->buffer, "%*d %*x " MAX_STRING " " MAX_STRING, name, subnetstr) != 2) { logger(LOG_ERR, "Got bad %s from %s (%s)", "ADD_SUBNET", c->name, @@ -160,7 +160,7 @@ bool del_subnet_h(connection_t *c) { char subnetstr[MAX_STRING_SIZE]; char name[MAX_STRING_SIZE]; node_t *owner; - subnet_t s = {}, *find; + subnet_t s = {0}, *find; if(sscanf(c->buffer, "%*d %*x " MAX_STRING " " MAX_STRING, name, subnetstr) != 2) { logger(LOG_ERR, "Got bad %s from %s (%s)", "DEL_SUBNET", c->name, diff --git a/src/route.c b/src/route.c index 8b7a13c8..3e86b40d 100644 --- a/src/route.c +++ b/src/route.c @@ -116,8 +116,8 @@ static void swap_mac_addresses(vpn_packet_t *packet) { /* 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; @@ -218,7 +218,7 @@ static void route_ipv4_unreachable(node_t *source, vpn_packet_t *packet, length_ 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; struct { @@ -632,11 +632,13 @@ static void route_ipv4_unicast(node_t *source, vpn_packet_t *packet) { } if(!subnet->owner->status.reachable) { - return route_ipv4_unreachable(source, packet, ether_size, ICMP_DEST_UNREACH, ICMP_NET_UNREACH); + route_ipv4_unreachable(source, packet, ether_size, ICMP_DEST_UNREACH, ICMP_NET_UNREACH); + return; } if(forwarding_mode == FMODE_OFF && source != myself && subnet->owner != myself) { - return route_ipv4_unreachable(source, packet, ether_size, ICMP_DEST_UNREACH, ICMP_NET_ANO); + route_ipv4_unreachable(source, packet, ether_size, ICMP_DEST_UNREACH, ICMP_NET_ANO); + return; } if(decrement_ttl && source != myself && subnet->owner != myself) @@ -656,7 +658,8 @@ static void route_ipv4_unicast(node_t *source, vpn_packet_t *packet) { } if(directonly && subnet->owner != via) { - return route_ipv4_unreachable(source, packet, ether_size, ICMP_DEST_UNREACH, ICMP_NET_ANO); + route_ipv4_unreachable(source, packet, ether_size, ICMP_DEST_UNREACH, ICMP_NET_ANO); + return; } if(via && packet->len > MAX(via->mtu, 590) && via != myself) { @@ -723,17 +726,20 @@ static void route_ipv6_unicast(node_t *source, vpn_packet_t *packet) { } if(!subnet->owner->status.reachable) { - return route_ipv6_unreachable(source, packet, ether_size, ICMP6_DST_UNREACH, ICMP6_DST_UNREACH_NOROUTE); + route_ipv6_unreachable(source, packet, ether_size, ICMP6_DST_UNREACH, ICMP6_DST_UNREACH_NOROUTE); + return; } if(forwarding_mode == FMODE_OFF && source != myself && subnet->owner != myself) { - return route_ipv6_unreachable(source, packet, ether_size, ICMP6_DST_UNREACH, ICMP6_DST_UNREACH_ADMIN); + route_ipv6_unreachable(source, packet, ether_size, ICMP6_DST_UNREACH, ICMP6_DST_UNREACH_ADMIN); + return; } - if(decrement_ttl && source != myself && subnet->owner != myself) + if(decrement_ttl && source != myself && subnet->owner != myself) { if(!do_decrement_ttl(source, packet)) { return; } + } if(priorityinheritance) { packet->priority = ((packet->data[14] & 0x0f) << 4) | (packet->data[15] >> 4); @@ -747,7 +753,8 @@ static void route_ipv6_unicast(node_t *source, vpn_packet_t *packet) { } if(directonly && subnet->owner != via) { - return route_ipv6_unreachable(source, packet, ether_size, ICMP6_DST_UNREACH, ICMP6_DST_UNREACH_ADMIN); + route_ipv6_unreachable(source, packet, ether_size, ICMP6_DST_UNREACH, ICMP6_DST_UNREACH_ADMIN); + return; } if(via && packet->len > MAX(via->mtu, 1294) && via != myself) { diff --git a/src/subnet.c b/src/subnet.c index b4c79139..81dae5f3 100644 --- a/src/subnet.c +++ b/src/subnet.c @@ -387,7 +387,7 @@ bool str2net(subnet_t *subnet, const char *subnetstr) { bool net2str(char *netstr, int len, const subnet_t *subnet) { if(!netstr || !subnet) { - logger(LOG_ERR, "net2str() was called with netstr=%p, subnet=%p!", netstr, subnet); + logger(LOG_ERR, "net2str() was called with netstr=%p, subnet=%p!", (void *)netstr, (void *)subnet); return false; } @@ -592,9 +592,9 @@ void subnet_update(node_t *owner, subnet_t *subnet, bool up) { // Prepare environment variables to be passed to the script - xasprintf(&envp[0], "NETNAME=%s", netname ? : ""); - xasprintf(&envp[1], "DEVICE=%s", device ? : ""); - xasprintf(&envp[2], "INTERFACE=%s", iface ? : ""); + xasprintf(&envp[0], "NETNAME=%s", netname ? netname : ""); + xasprintf(&envp[1], "DEVICE=%s", device ? device : ""); + xasprintf(&envp[2], "INTERFACE=%s", iface ? iface : ""); xasprintf(&envp[3], "NODE=%s", owner->name); xasprintf(&envp[4], "NAME=%s", myself->name);