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 7aa08669f81002d7aff53d736c1d1cbc4af182d1 Author: makejian <[email protected]> AuthorDate: Wed Nov 25 13:08:42 2026 +0800 signal: fix nxsig_timedwait misra coverity Keep one exit path in the wait loop of nxsig_timedwait(): re-enter the critical section and evaluate the wakening cause inside the branch that handles the successful wait, nest the signal-member and timeout tests instead of leaving the section early, and hold the result in the existing variable, as the MISRA C:2012 guidelines require. The stack-local siginfo buffer unbinfo that master uses, and the copy to the caller's buffer, stay unchanged. Signed-off-by: makejian <[email protected]> Signed-off-by: zhangyuan29 <[email protected]> --- sched/signal/sig_timedwait.c | 96 +++++++++++++++++++++++--------------------- 1 file changed, 51 insertions(+), 45 deletions(-) diff --git a/sched/signal/sig_timedwait.c b/sched/signal/sig_timedwait.c index 30a53268133..cce6776e743 100644 --- a/sched/signal/sig_timedwait.c +++ b/sched/signal/sig_timedwait.c @@ -194,73 +194,79 @@ int nxsig_timedwait(FAR const sigset_t *set, FAR struct siginfo *info, ret = nxsig_clockwait(CLOCK_REALTIME, 0, timeout, NULL); if (ret < 0) { + /* No wait happened: the mask was never consumed. Clear it, or + * an ignored signal of the set wakes a later nanosleep(). + */ + sigemptyset(&rtcb->sigwaitmask); rtcb->sigunbinfo = NULL; return ret; } + else + { + flags = enter_critical_section(); - flags = enter_critical_section(); - - /* We are running again, clear the sigwaitmask */ - - sigemptyset(&rtcb->sigwaitmask); + /* We are running again, clear the sigwaitmask */ - /* When we awaken, the cause will be in the TCB. Get the signal number - * or timeout) that awakened us. - */ + sigemptyset(&rtcb->sigwaitmask); - if (GOOD_SIGNO(unbinfo.si_signo)) - { - /* We were awakened by a signal... but is it one of the signals - * that we were waiting for? + /* When we awaken, the cause will be in the TCB. + * Get the signal number or timeout that awakened us. */ - if (nxsig_ismember(set, unbinfo.si_signo) == 1) + if (GOOD_SIGNO(unbinfo.si_signo)) { - /* Yes.. the return value is the number of the signal that - * awakened us. + /* We were awakened by a signal... but is it one of the + * signals that we were waiting for? */ - ret = unbinfo.si_signo; - } - else - { - /* No... then report the EINTR error */ + if (nxsig_ismember(set, unbinfo.si_signo) == 1) + { + /* Yes.. the return value is the number of the signal + * that awakened us. + */ - ret = -EINTR; - } - } - else - { - /* Otherwise, we must have been awakened by the timeout or, - * perhaps, the wait was cancelled. - */ + ret = unbinfo.si_signo; + } + else + { + /* No... then report the EINTR error */ -#ifdef CONFIG_CANCELLATION_POINTS - if (unbinfo.si_signo == SIG_CANCEL_TIMEOUT) - { - /* The wait was canceled */ - - ret = -unbinfo.si_errno; - DEBUGASSERT(ret < 0); + ret = -EINTR; + } } else -#endif { - /* We were awakened by a timeout. Set EAGAIN and return an - * error. + /* Otherwise, we must have been awakened by the timeout or, + * perhaps, the wait was cancelled. */ - DEBUGASSERT(unbinfo.si_signo == SIG_WAIT_TIMEOUT); - ret = -EAGAIN; +#ifdef CONFIG_CANCELLATION_POINTS + if (unbinfo.si_signo == SIG_CANCEL_TIMEOUT) + { + /* The wait was canceled */ + + ret = -unbinfo.si_errno; + DEBUGASSERT(ret < 0); + } + else +#endif + { + /* We were awakened by a timeout. Set EAGAIN and return + * an error. + */ + + DEBUGASSERT(unbinfo.si_signo == SIG_WAIT_TIMEOUT); + ret = -EAGAIN; + } } - } - rtcb->sigunbinfo = NULL; + rtcb->sigunbinfo = NULL; - if (info != NULL) - { - memcpy(info, &unbinfo, sizeof(struct siginfo)); + if (info != NULL) + { + memcpy(info, &unbinfo, sizeof(struct siginfo)); + } } }
