Fix all warnings when compiling with -Wall -W -pedantic.
authorGuus Sliepen <guus@tinc-vpn.org>
Sun, 23 Sep 2018 13:33:23 +0000 (15:33 +0200)
committerGuus Sliepen <guus@tinc-vpn.org>
Sun, 23 Sep 2018 15:19:59 +0000 (17:19 +0200)
src/conf.c
src/graph.c
src/net.c
src/net_setup.c
src/netutl.c
src/node.c
src/protocol.c
src/protocol_subnet.c
src/route.c
src/subnet.c

index 4497b0e..0388799 100644 (file)
@@ -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) {
 }
 
 bool get_config_subnet(const config_t *cfg, subnet_t **result) {
-       subnet_t subnet = {};
+       subnet_t subnet = {0};
 
        if(!cfg) {
                return false;
 
        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 ])) {
 
                                // 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;
                                        }
                                                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));
 
                /* 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;
                }
                        fprintf(stderr, "Pathname too long: %s/%s\n", directory, fn);
                        return NULL;
                }
index 832e017..3529d01 100644 (file)
@@ -274,9 +274,9 @@ static void sssp_bfs(void) {
                                n->mtuevent = NULL;
                        }
 
                                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);
                        xasprintf(&envp[3], "NODE=%s", n->name);
                        sockaddr2str(&n->address, &address, &port);
                        xasprintf(&envp[4], "REMOTEADDRESS=%s", address);
index d20cbff..37ae116 100644 (file)
--- a/src/net.c
+++ b/src/net.c
@@ -191,7 +191,7 @@ void tarpit(int fd) {
 
        pits[next_pit++] = 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;
        }
 }
                next_pit = 0;
        }
 }
index 5eddb1a..8c43b39 100644 (file)
@@ -388,8 +388,8 @@ static bool setup_myself(void) {
        char *address = NULL;
        char *proxy = NULL;
        char *space;
        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;
        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 */
        }
 
        /* 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
        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;
 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) {
        int i;
 
        for(node = connection_tree->head; node; node = next) {
@@ -1099,9 +1099,9 @@ void close_network_connections(void) {
                close(listen_socket[i].udp);
        }
 
                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();
        xasprintf(&envp[3], "NAME=%s", myself->name);
 
        exit_requests();
index 3c2a77d..abe3d87 100644 (file)
@@ -33,7 +33,7 @@ bool hostnames = false;
   Return NULL on failure.
 */
 struct addrinfo *str2addrinfo(const char *address, const char *service, int socktype) {
   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;
        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) {
 }
 
 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;
 
        sockaddr_t result;
        int err;
 
index 12bc38f..03be21c 100644 (file)
@@ -140,7 +140,7 @@ void node_del(node_t *n) {
 }
 
 node_t *lookup_node(char *name) {
 }
 
 node_t *lookup_node(char *name) {
-       node_t n = {};
+       node_t n = {0};
 
        n.name = name;
 
 
        n.name = name;
 
@@ -148,7 +148,7 @@ node_t *lookup_node(char *name) {
 }
 
 node_t *lookup_node_udp(const sockaddr_t *sa) {
 }
 
 node_t *lookup_node_udp(const sockaddr_t *sa) {
-       node_t n = {};
+       node_t n = {0};
 
        n.address = *sa;
        n.name = NULL;
 
        n.address = *sa;
        n.name = NULL;
index d04f9ef..4f74d3b 100644 (file)
@@ -193,7 +193,7 @@ void exit_requests(void) {
 }
 
 bool seen_request(char *request) {
 }
 
 bool seen_request(char *request) {
-       past_request_t *new, p = {};
+       past_request_t *new, p = {0};
 
        p.request = request;
 
 
        p.request = request;
 
index 01aed64..2c4d08f 100644 (file)
@@ -46,7 +46,7 @@ bool add_subnet_h(connection_t *c) {
        char subnetstr[MAX_STRING_SIZE];
        char name[MAX_STRING_SIZE];
        node_t *owner;
        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,
 
        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;
        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,
 
        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,
index 8b7a13c..3e86b40 100644 (file)
@@ -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) {
 /* 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;
 
        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;
 
 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 {
        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) {
        }
 
        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) {
        }
 
        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)
        }
 
        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) {
        }
 
        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) {
        }
 
        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) {
        }
 
        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) {
        }
 
        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(!do_decrement_ttl(source, packet)) {
                        return;
                }
+       }
 
        if(priorityinheritance) {
                packet->priority = ((packet->data[14] & 0x0f) << 4) | (packet->data[15] >> 4);
 
        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) {
        }
 
        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) {
        }
 
        if(via && packet->len > MAX(via->mtu, 1294) && via != myself) {
index b4c7913..81dae5f 100644 (file)
@@ -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) {
 
 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;
        }
 
                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
 
 
        // 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);
 
        xasprintf(&envp[3], "NODE=%s", owner->name);
        xasprintf(&envp[4], "NAME=%s", myself->name);