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 ee46778c9d0133292f96f5ae02e150e6245ffadb Author: makejian <[email protected]> AuthorDate: Wed Nov 25 13:03:46 2026 +0800 signal: fix nxsig_sleep misra coverity Keep one exit path in nxsig_sleep(): initialize remaining once, drop the local variable that only held the nanosleep() result, and compare the seconds argument against the unsigned literal 0u. The remaining time is clamped with MAX() as 32e0d6806a3 does on master. Signed-off-by: makejian <[email protected]> Signed-off-by: zhangyuan29 <[email protected]> --- sched/signal/sig_sleep.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/sched/signal/sig_sleep.c b/sched/signal/sig_sleep.c index c70e9227652..ad4198b1437 100644 --- a/sched/signal/sig_sleep.c +++ b/sched/signal/sig_sleep.c @@ -74,25 +74,22 @@ unsigned int nxsig_sleep(unsigned int seconds) struct timespec rqtp; struct timespec rmtp; unsigned int remaining = 0; - int ret; /* Don't sleep if seconds == 0 */ - if (seconds > 0) + if (seconds > 0u) { /* Let nxsig_nanosleep() do all of the work. */ - rqtp.tv_sec = seconds; + rqtp.tv_sec = (time_t)seconds; rqtp.tv_nsec = 0; - ret = nxsig_nanosleep(&rqtp, &rmtp); - - /* nanosleep() should only fail if it was interrupted by a signal, - * but we treat all errors the same, - */ - - if (ret < 0) + if (nxsig_nanosleep(&rqtp, &rmtp) < 0) { + /* nanosleep() should only fail if it was interrupted by a signal, + * but we treat all errors the same, + */ + remaining = (unsigned int)MAX(rmtp.tv_sec, 0); if (remaining < seconds && rmtp.tv_nsec >= 500000000) { @@ -101,9 +98,7 @@ unsigned int nxsig_sleep(unsigned int seconds) remaining++; } } - - return remaining; } - return 0; + return remaining; }
