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 1d638d0f5eb57a19e435fd3b0bf1ba79c0b25794 Author: makejian <[email protected]> AuthorDate: Wed Nov 25 13:07:13 2026 +0800 signal: fix nxsig_kill misra coverity Keep one exit path in nxsig_kill(): 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. The path for a process-group pid and the zero-initialization of the siginfo structure that master added stay unchanged. Signed-off-by: makejian <[email protected]> Signed-off-by: zhangyuan29 <[email protected]> --- sched/signal/sig_kill.c | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/sched/signal/sig_kill.c b/sched/signal/sig_kill.c index 325ae385353..fc376326357 100644 --- a/sched/signal/sig_kill.c +++ b/sched/signal/sig_kill.c @@ -170,6 +170,7 @@ int nxsig_kill(pid_t pid, int signo) #endif #ifndef CONFIG_DISABLE_ALL_SIGNALS siginfo_t info; + int ret = -EINVAL; #endif #ifdef CONFIG_SCHED_PROCESS_GROUPS @@ -217,33 +218,31 @@ int nxsig_kill(pid_t pid, int signo) #else /* Make sure that the signal is valid */ - if (!GOOD_SIGNO(signo)) + if (GOOD_SIGNO(signo)) { - return -EINVAL; - } - - /* Create the siginfo structure */ - - /* Zero the whole siginfo first: sigaction-queued signals carry a - * si_user field that only the sigaction queue path assigns, so a - * stack-garbage si_user here would be memcpy'd into the pending - * entry and handed back to a sigtimedwait() consumer. - */ + /* Zero the whole siginfo first: sigaction-queued signals carry a + * si_user field that only the sigaction queue path assigns, so a + * stack-garbage si_user here would be memcpy'd into the pending + * entry and handed back to a sigtimedwait() consumer. + */ - memset(&info, 0, sizeof(siginfo_t)); - info.si_signo = signo; - info.si_code = SI_USER; - info.si_errno = EINTR; - info.si_value.sival_ptr = NULL; + memset(&info, 0, sizeof(siginfo_t)); + info.si_signo = signo; + info.si_code = SI_USER; + info.si_errno = EINTR; + info.si_value.sival_ptr = NULL; #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 - /* Send the signal */ + /* Send the signal */ + + ret = nxsig_dispatch(pid, &info, false, NULL, false); + } - return nxsig_dispatch(pid, &info, false, NULL, false); + return ret; #endif }
