From 87ff25049c7a3d9856ca7a0b82964405a2d0c62d Mon Sep 17 00:00:00 2001 From: David Drysdale Date: Tue, 22 Dec 2015 12:14:26 +0000 Subject: [PATCH] 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). --- ares__get_hostent.c | 2 +- ares__timeval.c | 2 +- ares_expand_name.c | 2 +- ares_getnameinfo.c | 4 ++-- ares_init.c | 15 ++++++++------- ares_library_init.c | 2 +- ares_options.c | 4 ++-- ares_parse_a_reply.c | 12 ++++++------ ares_parse_aaaa_reply.c | 12 ++++++------ ares_parse_ns_reply.c | 4 ++-- ares_parse_ptr_reply.c | 4 ++-- ares_process.c | 10 +++++----- inet_net_pton.c | 2 +- 13 files changed, 38 insertions(+), 37 deletions(-) diff --git a/ares__get_hostent.c b/ares__get_hostent.c index 4497d60..ed3f9ef 100644 --- a/ares__get_hostent.c +++ b/ares__get_hostent.c @@ -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; diff --git a/ares__timeval.c b/ares__timeval.c index f7aa788..94efb7d 100644 --- a/ares__timeval.c +++ b/ares__timeval.c @@ -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); diff --git a/ares_expand_name.c b/ares_expand_name.c index 0dfc109..81f4cee 100644 --- a/ares_expand_name.c +++ b/ares_expand_name.c @@ -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; } diff --git a/ares_getnameinfo.c b/ares_getnameinfo.c index e74c7a0..77de0d7 100644 --- a/ares_getnameinfo.c +++ b/ares_getnameinfo.c @@ -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'; diff --git a/ares_init.c b/ares_init.c index debe0c1..e8c2433 100644 --- a/ares_init.c +++ b/ares_init.c @@ -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 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) diff --git a/ares_parse_aaaa_reply.c b/ares_parse_aaaa_reply.c index 31e4a8c..454ff1c 100644 --- a/ares_parse_aaaa_reply.c +++ b/ares_parse_aaaa_reply.c @@ -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 diff --git a/ares_parse_ns_reply.c b/ares_parse_ns_reply.c index d331e67..3607c3b 100644 --- a/ares_parse_ns_reply.c +++ b/ares_parse_ns_reply.c @@ -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 ) diff --git a/ares_parse_ptr_reply.c b/ares_parse_ptr_reply.c index df21e40..13d6b44 100644 --- a/ares_parse_ptr_reply.c +++ b/ares_parse_ptr_reply.c @@ -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) diff --git a/ares_process.c b/ares_process.c index c85b18a..1cf271a 100644 --- a/ares_process.c +++ b/ares_process.c @@ -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 */ diff --git a/inet_net_pton.c b/inet_net_pton.c index 71c07c5..b64fc5b 100644 --- a/inet_net_pton.c +++ b/inet_net_pton.c @@ -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 */