This is an automated email from the ASF dual-hosted git repository. xiaoxiang781216 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit dadf797e70019d0c17081647fb3c50b55ed126d2 Author: makejian <[email protected]> AuthorDate: Mon Oct 20 11:38:10 2025 +0800 signal: fix clock_nanosleep misra coverity Restructure clock_nanosleep() to a single exit path: keep the result in one variable, test the clockid range in the positive form, and drop the early returns, as the MISRA C:2012 guidelines require. Signed-off-by: makejian <[email protected]> --- sched/signal/sig_nanosleep.c | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/sched/signal/sig_nanosleep.c b/sched/signal/sig_nanosleep.c index bf719cbae24..20717667e00 100644 --- a/sched/signal/sig_nanosleep.c +++ b/sched/signal/sig_nanosleep.c @@ -117,33 +117,30 @@ int clock_nanosleep(clockid_t clockid, int flags, FAR const struct timespec *rqtp, FAR struct timespec *rmtp) { - int ret; + int ret = EINVAL; /* clock_nanosleep() is a cancellation point */ enter_cancellation_point(); - if (clockid < CLOCK_REALTIME || clockid > CLOCK_BOOTTIME) + if (clockid >= CLOCK_REALTIME && clockid <= CLOCK_BOOTTIME) { - leave_cancellation_point(); - return EINVAL; - } - - /* Just a wrapper around nxsig_clockwait() */ + /* Just a wrapper around nxsig_clockwait() */ - ret = nxsig_clockwait(clockid, flags, rqtp, rmtp); + ret = nxsig_clockwait(clockid, flags, rqtp, rmtp); - /* Check if nxsig_clockwait() succeeded */ + /* Check if nxsig_clockwait() succeeded */ - if (ret == -EAGAIN) - { - ret = OK; - } - else if (ret < 0) - { - /* If not return the errno */ + if (ret == -EAGAIN) + { + ret = OK; + } + else if (ret < 0) + { + /* If not return the errno */ - ret = -ret; + ret = -ret; + } } leave_cancellation_point();
