From 72bde6e13171e1c2425e094413598ec88a8397a0 Mon Sep 17 00:00:00 2001 From: Daniele Forsi IU5HKX Date: Fri, 30 May 2025 22:56:37 +0200 Subject: [PATCH] Fix sign of error return values All RIG_E* constants should be negated when returned or compared. Change the usages of RIG_IS_SOFT_ERRCODE() for consistency. --- include/hamlib/rig.h | 8 ++++---- tests/rigctl.c | 4 ++-- tests/rigctld.c | 4 ++-- tests/rigctltcp.c | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/include/hamlib/rig.h b/include/hamlib/rig.h index 6656c5aeb..8f6326d01 100644 --- a/include/hamlib/rig.h +++ b/include/hamlib/rig.h @@ -222,10 +222,10 @@ enum rig_errcode_e { * Soft errors are caused by invalid parameters and software/hardware features * and cannot be fixed by retries or by re-initializing hardware. */ -#define RIG_IS_SOFT_ERRCODE(errcode) (errcode == RIG_EINVAL || errcode == RIG_ENIMPL || errcode == RIG_ERJCTED \ - || errcode == RIG_ETRUNC || errcode == RIG_ENAVAIL || errcode == RIG_ENTARGET \ - || errcode == RIG_EVFO || errcode == RIG_EDOM || errcode == RIG_EDEPRECATED \ - || errcode == RIG_ESECURITY || errcode == RIG_EPOWER) +#define RIG_IS_SOFT_ERRCODE(errcode) (errcode == -RIG_EINVAL || errcode == -RIG_ENIMPL || errcode == -RIG_ERJCTED \ + || errcode == -RIG_ETRUNC || errcode == -RIG_ENAVAIL || errcode == -RIG_ENTARGET \ + || errcode == -RIG_EVFO || errcode == -RIG_EDOM || errcode == -RIG_EDEPRECATED \ + || errcode == -RIG_ESECURITY || errcode == -RIG_EPOWER) /** * \brief Token in the netrigctl protocol for returning error code diff --git a/tests/rigctl.c b/tests/rigctl.c index a262d32f3..e04ff7e8f 100644 --- a/tests/rigctl.c +++ b/tests/rigctl.c @@ -816,7 +816,7 @@ int main(int argc, char *argv[]) // if we get a hard error we try to reopen the rig again // this should cover short dropouts that can occur - if (retcode < 0 && !RIG_IS_SOFT_ERRCODE(-retcode)) + if (retcode < 0 && !RIG_IS_SOFT_ERRCODE(retcode)) { int retry = 3; rig_debug(RIG_DEBUG_ERR, "%s: i/o error\n", __func__); @@ -833,7 +833,7 @@ int main(int argc, char *argv[]) while (retry-- > 0 && retcode != RIG_OK); } } - while (!ctrl_c && (retcode == RIG_OK || RIG_IS_SOFT_ERRCODE(-retcode))); + while (!ctrl_c && (retcode == RIG_OK || RIG_IS_SOFT_ERRCODE(retcode))); if (interactive && prompt) { diff --git a/tests/rigctld.c b/tests/rigctld.c index 9ffb01a6f..4435c26ca 100644 --- a/tests/rigctld.c +++ b/tests/rigctld.c @@ -1282,7 +1282,7 @@ void *handle_socket(void *arg) // if we get a hard error we try to reopen the rig again // this should cover short dropouts that can occur - if (retcode < 0 && !RIG_IS_SOFT_ERRCODE(-retcode)) + if (retcode < 0 && !RIG_IS_SOFT_ERRCODE(retcode)) { int retry = 3; rig_debug(RIG_DEBUG_ERR, "%s: i/o error\n", __func__); @@ -1312,7 +1312,7 @@ void *handle_socket(void *arg) while (!ctrl_c && !rig_opened && retry-- > 0 && retcode != RIG_OK); } } - while (!ctrl_c && (retcode == RIG_OK || RIG_IS_SOFT_ERRCODE(-retcode))); + while (!ctrl_c && (retcode == RIG_OK || RIG_IS_SOFT_ERRCODE(retcode))); #if defined(HAVE_PTHREAD) diff --git a/tests/rigctltcp.c b/tests/rigctltcp.c index a9eaa9dc7..17d40be6e 100644 --- a/tests/rigctltcp.c +++ b/tests/rigctltcp.c @@ -1283,7 +1283,7 @@ void *handle_socket(void *arg) // if we get a hard error we try to reopen the rig again // this should cover short dropouts that can occur - if (retcode < 0 && !RIG_IS_SOFT_ERRCODE(-retcode)) + if (retcode < 0 && !RIG_IS_SOFT_ERRCODE(retcode)) { int retry = 3; rig_debug(RIG_DEBUG_ERR, "%s: i/o error\n", __func__); @@ -1313,7 +1313,7 @@ void *handle_socket(void *arg) while (!ctrl_c && !rig_opened && retry-- > 0 && retcode != RIG_OK); } } - while (!ctrl_c && (retcode == RIG_OK || RIG_IS_SOFT_ERRCODE(-retcode))); + while (!ctrl_c && (retcode == RIG_OK || RIG_IS_SOFT_ERRCODE(retcode))); client_done: