Browse Source

Fix all warnings when compiling with -Wall -W -pedantic.

Guus Sliepen 5 years ago
parent
commit
99763e34d5
10 changed files with 44 additions and 37 deletions
  1. 3 3
      src/conf.c
  2. 3 3
      src/graph.c
  3. 1 1
      src/net.c
  4. 9 9
      src/net_setup.c
  5. 2 2
      src/netutl.c
  6. 2 2
      src/node.c
  7. 1 1
      src/protocol.c
  8. 2 2
      src/protocol_subnet.c
  9. 17 10
      src/route.c
  10. 4 4
      src/subnet.c

+ 3 - 3
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;
 		}

+ 3 - 3
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);

+ 1 - 1
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;
 	}
 }

+ 9 - 9
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();

+ 2 - 2
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;
 

+ 2 - 2
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;

+ 1 - 1
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;
 

+ 2 - 2
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,

+ 17 - 10
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) {

+ 4 - 4
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);