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 d72ca5310f2163d998615df2da847224e0615564
Author: makejian <[email protected]>
AuthorDate: Mon Oct 27 16:55:18 2025 +0800

    signal: fix nxsig_usleep misra coverity
    
    The useconds_t to struct timespec conversion mixed time_t and unsigned
    arithmetic; Coverity flags the implicit conversions.  Rewrite the
    seconds/nanoseconds split with explicit div/mod and casts.
    
    Signed-off-by: makejian <[email protected]>
    Signed-off-by: zhangyuan29 <[email protected]>
---
 sched/signal/sig_usleep.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/sched/signal/sig_usleep.c b/sched/signal/sig_usleep.c
index 99825f5e9ff..46a06557b8b 100644
--- a/sched/signal/sig_usleep.c
+++ b/sched/signal/sig_usleep.c
@@ -70,16 +70,14 @@
 int nxsig_usleep(useconds_t usec)
 {
   struct timespec rqtp;
-  time_t sec;
   int ret = 0;
 
   if (usec)
     {
       /* Let nxsig_nanosleep() do all of the work. */
 
-      sec          = USEC2SEC(usec);
-      rqtp.tv_sec  = sec;
-      rqtp.tv_nsec = (usec - (sec * USEC_PER_SEC)) * NSEC_PER_USEC;
+      rqtp.tv_sec  = (time_t)(usec / (useconds_t)USEC_PER_SEC);
+      rqtp.tv_nsec = (long)(usec % (useconds_t)USEC_PER_SEC) * NSEC_PER_USEC;
 
       ret = nxsig_nanosleep(&rqtp, NULL);
     }

Reply via email to