SonarCloud: fix up codesmells

pull/614/head
Brad House 1 year ago
parent 956b7ebf68
commit b1a514acc1
  1. 27
      src/tools/adig.c
  2. 11
      src/tools/ares_getopt.c

@ -149,16 +149,13 @@ static void print_help(void)
static ares_bool_t read_cmdline(int argc, const char **argv, adig_config_t *config)
{
ares_getopt_state_t state;
int c;
ares_getopt_init(&state, argc, argv);
while (1) {
int c;
while ((c = ares_getopt(&state, "dh?f:s:c:t:T:U:")) != -1) {
int f;
c = ares_getopt(&state, "dh?f:s:c:t:T:U:");
if (c == -1)
break;
switch (c) {
case 'd':
#ifdef WATT32
@ -230,16 +227,18 @@ static ares_bool_t read_cmdline(int argc, const char **argv, adig_config_t *conf
config->options.udp_port = (unsigned short)strtol(state.optarg, NULL, 0);
config->optmask |= ARES_OPT_UDP_PORT;
break;
default:
snprintf(config->error, sizeof(config->error), "unrecognized option %c", c);
return ARES_FALSE;
}
}
config->args_processed = state.optind;
if (config->args_processed >= argc) {
snprintf(config->error, sizeof(config->error), "missing query name");
return ARES_FALSE;
}
return ARES_TRUE;
}
@ -292,7 +291,10 @@ static void print_question(const ares_dns_record_t *dnsrec)
ares_dns_rec_type_t qtype;
ares_dns_class_t qclass;
size_t len;
ares_dns_record_query_get(dnsrec, i, &name, &qtype, &qclass);
if (ares_dns_record_query_get(dnsrec, i, &name, &qtype, &qclass) != ARES_SUCCESS)
return;
if (name == NULL)
return;
len = strlen(name);
printf(";%s.\t", name);
if (len + 1 < 24) {
@ -607,12 +609,17 @@ static void print_binp(const ares_dns_rr_t *rr, ares_dns_rr_key_t key)
static void print_rr(const ares_dns_rr_t *rr)
{
const char *name = ares_dns_rr_get_name(rr);
size_t len = strlen(name);
size_t len = 0;
size_t keys_cnt = 0;
ares_dns_rec_type_t rtype = ares_dns_rr_get_type(rr);
const ares_dns_rr_key_t *keys = ares_dns_rr_get_keys(rtype, &keys_cnt);
size_t i;
if (name == NULL)
return;
len = strlen(name);
printf("%s.\t", name);
if (len < 24) {
printf("\t");

@ -40,11 +40,6 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
/* #if !defined(lint)
* static char sccsid[] = "@(#)getopt.c 8.2 (Berkeley) 4/2/94";
* #endif
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -70,7 +65,7 @@ void ares_getopt_init(ares_getopt_state_t *state, int nargc, const char **nargv)
*/
int ares_getopt(ares_getopt_state_t *state, const char *ostr)
{
char *oli; /* option letter list index */
const char *oli; /* option letter list index */
if (!*state->place) { /* update scanning pointer */
if (state->optind >= state->argc || *(state->place = state->argv[state->optind]) != '-') {
@ -83,13 +78,13 @@ int ares_getopt(ares_getopt_state_t *state, const char *ostr)
return (EOF);
}
} /* option letter okay? */
if ((state->optopt = (int)*state->place++) == (int)':' ||
if ((state->optopt = (int)*state->place++) == ':' ||
(oli = strchr(ostr, state->optopt)) == NULL) {
/*
* if the user didn't specify '-' as an option,
* assume it means EOF.
*/
if (state->optopt == (int)'-') {
if (state->optopt == '-') {
return (EOF);
}
if (!*state->place) {

Loading…
Cancel
Save