sched/spawn: Fix MISRA C 2012 Rule 10.4 violations

Fix violations of MISRA C:2012 Rule 10.4 (essential type operand of
unsigned and signed) in posix_spawn attribute handling code.

Changed all POSIX_SPAWN_* flag macro definitions to use unsigned literals
(1u instead of 1) to ensure consistent unsigned arithmetic when performing
bitwise operations. This eliminates mixed signed/unsigned operand violations
in the following flags:

- POSIX_SPAWN_RESETIDS
- POSIX_SPAWN_SETPGROUP
- POSIX_SPAWN_SETSCHEDPARAM
- POSIX_SPAWN_SETSCHEDULER
- POSIX_SPAWN_SETSIGDEF
- POSIX_SPAWN_SETSIGMASK
- POSIX_SPAWN_SETSID

Updated all flag checking comparisons in spawn_execattrs() to compare
against 0u instead of 0 for consistency.

Signed-off-by: fangxinyong <fangxinyong@xiaomi.com>
This commit is contained in:
fangxinyong
2026-02-02 16:20:42 +08:00
committed by Xiang Xiao
parent 9ae2fce3c1
commit 2b9506bc5d
2 changed files with 12 additions and 12 deletions
+7 -7
View File
@@ -48,13 +48,13 @@
* posix_spawnattr_t object using the posix_spawnattr_setflags() function:" * posix_spawnattr_t object using the posix_spawnattr_setflags() function:"
*/ */
#define POSIX_SPAWN_RESETIDS (1 << 0) /* 1: Reset effective user ID */ #define POSIX_SPAWN_RESETIDS (1u << 0) /* 1: Reset effective user ID */
#define POSIX_SPAWN_SETPGROUP (1 << 1) /* 1: Set process group */ #define POSIX_SPAWN_SETPGROUP (1u << 1) /* 1: Set process group */
#define POSIX_SPAWN_SETSCHEDPARAM (1 << 2) /* 1: Set task's priority */ #define POSIX_SPAWN_SETSCHEDPARAM (1u << 2) /* 1: Set task's priority */
#define POSIX_SPAWN_SETSCHEDULER (1 << 3) /* 1: Set task's scheduler policy */ #define POSIX_SPAWN_SETSCHEDULER (1u << 3) /* 1: Set task's scheduler policy */
#define POSIX_SPAWN_SETSIGDEF (1 << 4) /* 1: Set default signal actions */ #define POSIX_SPAWN_SETSIGDEF (1u << 4) /* 1: Set default signal actions */
#define POSIX_SPAWN_SETSIGMASK (1 << 5) /* 1: Set sigmask */ #define POSIX_SPAWN_SETSIGMASK (1u << 5) /* 1: Set sigmask */
#define POSIX_SPAWN_SETSID (1 << 7) /* 1: Create the new session(glibc specific) */ #define POSIX_SPAWN_SETSID (1u << 7) /* 1: Create the new session(glibc specific) */
/* NOTE: NuttX provides only one implementation: If /* NOTE: NuttX provides only one implementation: If
* CONFIG_LIBC_ENVPATH is defined, then only posix_spawnp() behavior * CONFIG_LIBC_ENVPATH is defined, then only posix_spawnp() behavior
+5 -5
View File
@@ -158,7 +158,7 @@ int spawn_execattrs(pid_t pid, FAR const posix_spawnattr_t *attr)
/* Firstly, set the signal mask if requested to do so */ /* Firstly, set the signal mask if requested to do so */
#ifndef CONFIG_DISABLE_ALL_SIGNALS #ifndef CONFIG_DISABLE_ALL_SIGNALS
if ((attr->flags & POSIX_SPAWN_SETSIGMASK) != 0) if ((attr->flags & POSIX_SPAWN_SETSIGMASK) != 0u)
{ {
FAR struct tcb_s *tcb = nxsched_get_tcb(pid); FAR struct tcb_s *tcb = nxsched_get_tcb(pid);
if (tcb) if (tcb)
@@ -172,7 +172,7 @@ int spawn_execattrs(pid_t pid, FAR const posix_spawnattr_t *attr)
* to set the priority of the of the new task. * to set the priority of the of the new task.
*/ */
if ((attr->flags & POSIX_SPAWN_SETSCHEDPARAM) != 0) if ((attr->flags & POSIX_SPAWN_SETSCHEDPARAM) != 0u)
{ {
#ifdef CONFIG_SCHED_SPORADIC #ifdef CONFIG_SCHED_SPORADIC
/* Get the current sporadic scheduling parameters. Those will not be /* Get the current sporadic scheduling parameters. Those will not be
@@ -192,7 +192,7 @@ int spawn_execattrs(pid_t pid, FAR const posix_spawnattr_t *attr)
* then we will call nxsched_set_scheduler() below. * then we will call nxsched_set_scheduler() below.
*/ */
if ((attr->flags & POSIX_SPAWN_SETSCHEDULER) == 0) if ((attr->flags & POSIX_SPAWN_SETSCHEDULER) == 0u)
{ {
sinfo("Setting priority=%d for pid=%d\n", sinfo("Setting priority=%d for pid=%d\n",
param.sched_priority, pid); param.sched_priority, pid);
@@ -207,7 +207,7 @@ int spawn_execattrs(pid_t pid, FAR const posix_spawnattr_t *attr)
* preparation for the nxsched_set_scheduler() call below. * preparation for the nxsched_set_scheduler() call below.
*/ */
else if ((attr->flags & POSIX_SPAWN_SETSCHEDULER) != 0) else if ((attr->flags & POSIX_SPAWN_SETSCHEDULER) != 0u)
{ {
ret = nxsched_get_param(0, &param); ret = nxsched_get_param(0, &param);
} }
@@ -216,7 +216,7 @@ int spawn_execattrs(pid_t pid, FAR const posix_spawnattr_t *attr)
* setting determined above. * setting determined above.
*/ */
if (ret == OK && (attr->flags & POSIX_SPAWN_SETSCHEDULER) != 0) if (ret == OK && (attr->flags & POSIX_SPAWN_SETSCHEDULER) != 0u)
{ {
sinfo("Setting policy=%d priority=%d for pid=%d\n", sinfo("Setting policy=%d priority=%d for pid=%d\n",
attr->policy, param.sched_priority, pid); attr->policy, param.sched_priority, pid);