From 297bf9aa6badb555014697b7fbcfad265a76aa17 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Tue, 14 Jan 2020 23:36:01 -0600 Subject: [PATCH] Fix cppcheck warnings --- alinco/alinco.c | 6 ++---- src/cm108.c | 21 ++++++++++----------- src/event.c | 1 + src/network.c | 6 +++--- tests/ampctl_parse.c | 2 ++ tests/rigctl_parse.c | 29 ++++++++++++++++++----------- tests/rotctl_parse.c | 4 +++- yaesu/newcat.h | 2 +- 8 files changed, 40 insertions(+), 31 deletions(-) diff --git a/alinco/alinco.c b/alinco/alinco.c index b0dffcfd1..9fbaad4ca 100644 --- a/alinco/alinco.c +++ b/alinco/alinco.c @@ -109,9 +109,7 @@ int alinco_transaction(RIG *rig, if (cmd == NULL) { rig_debug(RIG_DEBUG_ERR, - "%s: null argument? cmd(%s), data(%s), data_len(%s)\n", __func__, - cmd == NULL ? "OK" : "NULL", data == NULL ? "OK" : "NULL", - data_len == NULL ? "OK" : "NULL"); + "%s: null argument for cmd?\n", __func__); return -RIG_EINTERNAL; } @@ -137,7 +135,7 @@ int alinco_transaction(RIG *rig, return retval; } - if ((data == NULL && data_len != NULL) || (data != NULL && data_len == NULL)) + if (!(data && data_len)) { rig_debug(RIG_DEBUG_ERR, "%s: data and datalen not both NULL??\n", __func__); return -RIG_EINTERNAL; diff --git a/src/cm108.c b/src/cm108.c index 169cbc4b3..a08c6a853 100644 --- a/src/cm108.c +++ b/src/cm108.c @@ -163,17 +163,6 @@ int cm108_close(hamlib_port_t *p) */ int cm108_ptt_set(hamlib_port_t *p, ptt_t pttx) { - ssize_t nw; - char out_rep[] = - { - 0x00, // report number - // HID output report - 0x00, - (pttx == RIG_PTT_ON) ? (1 << p->parm.cm108.ptt_bitnum) : 0, // set GPIO - 1 << p->parm.cm108.ptt_bitnum, // Data direction register (1=output) - 0x00 - }; - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); // For a CM108 USB audio device PTT is wired up to one of the GPIO @@ -188,6 +177,16 @@ int cm108_ptt_set(hamlib_port_t *p, ptt_t pttx) case RIG_PTT_CM108: { + ssize_t nw; + char out_rep[] = + { + 0x00, // report number + // HID output report + 0x00, + (pttx == RIG_PTT_ON) ? (1 << p->parm.cm108.ptt_bitnum) : 0, // set GPIO + 1 << p->parm.cm108.ptt_bitnum, // Data direction register (1=output) + 0x00 + }; // Build a packet for CM108 HID to turn GPIO bit on or off. // Packet is 4 bytes, preceded by a 'report number' byte diff --git a/src/event.c b/src/event.c index 47993d671..8c359376b 100644 --- a/src/event.c +++ b/src/event.c @@ -38,6 +38,7 @@ #include #include #include +#include #include #include diff --git a/src/network.c b/src/network.c index 9aba3ba6f..c116b4697 100644 --- a/src/network.c +++ b/src/network.c @@ -239,7 +239,7 @@ int network_open(hamlib_port_t *rp, int default_port) return -RIG_EIO; } - if ((status = connect(fd, res->ai_addr, res->ai_addrlen)) == 0) + if (connect(fd, res->ai_addr, res->ai_addrlen) == 0) { break; } @@ -281,9 +281,9 @@ int network_open(hamlib_port_t *rp, int default_port) void network_flush(hamlib_port_t *rp) { #ifdef __MINGW32__ - ULONG len = 0; + ULONG len; #else - uint len = 0; + uint len; #endif char buffer[NET_BUFFER_SIZE] = { 0 }; diff --git a/tests/ampctl_parse.c b/tests/ampctl_parse.c index 2415930fd..7d562a9f8 100644 --- a/tests/ampctl_parse.c +++ b/tests/ampctl_parse.c @@ -478,7 +478,9 @@ int ampctl_parse(AMP *my_amp, FILE *fin, FILE *fout, char *argv[], int argc) #endif /* cmd, internal, ampctld */ +#ifdef HAVE_LIBREADLINE if (!(interactive && prompt && have_rl)) +#endif { if (interactive) { diff --git a/tests/rigctl_parse.c b/tests/rigctl_parse.c index 4dfed56dc..18cf3d641 100644 --- a/tests/rigctl_parse.c +++ b/tests/rigctl_parse.c @@ -321,7 +321,7 @@ static struct test_table *find_cmd_entry(int cmd) } } - if (i >= MAXNBOPT || test_list[i].cmd == 0x00) + if (test_list[i].cmd == 0x00) { return NULL; } @@ -380,7 +380,13 @@ int hash_model_id_sort(struct mod_lst *a, struct mod_lst *b) void hash_sort_by_model_id() { - HASH_SORT(models, hash_model_id_sort); + if (models != NULL) + { + HASH_SORT(models, hash_model_id_sort); + } + else { + rig_debug(RIG_DEBUG_ERR,"%s: models empty?\n", __func__); + } } @@ -576,11 +582,10 @@ static int next_word(char *buffer, int argc, char *argv[], int newline) } -#define fprintf_flush(f, a...) \ - ({ int __ret; \ - __ret = fprintf((f), a); \ - fflush((f)); \ - __ret; \ +#define fprintf_flush(f, a...) \ + ({ fprintf((f), a); \ + fflush((f)); \ + \ }) @@ -600,7 +605,9 @@ int rigctl_parse(RIG *my_rig, FILE *fin, FILE *fout, char *argv[], int argc, vfo_t vfo = RIG_VFO_CURR; /* cmd, internal, rigctld */ +#ifdef HAVE_LIBREADLINE if (!(interactive && prompt && have_rl)) +#endif { if (interactive) @@ -3688,14 +3695,14 @@ int dump_chan(FILE *fout, RIG *rig, channel_t *chan) sprintf_freq(freqbuf, chan->xit); fprintf(fout, "XIT: %s%s\n", chan->xit > 0 ? "+" : "", freqbuf); - fprintf(fout, "CTCSS: %d.%dHz, ", chan->ctcss_tone / 10, chan->ctcss_tone % 10); + fprintf(fout, "CTCSS: %u.%uHz, ", chan->ctcss_tone / 10, chan->ctcss_tone % 10); fprintf(fout, - "CTCSSsql: %d.%dHz, ", + "CTCSSsql: %u.%uHz, ", chan->ctcss_sql / 10, chan->ctcss_sql % 10); - fprintf(fout, "DCS: %d.%d, ", chan->dcs_code / 10, chan->dcs_code % 10); - fprintf(fout, "DCSsql: %d.%d\n", chan->dcs_sql / 10, chan->dcs_sql % 10); + fprintf(fout, "DCS: %u.%u, ", chan->dcs_code / 10, chan->dcs_code % 10); + fprintf(fout, "DCSsql: %u.%u\n", chan->dcs_sql / 10, chan->dcs_sql % 10); sprintf_func(prntbuf, chan->funcs); fprintf(fout, "Functions: %s\n", prntbuf); diff --git a/tests/rotctl_parse.c b/tests/rotctl_parse.c index e2c27fdd0..04b360f8e 100644 --- a/tests/rotctl_parse.c +++ b/tests/rotctl_parse.c @@ -523,7 +523,9 @@ int rotctl_parse(ROT *my_rot, FILE *fin, FILE *fout, char *argv[], int argc, #endif /* cmd, internal, rotctld */ +#ifdef HAVE_LIBREADLINE if (!(interactive && prompt && have_rl)) +#endif { if (interactive) { @@ -1450,7 +1452,7 @@ int rotctl_parse(ROT *my_rot, FILE *fin, FILE *fout, char *argv[], int argc, if (interactive && !prompt) { fprintf(fout, NETROTCTL_RET "%d\n", retcode); - ext_resp = 0; + // ext_resp = 0; // not used ? resp_sep = '\n'; } else diff --git a/yaesu/newcat.h b/yaesu/newcat.h index 60b2a5983..df5ef3734 100644 --- a/yaesu/newcat.h +++ b/yaesu/newcat.h @@ -50,7 +50,7 @@ typedef char ncboolean; /* shared function version */ -#define NEWCAT_VER "0.26" +#define NEWCAT_VER "0.27" /* Hopefully large enough for future use, 128 chars plus '\0' */ #define NEWCAT_DATA_LEN 129