fxysunshine opened a new pull request, #18306:
URL: https://github.com/apache/nuttx/pull/18306

   ## Summary
   
   This PR fixes MISRA C:2012 Rule 10.4 violations in cancellation point 
handling code by ensuring consistent use of unsigned operands in bitwise 
operations.
   
   ### Changes Made
   
   Modified all `CANCEL_FLAG_*` macro definitions and their usage sites to use 
unsigned literals (`1u` instead of `1`):
   
   **Macro definitions** (`include/nuttx/cancelpt.h`):
   - `CANCEL_FLAG_NONCANCELABLE`: Changed from `(1 << 0)` to `(1u << 0)`
   - `CANCEL_FLAG_CANCEL_ASYNC`: Changed from `(1 << 1)` to `(1u << 1)`
   - `CANCEL_FLAG_CANCEL_PENDING`: Changed from `(1 << 2)` to `(1u << 2)`
   
   **Usage sites** (18 locations across 4 files):
   - `libs/libc/sched/task_cancelpt.c`: 7 comparisons updated
   - `libs/libc/sched/task_setcancelstate.c`: 3 comparisons updated
   - `libs/libc/sched/task_setcanceltype.c`: 3 comparisons updated
   - `sched/task/task_cancelpt.c`: 2 comparisons updated
   
   All bitwise AND operations now compare against `0u` instead of `0` to 
maintain unsigned arithmetic consistency.
   
   ### 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
   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 
behavior
   **Code Quality**: Positive - eliminates 18 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]

Reply via email to