From 6e8d328fb15c63f09bc51e82340d5b6c076481fd Mon Sep 17 00:00:00 2001 From: Mike Black W9MDB Date: Sat, 30 Sep 2023 23:42:22 -0500 Subject: [PATCH] Fix most of the redundant warning from cppcheck --- cppcheck.sh | 2 +- rigs/anytone/anytone.c | 104 +++++++++++++---------------------------- rigs/dummy/tci1x.c | 5 -- rigs/flexradio/dttsp.c | 3 +- rigs/gomspace/gs100.c | 5 -- rigs/icom/icom.c | 6 --- rigs/kenwood/kenwood.c | 5 -- rigs/kenwood/th.c | 2 +- rigs/yaesu/newcat.c | 2 +- rotators/flir/flir.c | 6 +-- 10 files changed, 37 insertions(+), 103 deletions(-) diff --git a/cppcheck.sh b/cppcheck.sh index 07a8023cb..e669d0236 100755 --- a/cppcheck.sh +++ b/cppcheck.sh @@ -25,7 +25,7 @@ SUPPRESS="\ --suppress=*:extra/gnuradio/HrAGC.h \ --suppress=*:extra/gnuradio/gnuradio.cc \ --suppress=missingIncludeSystem \ ---suppress=*.style/rigs/adat/adat.c +--suppress=*:style/rigs/adat/adat.c #CHECK="\ #-D RIG_LEVEL_LINEOUT=1 \ diff --git a/rigs/anytone/anytone.c b/rigs/anytone/anytone.c index f14d6162e..63cef4da2 100644 --- a/rigs/anytone/anytone.c +++ b/rigs/anytone/anytone.c @@ -204,19 +204,12 @@ int anytone_transaction(RIG *rig, unsigned char *cmd, int cmd_len, unsigned char ENTERFUNC; - if (rig == NULL) - { - retval = -RIG_EARG; - } - else - { - retval = anytone_send(rig, cmd, cmd_len); + retval = anytone_send(rig, cmd, cmd_len); - if (retval == RIG_OK && expected_len != 0) - { - int len = anytone_receive(rig, reply, reply_len, expected_len); - rig_debug(RIG_DEBUG_VERBOSE, "%s(%d): rx len=%d\n", __func__, __LINE__, len); - } + if (retval == RIG_OK && expected_len != 0) + { + int len = anytone_receive(rig, reply, reply_len, expected_len); + rig_debug(RIG_DEBUG_VERBOSE, "%s(%d): rx len=%d\n", __func__, __LINE__, len); } RETURNFUNC(retval); @@ -266,17 +259,10 @@ int anytone_cleanup(RIG *rig) ENTERFUNC; - if (rig == NULL) + if (rig->state.priv != NULL) { - retval = -RIG_EARG; - } - else - { - if (rig->state.priv != NULL) - { - free(rig->state.priv); - rig->state.priv = NULL; - } + free(rig->state.priv); + rig->state.priv = NULL; } RETURNFUNC(retval); @@ -291,11 +277,6 @@ int anytone_open(RIG *rig) ENTERFUNC; - if (rig == NULL) - { - retval = -RIG_EARG; - } - unsigned char cmd[] = { 0x2B,0x41,0x44,0x41,0x54,0x41,0x3A,0x30,0x30,0x2C,0x30,0x30,0x31,0x0d,0x0a,'a',0x0d,0x0a }; write_block(&rig->state.rigport, cmd, sizeof(cmd)); hl_usleep(500 * 1000); @@ -345,27 +326,20 @@ int anytone_get_vfo(RIG *rig, vfo_t *vfo) ENTERFUNC; - if (rig == NULL) - { - retval = -RIG_EARG; - } + anytone_priv_data_ptr p = (anytone_priv_data_ptr) rig->state.priv; + unsigned char reply[512]; + unsigned char cmd[] = { 0x2b,0x41,0x44,0x41,0x54,0x41,0x3a,0x30,0x30,0x2c,0x30,0x30,0x36,0x0d,0x0a,0x04,0x05,0x00,0x00,0x00,0x00,0x0d,0x0a }; + anytone_transaction(rig, cmd, sizeof(cmd), reply, sizeof(reply), 114); + if (reply[113] == 0x9b) *vfo = RIG_VFO_A; + else if (reply[113] == 0x9c) *vfo = RIG_VFO_B; else { - anytone_priv_data_ptr p = (anytone_priv_data_ptr) rig->state.priv; - unsigned char reply[512]; - unsigned char cmd[] = { 0x2b,0x41,0x44,0x41,0x54,0x41,0x3a,0x30,0x30,0x2c,0x30,0x30,0x36,0x0d,0x0a,0x04,0x05,0x00,0x00,0x00,0x00,0x0d,0x0a }; - anytone_transaction(rig, cmd, sizeof(cmd), reply, sizeof(reply), 114); - if (reply[113] == 0x9b) *vfo = RIG_VFO_A; - else if (reply[113] == 0x9c) *vfo = RIG_VFO_B; - else - { - *vfo = RIG_VFO_A; // default to VFOA - rig_debug(RIG_DEBUG_ERR, "%s: unknown vfo=0x%02x\n", __func__, reply[113]); - } - - *vfo = p->vfo_curr; + *vfo = RIG_VFO_A; // default to VFOA + rig_debug(RIG_DEBUG_ERR, "%s: unknown vfo=0x%02x\n", __func__, reply[113]); } + *vfo = p->vfo_curr; + RETURNFUNC(retval); } @@ -396,17 +370,10 @@ int anytone_get_ptt(RIG *rig, vfo_t vfo, ptt_t *ptt) ENTERFUNC; - if (rig == NULL) - { - retval = -RIG_EARG; - } - else - { - anytone_priv_data_t *p = rig->state.priv; - *ptt = p->ptt; - } + anytone_priv_data_t *p = rig->state.priv; + *ptt = p->ptt; - return retval; + RETURNFUNC(retval); } // --------------------------------------------------------------------------- // anytone_set_ptt @@ -417,26 +384,19 @@ int anytone_set_ptt(RIG *rig, vfo_t vfo, ptt_t ptt) ENTERFUNC; - if (rig == NULL) - { - retval = -RIG_EARG; - } - else - { - //char buf[8] = { 0x41, 0x00, 0x00, 0x00, 0x27, 0x00, 0x00, 0x06 }; - unsigned char ptton[] = { 0x2B,0x41,0x44,0x41,0x54,0x41,0x3A,0x30,0x30,0x2C,0x30,0x30,0x31,0x0d,0x0a,0x61,0x0d,0x0a }; - unsigned char pttoff[] = { 0x2B,0x41,0x44,0x41,0x54,0x41,0x3A,0x30,0x30,0x2C,0x30,0x32,0x33,0x0d,0x0a,0x56,0x0d,0x0a }; - void *pttcmd = ptton; - if (!ptt) pttcmd = pttoff; + //char buf[8] = { 0x41, 0x00, 0x00, 0x00, 0x27, 0x00, 0x00, 0x06 }; + unsigned char ptton[] = { 0x2B,0x41,0x44,0x41,0x54,0x41,0x3A,0x30,0x30,0x2C,0x30,0x30,0x31,0x0d,0x0a,0x61,0x0d,0x0a }; + unsigned char pttoff[] = { 0x2B,0x41,0x44,0x41,0x54,0x41,0x3A,0x30,0x30,0x2C,0x30,0x32,0x33,0x0d,0x0a,0x56,0x0d,0x0a }; + void *pttcmd = ptton; + if (!ptt) pttcmd = pttoff; - //if (!ptt) { cmd = " (unsigned char*)+ADATA:00,023\r\nV\r\n"; } + //if (!ptt) { cmd = " (unsigned char*)+ADATA:00,023\r\nV\r\n"; } - MUTEX_LOCK(p->mutex); - anytone_transaction(rig, pttcmd, sizeof(ptton), NULL, 0, 0); - anytone_priv_data_t *p = rig->state.priv; - p->ptt = ptt; - MUTEX_UNLOCK(p->mutex); - } + MUTEX_LOCK(p->mutex); + anytone_transaction(rig, pttcmd, sizeof(ptton), NULL, 0, 0); + anytone_priv_data_t *p = rig->state.priv; + p->ptt = ptt; + MUTEX_UNLOCK(p->mutex); RETURNFUNC(retval); } diff --git a/rigs/dummy/tci1x.c b/rigs/dummy/tci1x.c index be9357786..409c1d5a1 100644 --- a/rigs/dummy/tci1x.c +++ b/rigs/dummy/tci1x.c @@ -820,11 +820,6 @@ static int tci1x_cleanup(RIG *rig) ENTERFUNC; - if (rig == NULL) - { - RETURNFUNC(-RIG_EINVAL); - } - priv = (struct tci1x_priv_data *)rig->state.priv; free(priv->ext_parms); diff --git a/rigs/flexradio/dttsp.c b/rigs/flexradio/dttsp.c index 9436fdf8e..0e03f2dfa 100644 --- a/rigs/flexradio/dttsp.c +++ b/rigs/flexradio/dttsp.c @@ -662,10 +662,9 @@ int dttsp_cleanup(RIG *rig) if (priv && priv->tuner) { rig_cleanup(priv->tuner); + priv->tuner = NULL; } - priv->tuner = NULL; - free(rig->state.priv); rig->state.priv = NULL; diff --git a/rigs/gomspace/gs100.c b/rigs/gomspace/gs100.c index 7c5e44c25..7892faaa5 100644 --- a/rigs/gomspace/gs100.c +++ b/rigs/gomspace/gs100.c @@ -99,11 +99,6 @@ static int gs100_init(RIG *rig) ENTERFUNC; - if (!rig || !rig->caps) - { - RETURNFUNC(-RIG_EINVAL); - } - priv = (struct gs100_priv_data *)calloc(1, sizeof(struct gs100_priv_data)); if (!priv) diff --git a/rigs/icom/icom.c b/rigs/icom/icom.c index bea56806c..db39e72c1 100644 --- a/rigs/icom/icom.c +++ b/rigs/icom/icom.c @@ -732,14 +732,8 @@ int icom_cleanup(RIG *rig) struct icom_priv_data *priv; int i; - if (!rig) - { - RETURNFUNC(-RIG_EINVAL); - } - ENTERFUNC; - priv = rig->state.priv; for (i = 0; rig->caps->spectrum_scopes[i].name != NULL; i++) diff --git a/rigs/kenwood/kenwood.c b/rigs/kenwood/kenwood.c index 470ed3de6..4ca6bb2a9 100644 --- a/rigs/kenwood/kenwood.c +++ b/rigs/kenwood/kenwood.c @@ -5919,11 +5919,6 @@ DECLARE_PROBERIG_BACKEND(kenwood) int write_delay = port->write_delay; short retry = port->retry; - if (!port) - { - return (RIG_MODEL_NONE); - } - if (port->type.rig != RIG_PORT_SERIAL) { return (RIG_MODEL_NONE); diff --git a/rigs/kenwood/th.c b/rigs/kenwood/th.c index 5d4f548bf..7b33928f5 100644 --- a/rigs/kenwood/th.c +++ b/rigs/kenwood/th.c @@ -1251,7 +1251,7 @@ th_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) return retval; } - if (ackbuf[4] < '0' || ackbuf[4] > '9') + if (ackbuf[4] < '0' || ackbuf[4] > '8') { return -RIG_EPROTO; } diff --git a/rigs/yaesu/newcat.c b/rigs/yaesu/newcat.c index 1a0075091..bb02f0bef 100644 --- a/rigs/yaesu/newcat.c +++ b/rigs/yaesu/newcat.c @@ -4646,7 +4646,7 @@ int newcat_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val) { rig_debug(RIG_DEBUG_TRACE, "%s: ft101 #1 val.i=%d\n", __func__, val.i); - if (val.i == 0) { val.i = 0; } + if (val.i == 0) { ; } else if (val.i <= 100) { val.i = 2; } else if (val.i <= 200) { val.i = 4; } else if (val.i > 3000) { val.i = 33; } diff --git a/rotators/flir/flir.c b/rotators/flir/flir.c index fad23c17a..ebc0fe4c7 100644 --- a/rotators/flir/flir.c +++ b/rotators/flir/flir.c @@ -165,11 +165,7 @@ static int flir_cleanup(ROT *rot) free(priv->ext_levels); free(priv->ext_parms); free(priv->magic_conf); - - if (rot->state.priv) - { - free(rot->state.priv); - } + free(rot->state.priv); rot->state.priv = NULL;