Mark unhittable lines

Add comments for the benefit of the lcov tool, marking
lines that cannot be hit.  Typically these are fall-back
protection arms that are already covered by earlier checks,
and so it's not worth taking out the unhittable code (in case
someone changes the code between the two places in future).
This commit is contained in:
David Drysdale 2015-12-22 12:14:26 +00:00
parent 35609ceb41
commit 87ff25049c
13 changed files with 38 additions and 37 deletions

View File

@ -94,7 +94,7 @@ int ares__get_hostent(FILE *fp, int family, struct hostent **host)
p++;
if (!*p)
/* Ignore line if reached end of line. */
continue;
continue; /* LCOV_EXCL_LINE: trailing whitespace already stripped */
/* Pointer to start of host name. */
txthost = p;

View File

@ -56,7 +56,7 @@ struct timeval ares__tvnow(void)
*/
#ifdef HAVE_GETTIMEOFDAY
else
(void)gettimeofday(&now, NULL);
(void)gettimeofday(&now, NULL); /* LCOV_EXCL_LINE */
#else
else {
now.tv_sec = (long)time(NULL);

View File

@ -129,7 +129,7 @@ int ares_expand_name(const unsigned char *encoded, const unsigned char *abuf,
if (q > *s)
*(q - 1) = 0;
else
*q = 0; /* zero terminate */
*q = 0; /* zero terminate; LCOV_EXCL_LINE: empty names exit above */
return ARES_SUCCESS;
}

View File

@ -304,7 +304,7 @@ static char *lookup_service(unsigned short port, int flags,
#if GETSERVBYPORT_R_ARGS == 6
if (getservbyport_r(port, proto, &se, (void *)tmpbuf,
sizeof(tmpbuf), &sep) != 0)
sep = NULL;
sep = NULL; /* LCOV_EXCL_LINE: buffer large so this never fails */
#elif GETSERVBYPORT_R_ARGS == 5
sep = getservbyport_r(port, proto, &se, (void *)tmpbuf,
sizeof(tmpbuf));
@ -341,7 +341,7 @@ static char *lookup_service(unsigned short port, int flags,
memcpy(buf, name, name_len + 1);
else
/* avoid reusing previous one */
buf[0] = '\0';
buf[0] = '\0'; /* LCOV_EXCL_LINE: no real service names are too big */
return buf;
}
buf[0] = '\0';

View File

@ -129,7 +129,7 @@ int ares_init_options(ares_channel *channelptr, struct ares_options *options,
#endif
if (ares_library_initialized() != ARES_SUCCESS)
return ARES_ENOTINITIALIZED;
return ARES_ENOTINITIALIZED; /* LCOV_EXCL_LINE: n/a on non-WinSock */
channel = malloc(sizeof(struct ares_channeldata));
if (!channel) {
@ -540,7 +540,7 @@ static int init_by_environment(ares_channel channel)
{
status = set_options(channel, res_options);
if (status != ARES_SUCCESS)
return status;
return status; /* LCOV_EXCL_LINE: set_options() never fails */
}
return ARES_SUCCESS;
@ -1764,13 +1764,14 @@ static int set_search(ares_channel channel, const char *str)
const char *p, *q;
if(channel->ndomains != -1) {
/* LCOV_EXCL_START: all callers check ndomains == -1 */
/* if we already have some domains present, free them first */
for(n=0; n < channel->ndomains; n++)
free(channel->domains[n]);
free(channel->domains);
channel->domains = NULL;
channel->ndomains = -1;
}
} /* LCOV_EXCL_STOP */
/* Count the domains given. */
n = 0;
@ -1864,7 +1865,7 @@ static char *try_config(char *s, const char *opt, char scc)
if (!s || !opt)
/* no line or no option */
return NULL;
return NULL; /* LCOV_EXCL_LINE */
/* Hash '#' character is always used as primary comment char, additionally
a not-NUL secondary comment char will be considered when specified. */
@ -1896,7 +1897,7 @@ static char *try_config(char *s, const char *opt, char scc)
if ((len = strlen(opt)) == 0)
/* empty option */
return NULL;
return NULL; /* LCOV_EXCL_LINE */
if (strncmp(p, opt, len) != 0)
/* line and option do not match */
@ -1907,7 +1908,7 @@ static char *try_config(char *s, const char *opt, char scc)
if (!*p)
/* no option value */
return NULL;
return NULL; /* LCOV_EXCL_LINE */
if ((opt[len-1] != ':') && (opt[len-1] != '=') && !ISSPACE(*p))
/* whitespace between option name and value is mandatory
@ -2004,7 +2005,7 @@ static void randomize_key(unsigned char* key,int key_data_len)
if (!randomized) {
for (;counter<key_data_len;counter++)
key[counter]=(unsigned char)(rand() % 256);
key[counter]=(unsigned char)(rand() % 256); /* LCOV_EXCL_LINE */
}
}

View File

@ -111,7 +111,7 @@ int ares_library_init(int flags)
{
res = ares_win32_init();
if (res != ARES_SUCCESS)
return res;
return res; /* LCOV_EXCL_LINE: can't test Win32 init failure */
}
ares_init_flags = flags;

View File

@ -92,7 +92,7 @@ int ares_set_servers(ares_channel channel,
int i;
if (ares_library_initialized() != ARES_SUCCESS)
return ARES_ENOTINITIALIZED;
return ARES_ENOTINITIALIZED; /* LCOV_EXCL_LINE: n/a on non-WinSock */
if (!channel)
return ARES_ENODATA;
@ -146,7 +146,7 @@ int ares_set_servers_csv(ares_channel channel,
struct ares_addr_node *last = NULL;
if (ares_library_initialized() != ARES_SUCCESS)
return ARES_ENOTINITIALIZED;
return ARES_ENOTINITIALIZED; /* LCOV_EXCL_LINE: n/a on non-WinSock */
if (!channel)
return ARES_ENODATA;

View File

@ -150,22 +150,22 @@ int ares_parse_a_reply(const unsigned char *abuf, int alen,
if (addrs)
{
if (aptr + sizeof(struct in_addr) > abuf + alen)
{
{ /* LCOV_EXCL_START: already checked above */
free(rr_name);
status = ARES_EBADRESP;
break;
}
} /* LCOV_EXCL_STOP */
memcpy(&addrs[naddrs], aptr, sizeof(struct in_addr));
}
if (naddrs < max_addr_ttls)
{
struct ares_addrttl * const at = &addrttls[naddrs];
if (aptr + sizeof(struct in_addr) > abuf + alen)
{
{ /* LCOV_EXCL_START: already checked above */
free(rr_name);
status = ARES_EBADRESP;
break;
}
} /* LCOV_EXCL_STOP */
memcpy(&at->ipaddr, aptr, sizeof(struct in_addr));
at->ttl = rr_ttl;
}
@ -199,10 +199,10 @@ int ares_parse_a_reply(const unsigned char *abuf, int alen,
aptr += rr_len;
if (aptr > abuf + alen)
{
{ /* LCOV_EXCL_START: already checked above */
status = ARES_EBADRESP;
break;
}
} /* LCOV_EXCL_STOP */
}
if (status == ARES_SUCCESS && naddrs == 0 && naliases == 0)

View File

@ -150,22 +150,22 @@ int ares_parse_aaaa_reply(const unsigned char *abuf, int alen,
if (addrs)
{
if (aptr + sizeof(struct ares_in6_addr) > abuf + alen)
{
{ /* LCOV_EXCL_START: already checked above */
free(rr_name);
status = ARES_EBADRESP;
break;
}
} /* LCOV_EXCL_STOP */
memcpy(&addrs[naddrs], aptr, sizeof(struct ares_in6_addr));
}
if (naddrs < max_addr_ttls)
{
struct ares_addr6ttl * const at = &addrttls[naddrs];
if (aptr + sizeof(struct ares_in6_addr) > abuf + alen)
{
{ /* LCOV_EXCL_START: already checked above */
free(rr_name);
status = ARES_EBADRESP;
break;
}
} /* LCOV_EXCL_STOP */
memcpy(&at->ip6addr, aptr, sizeof(struct ares_in6_addr));
at->ttl = rr_ttl;
}
@ -199,10 +199,10 @@ int ares_parse_aaaa_reply(const unsigned char *abuf, int alen,
aptr += rr_len;
if (aptr > abuf + alen)
{
{ /* LCOV_EXCL_START: already checked above */
status = ARES_EBADRESP;
break;
}
} /* LCOV_EXCL_STOP */
}
/* the check for naliases to be zero is to make sure CNAME responses

View File

@ -142,10 +142,10 @@ int ares_parse_ns_reply( const unsigned char* abuf, int alen,
aptr += rr_len;
if ( aptr > abuf + alen )
{
{ /* LCOV_EXCL_START: already checked above */
status = ARES_EBADRESP;
break;
}
} /* LCOV_EXCL_STOP */
}
if ( status == ARES_SUCCESS && nameservers_num == 0 )

View File

@ -163,10 +163,10 @@ int ares_parse_ptr_reply(const unsigned char *abuf, int alen, const void *addr,
free(rr_name);
aptr += rr_len;
if (aptr > abuf + alen)
{
{ /* LCOV_EXCL_START: already checked above */
status = ARES_EBADRESP;
break;
}
} /* LCOV_EXCL_STOP */
}
if (status == ARES_SUCCESS && !hostname)

View File

@ -861,7 +861,7 @@ static int setsocknonblock(ares_socket_t sockfd, /* operate on this */
if (FALSE != nonblock)
return fcntl(sockfd, F_SETFL, flags | O_NONBLOCK);
else
return fcntl(sockfd, F_SETFL, flags & (~O_NONBLOCK));
return fcntl(sockfd, F_SETFL, flags & (~O_NONBLOCK)); /* LCOV_EXCL_LINE */
#elif defined(HAVE_IOCTL_FIONBIO)
@ -909,7 +909,7 @@ static int configure_socket(ares_socket_t s, int family, ares_channel channel)
#if defined(FD_CLOEXEC) && !defined(MSDOS)
/* Configure the socket fd as close-on-exec. */
if (fcntl(s, F_SETFD, FD_CLOEXEC) == -1)
return -1;
return -1; /* LCOV_EXCL_LINE */
#endif
/* Set the socket's send and receive buffer sizes. */
@ -991,7 +991,7 @@ static int open_tcp_socket(ares_channel channel, struct server_state *server)
sizeof(server->addr.addrV6));
break;
default:
return -1;
return -1; /* LCOV_EXCL_LINE */
}
/* Acquire a socket. */
@ -1083,7 +1083,7 @@ static int open_udp_socket(ares_channel channel, struct server_state *server)
sizeof(server->addr.addrV6));
break;
default:
return -1;
return -1; /* LCOV_EXCL_LINE */
}
/* Acquire a socket. */
@ -1228,7 +1228,7 @@ static int same_address(struct sockaddr *sa, struct ares_addr *aa)
return 1; /* match */
break;
default:
break;
break; /* LCOV_EXCL_LINE */
}
}
return 0; /* different */

View File

@ -151,7 +151,7 @@ inet_net_pton_ipv4(const char *src, unsigned char *dst, size_t size)
/* If nothing was written to the destination, we found no address. */
if (dst == odst)
goto enoent;
goto enoent; /* LCOV_EXCL_LINE: all valid paths above increment dst */
/* If no CIDR spec was given, infer width from net class. */
if (bits == -1) {
if (*odst >= 240) /* Class E */