sonarcloud easy codesmells (#582)

Fix By: Brad House (@bradh352)
pull/583/head
Brad House 1 year ago committed by GitHub
parent 7dc3d98fba
commit ceb85775e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      src/lib/ares__addrinfo2hostent.c
  2. 13
      src/lib/ares__get_hostent.c
  3. 17
      src/lib/ares__readaddrinfo.c
  4. 25
      src/lib/ares__sortaddrinfo.c
  5. 4
      src/lib/ares_dns_record.c
  6. 18
      src/lib/ares_gethostbyname.c
  7. 10
      src/lib/ares_getnameinfo.c
  8. 29
      src/lib/ares_init.c
  9. 3
      src/lib/ares_query.c
  10. 3
      src/lib/ares_search.c
  11. 3
      src/lib/ares_send.c
  12. 5
      src/lib/ares_strsplit.c
  13. 3
      src/lib/bitncmp.c
  14. 22
      src/lib/inet_net_pton.c
  15. 49
      src/tools/adig.c
  16. 11
      src/tools/ahost.c
  17. 4
      src/tools/ares_getopt.c

@ -61,7 +61,10 @@ ares_status_t ares__addrinfo2hostent(const struct ares_addrinfo *ai, int family,
struct ares_addrinfo_cname *next_cname;
char **aliases = NULL;
char *addrs = NULL;
size_t naliases = 0, naddrs = 0, alias = 0, i;
size_t naliases = 0;
size_t naddrs = 0;
size_t alias = 0;
size_t i;
if (ai == NULL || host == NULL) {
return ARES_EBADQUERY;

@ -43,10 +43,17 @@
ares_status_t ares__get_hostent(FILE *fp, int family, struct hostent **host)
{
char *line = NULL, *p, *q, **alias;
char *txtaddr, *txthost, *txtalias;
char *line = NULL;
char *p;
char *q;
char **alias;
char *txtaddr;
char *txthost;
char *txtalias;
ares_status_t status;
size_t addrlen, linesize, naliases;
size_t addrlen;
size_t linesize;
size_t naliases;
struct ares_addr addr;
struct hostent *hostent = NULL;

@ -47,15 +47,22 @@ ares_status_t ares__readaddrinfo(FILE *fp, const char *name,
const struct ares_addrinfo_hints *hints,
struct ares_addrinfo *ai)
{
char *line = NULL, *p, *q;
char *txtaddr, *txthost, *txtalias;
char *line = NULL;
char *p;
char *q;
char *txtaddr;
char *txthost;
char *txtalias;
char *aliases[MAX_ALIASES];
size_t i, alias_count;
size_t i;
size_t alias_count;
ares_status_t status = ARES_SUCCESS;
size_t linesize;
struct ares_addrinfo_cname *cname = NULL, *cnames = NULL;
struct ares_addrinfo_cname *cname = NULL;
struct ares_addrinfo_cname *cnames = NULL;
struct ares_addrinfo_node *nodes = NULL;
ares_bool_t match_with_alias, match_with_canonical;
ares_bool_t match_with_alias;
ares_bool_t match_with_canonical;
ares_bool_t want_cname =
(hints->ai_flags & ARES_AI_CANONNAME) ? ARES_TRUE : ARES_FALSE;

@ -235,12 +235,22 @@ static int rfc6724_compare(const void *ptr1, const void *ptr2)
{
const struct addrinfo_sort_elem *a1 = (const struct addrinfo_sort_elem *)ptr1;
const struct addrinfo_sort_elem *a2 = (const struct addrinfo_sort_elem *)ptr2;
int scope_src1, scope_dst1, scope_match1;
int scope_src2, scope_dst2, scope_match2;
int label_src1, label_dst1, label_match1;
int label_src2, label_dst2, label_match2;
int precedence1, precedence2;
size_t prefixlen1, prefixlen2;
int scope_src1;
int scope_dst1;
int scope_match1;
int scope_src2;
int scope_dst2;
int scope_match2;
int label_src1;
int label_dst1;
int label_match1;
int label_src2;
int label_dst2;
int label_match2;
int precedence1;
int precedence2;
size_t prefixlen1;
size_t prefixlen2;
/* Rule 1: Avoid unusable destinations. */
if (a1->has_src_addr != a2->has_src_addr) {
@ -387,7 +397,8 @@ ares_status_t ares__sortaddrinfo(ares_channel channel,
struct ares_addrinfo_node *list_sentinel)
{
struct ares_addrinfo_node *cur;
size_t nelem = 0, i;
size_t nelem = 0;
size_t i;
int has_src_addr;
struct addrinfo_sort_elem *elems;

@ -756,7 +756,7 @@ ares_status_t ares_dns_rr_set_addr(ares_dns_rr_t *dns_rr, ares_dns_rr_key_t key,
return ARES_EFORMERR;
}
memcpy(a, addr, sizeof(*addr));
memcpy(a, addr, sizeof(*a));
return ARES_SUCCESS;
}
@ -775,7 +775,7 @@ ares_status_t ares_dns_rr_set_addr6(ares_dns_rr_t *dns_rr,
return ARES_EFORMERR;
}
memcpy(a, addr, sizeof(*addr));
memcpy(a, addr, sizeof(*a));
return ARES_SUCCESS;
}

@ -127,9 +127,12 @@ void ares_gethostbyname(ares_channel channel, const char *name, int family,
static void sort_addresses(struct hostent *host,
const struct apattern *sortlist, size_t nsort)
{
struct in_addr a1, a2;
int i1, i2;
size_t ind1, ind2;
struct in_addr a1;
struct in_addr a2;
int i1;
int i2;
size_t ind1;
size_t ind2;
/* This is a simple insertion sort, not optimized at all. i1 walks
* through the address list, with the loop invariant that everything
@ -181,9 +184,12 @@ static size_t get_address_index(const struct in_addr *addr,
static void sort6_addresses(struct hostent *host,
const struct apattern *sortlist, size_t nsort)
{
struct ares_in6_addr a1, a2;
int i1, i2;
size_t ind1, ind2;
struct ares_in6_addr a1;
struct ares_in6_addr a2;
int i1;
int i2;
size_t ind1;
size_t ind2;
/* This is a simple insertion sort, not optimized at all. i1 walks
* through the address list, with the loop invariant that everything

@ -333,7 +333,8 @@ static void append_scopeid(struct sockaddr_in6 *addr6, unsigned int flags,
char *buf, size_t buflen)
{
# ifdef HAVE_IF_INDEXTONAME
int is_ll, is_mcll;
int is_ll;
int is_mcll;
# endif
char tmpbuf[IF_NAMESIZE + 2];
size_t bufl;
@ -386,8 +387,11 @@ static void append_scopeid(struct sockaddr_in6 *addr6, unsigned int flags,
/* Determines if s1 ends with the string in s2 (case-insensitive) */
STATIC_TESTABLE char *ares_striendstr(const char *s1, const char *s2)
{
const char *c1, *c2, *c1_begin;
int lo1, lo2;
const char *c1;
const char *c2;
const char *c1_begin;
int lo1;
int lo2;
size_t s1_len = ares_strlen(s1);
size_t s2_len = ares_strlen(s2);

@ -345,7 +345,8 @@ int ares_dup(ares_channel *dest, ares_channel src)
int ares_save_options(ares_channel channel, struct ares_options *options,
int *optmask)
{
size_t i, j;
size_t i;
size_t j;
size_t ipv4_nservers = 0;
/* Zero everything out */
@ -623,7 +624,8 @@ static ares_status_t init_by_options(ares_channel channel,
static ares_status_t init_by_environment(ares_channel channel)
{
const char *localdomain, *res_options;
const char *localdomain;
const char *res_options;
ares_status_t status;
localdomain = getenv("LOCALDOMAIN");
@ -871,7 +873,9 @@ static ULONG getBestRouteMetric(IF_LUID * const luid, /* Can't be const :( */
static ares_bool_t get_DNS_Windows(char **outptr)
{
IP_ADAPTER_DNS_SERVER_ADDRESS *ipaDNSAddr;
IP_ADAPTER_ADDRESSES *ipaa, *newipaa, *ipaaEntry;
IP_ADAPTER_ADDRESSES *ipaa;
IP_ADAPTER_ADDRESSES *newipaa;
IP_ADAPTER_ADDRESSES *ipaaEntry;
ULONG ReqBufsz = IPAA_INITIAL_BUF_SZ;
ULONG Bufsz = IPAA_INITIAL_BUF_SZ;
ULONG AddrFlags = 0;
@ -1074,7 +1078,8 @@ done:
*/
static ares_bool_t get_SuffixList_Windows(char **outptr)
{
HKEY hKey, hKeyEnum;
HKEY hKey;
HKEY hKeyEnum;
char keyName[256];
DWORD keyNameBuffSize;
DWORD keyIdx = 0;
@ -1197,7 +1202,8 @@ static ares_status_t init_by_resolv_conf(ares_channel channel)
#elif defined(__MVS__)
struct __res_state *res = 0;
size_t count4, count6;
size_t count4;
size_t count6;
__STATEEXTIPV6 *v6;
struct server_state *pserver;
if (0 == res) {
@ -1833,7 +1839,8 @@ static ares_status_t config_lookup(ares_channel channel, const char *str,
const char *bindch, const char *altbindch,
const char *filech)
{
char lookups[3], *l;
char lookups[3];
char *l;
const char *vqualifier p;
ares_bool_t found;
@ -2055,7 +2062,8 @@ static ares_status_t config_nameserver(struct server_state **servers,
{
struct ares_addr host;
struct server_state *newserv;
const char *p, *txtaddr;
const char *p;
const char *txtaddr;
/* On Windows, there may be more than one nameserver specified in the same
* registry key, so we parse input as a space or comma seperated list.
*/
@ -2123,7 +2131,8 @@ static ares_status_t config_sortlist(struct apattern **sortlist, size_t *nsort,
/* Add sortlist entries. */
while (*str && *str != ';') {
int bits;
char ipbuf[17], ipbufpfx[32];
char ipbuf[17];
char ipbufpfx[32];
size_t len;
/* Find just the IP */
@ -2239,7 +2248,9 @@ static ares_status_t set_search(ares_channel channel, const char *str)
static ares_status_t set_options(ares_channel channel, const char *str)
{
const char *p, *q, *val;
const char *p;
const char *q;
const char *val;
p = str;
while (*p) {

@ -67,7 +67,8 @@ ares_status_t ares_query_qid(ares_channel channel, const char *name,
{
struct qquery *qquery;
unsigned char *qbuf;
int qlen, rd;
int qlen;
int rd;
ares_status_t status;
unsigned short id = generate_unique_id(channel);

@ -244,7 +244,8 @@ ares_status_t ares__single_domain(ares_channel channel, const char *name,
char *line = NULL;
ares_status_t status;
size_t linesize;
const char *p, *q;
const char *p;
const char *q;
int error;
/* If the name contains a trailing dot, then the single query is the name

@ -41,7 +41,8 @@ ares_status_t ares_send_ex(ares_channel channel, const unsigned char *qbuf,
size_t qlen, ares_callback callback, void *arg)
{
struct query *query;
size_t i, packetsz;
size_t i;
size_t packetsz;
struct timeval now;
/* Verify that the query is at least long enough to hold the header. */

@ -51,7 +51,10 @@ char **ares__strsplit(const char *in, const char *delms, size_t *num_elm)
const char *p;
char **table;
void *tmp;
size_t i, j, k, count;
size_t i;
size_t j;
size_t k;
size_t count;
if (in == NULL || delms == NULL || num_elm == NULL) {
return NULL;

@ -36,7 +36,8 @@
*/
int ares__bitncmp(const void *l, const void *r, size_t n)
{
size_t lb, rb;
size_t lb;
size_t rb;
ares_ssize_t x;
size_t b;

@ -64,7 +64,11 @@ static int ares_inet_net_pton_ipv4(const char *src, unsigned char *dst,
{
static const char xdigits[] = "0123456789abcdef";
static const char digits[] = "0123456789";
int n, ch, tmp = 0, dirty, bits;
int n;
int ch;
int tmp = 0;
int dirty;
int bits;
const unsigned char *odst = dst;
ch = *src++;
@ -236,11 +240,17 @@ static int getbits(const char *src, size_t *bitsp)
static int ares_inet_pton6(const char *src, unsigned char *dst)
{
static const char xdigits_l[] = "0123456789abcdef",
xdigits_u[] = "0123456789ABCDEF";
unsigned char tmp[NS_IN6ADDRSZ], *tp, *endp, *colonp;
const char *xdigits, *curtok;
int ch, saw_xdigit, count_xdigit;
static const char xdigits_l[] = "0123456789abcdef";
static const char xdigits_u[] = "0123456789ABCDEF";
unsigned char tmp[NS_IN6ADDRSZ];
unsigned char *tp;
unsigned char *endp;
unsigned char *colonp;
const char *xdigits;
const char *curtok;
int ch;
int saw_xdigit;
int count_xdigit;
unsigned int val;
memset((tp = tmp), '\0', NS_IN6ADDRSZ);

@ -191,14 +191,23 @@ static size_t ares_strcpy(char *dest, const char *src, size_t dest_size)
int main(int argc, char **argv)
{
ares_channel channel;
int c, i, optmask = ARES_OPT_FLAGS, dnsclass = C_IN, type = T_A;
int status, nfds, count;
int c;
int i;
int optmask = ARES_OPT_FLAGS;
int dnsclass = C_IN;
int type = T_A;
int status;
int nfds;
int count;
int use_ptr_helper = 0;
struct ares_options options;
struct hostent *hostent;
fd_set read_fds, write_fds;
struct timeval *tvp, tv;
struct ares_addr_node *srvr, *servers = NULL;
fd_set read_fds;
fd_set write_fds;
struct timeval *tvp;
struct timeval tv;
struct ares_addr_node *srvr;
struct ares_addr_node *servers = NULL;
#ifdef USE_WINSOCK
WORD wVersionRequested = MAKEWORD(USE_WINSOCK, USE_WINSOCK);
@ -419,8 +428,19 @@ static void callback(void *arg, int status, int timeouts, unsigned char *abuf,
int alen)
{
char *name = (char *)arg;
int id, qr, opcode, aa, tc, rd, ra, rcode;
unsigned int qdcount, ancount, nscount, arcount, i;
int id;
int qr;
int opcode;
int aa;
int tc;
int rd;
int ra;
int rcode;
unsigned int qdcount;
unsigned int ancount;
unsigned int nscount;
unsigned int arcount;
unsigned int i;
const unsigned char *aptr;
(void)timeouts;
@ -509,7 +529,9 @@ static const unsigned char *display_question(const unsigned char *aptr,
int alen)
{
char *name;
int type, dnsclass, status;
int type;
int dnsclass;
int status;
long len;
/* Parse the question name. */
@ -548,9 +570,12 @@ static const unsigned char *display_rr(const unsigned char *aptr,
const unsigned char *abuf, int alen)
{
const unsigned char *p;
int type, dnsclass;
int type;
int dnsclass;
unsigned int ttl;
int dlen, status, i;
int dlen;
int status;
int i;
long len;
int vlen;
char addr[46];
@ -915,7 +940,9 @@ static int convert_query(char **name_p, int use_bitstring)
char *c = new_name;
const unsigned char *ip = (const unsigned char *)&addr.addr6;
int max_i = (int)sizeof(addr.addr6) - 1;
int i, hi, lo;
int i;
int hi;
int lo;
/* Use the more compact RFC-2673 notation?
* Currently doesn't work or unsupported by the DNS-servers I've tested

@ -66,9 +66,14 @@ int main(int argc, char **argv)
struct ares_options options;
int optmask = 0;
ares_channel channel;
int status, nfds, c, addr_family = AF_INET;
fd_set read_fds, write_fds;
struct timeval *tvp, tv;
int status;
int nfds;
int c;
int addr_family = AF_INET;
fd_set read_fds;
fd_set write_fds;
struct timeval *tvp;
struct timeval tv;
struct in_addr addr4;
struct ares_in6_addr addr6;

@ -50,8 +50,8 @@
#include <string.h>
#include "ares_getopt.h"
int opterr = 1, /* if error message should be printed */
optind = 1; /* index into parent argv vector */
int opterr = 1; /* if error message should be printed */
int optind = 1; /* index into parent argv vector */
int optopt = 0; /* character checked for validity */
static int optreset; /* reset getopt */
char *optarg; /* argument associated with option */

Loading…
Cancel
Save