fxysunshine opened a new pull request, #18307: URL: https://github.com/apache/nuttx/pull/18307
## Summary This PR fixes MISRA C:2012 Rule 10.4 violations in posix_spawn attribute handling code by ensuring consistent use of unsigned operands in bitwise operations. ### Changes Made Modified all `POSIX_SPAWN_*` flag macro definitions and their usage sites to use unsigned literals: **Macro definitions** (`include/spawn.h`): - `POSIX_SPAWN_RESETIDS`: Changed from `(1 << 0)` to `(1u << 0)` - `POSIX_SPAWN_SETPGROUP`: Changed from `(1 << 1)` to `(1u << 1)` - `POSIX_SPAWN_SETSCHEDPARAM`: Changed from `(1 << 2)` to `(1u << 2)` - `POSIX_SPAWN_SETSCHEDULER`: Changed from `(1 << 3)` to `(1u << 3)` - `POSIX_SPAWN_SETSIGDEF`: Changed from `(1 << 4)` to `(1u << 4)` - `POSIX_SPAWN_SETSIGMASK`: Changed from `(1 << 5)` to `(1u << 5)` - `POSIX_SPAWN_SETSID`: Changed from `(1 << 7)` to `(1u << 7)` **Usage sites** (`sched/task/task_spawnparms.c`): - Updated 5 flag checking comparisons in `spawn_execattrs()` to compare against `0u` instead of `0` ### Why This Change is Needed MISRA C:2012 Rule 10.4 prohibits mixing signed and unsigned operands in arithmetic operations. The original code violated this rule by: 1. Using signed integer literals (`1`) in bit shift operations for flag definitions 2. Comparing bitwise results against signed zero (`0`) This could lead to: - Undefined behavior in edge cases - Compiler warnings in strict compliance mode - Potential portability issues across different platforms ## Impact **Stability**: No impact - purely type-safety improvements **Compatibility**: No breaking changes - all modifications preserve existing POSIX spawn behavior **Code Quality**: Positive - eliminates 12 MISRA C:2012 Rule 10.4 violations ## Testing ### Test Environment - **Host**: Ubuntu 22.04 x86_64 - **Toolchain**: GCC 11.4.0 - **Target**: sim:nsh configuration - **Build**: CMake + Ninja ### Test Steps 1. **Build verification**: ```bash cd nuttx cmake -B build -DBOARD_CONFIG=sim:nsh -GNinja ninja -C build -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
