start_listen_sockets: exit if no addresses

Do not allocate a 0 byte buffer if no addresses are available:

    common.c:122:14: warning: Call to 'malloc' has an allocation size of 0 bytes
       *sockfd = malloc(num_addr * sizeof(*sockfd[0]));
		 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This commit is contained in:
Michael Santos 2018-06-17 10:01:44 -04:00
parent 552723cc5f
commit c179d9a57b

View File

@ -116,6 +116,11 @@ int start_listen_sockets(int *sockfd[], struct addrinfo *addr_list)
for (addr = addr_list; addr; addr = addr->ai_next)
num_addr++;
if (num_addr == 0) {
fprintf(stderr, "FATAL: No available addresses.\n");
exit(1);
}
if (verbose)
fprintf(stderr, "listening to %d addresses\n", num_addr);