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 afd2baf9ab6b4d6bbf273fb29a59ab6957f62235
Author: makejian <[email protected]>
AuthorDate: Wed Nov 25 13:03:15 2026 +0800

    signal: fix nxsig_queue misra coverity
    
    Keep one exit path in nxsig_queue_send(): hold the result in a local
    variable for the dispatch instead of returning from the middle of the
    function, and test the signal number in the positive form, as the
    MISRA C:2012 guidelines require.
    
    On master the logic of nxsig_queue() lives in nxsig_queue_send(), which
    also serves sigqueue(), so the rework is applied there.
    
    Signed-off-by: makejian <[email protected]>
    Signed-off-by: zhangyuan29 <[email protected]>
---
 sched/signal/sig_queue.c | 32 +++++++++++++++++---------------
 1 file changed, 17 insertions(+), 15 deletions(-)

diff --git a/sched/signal/sig_queue.c b/sched/signal/sig_queue.c
index b52b3d5fa62..ad75891e55f 100644
--- a/sched/signal/sig_queue.c
+++ b/sched/signal/sig_queue.c
@@ -59,31 +59,33 @@ static int nxsig_queue_send(int pid, int signo, union 
sigval value,
 #endif
   siginfo_t info;
 
+  int ret = -EINVAL;
+
   sinfo("pid=0x%08x signo=%d value=%d\n", pid, signo, value.sival_int);
 
   /* Sanity checks */
 
-  if (!GOOD_SIGNO(signo))
+  if (GOOD_SIGNO(signo))
     {
-      return -EINVAL;
-    }
-
-  /* Create the siginfo structure */
+      /* Create the siginfo structure */
 
-  info.si_signo = signo;
-  info.si_code = SI_QUEUE;
-  info.si_errno = OK;
-  info.si_value = value;
+      info.si_signo = signo;
+      info.si_code = SI_QUEUE;
+      info.si_errno = OK;
+      info.si_value = value;
 #ifdef CONFIG_SCHED_HAVE_PARENT
-  info.si_pid = rtcb->pid;
-  info.si_uid = getuid();
-  info.si_status = OK;
+      info.si_pid = rtcb->pid;
+      info.si_uid = getuid();
+      info.si_status = OK;
 #endif
-  info.si_user = NULL; /* Will be set in sig_dispatch.c */
+      info.si_user = NULL; /* Will be set in sig_dispatch.c */
 
-  /* Send the signal */
+      /* Send the signal */
 
-  return nxsig_dispatch(pid, &info, false, NULL, limit);
+      ret = nxsig_dispatch(pid, &info, false, NULL, limit);
+    }
+
+  return ret;
 }
 
 /****************************************************************************

Reply via email to