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

   ## Summary
   
   This PR addresses multiple MISRA C:2012 compliance violations in 
`sched/misc/assert.c` to improve code quality and safety standards.
   
   ### Changes Made
   
   1. **Restrict global symbol scope**: Moved global variables (`g_policy`, 
`g_ttypenames`, `g_assert_lock`) to code block scope to minimize global 
variable visibility and comply with MISRA rules requiring limited scope.
   
   2. **Resolve type mismatch**: Fixed violations related to mixed 
signed/unsigned arithmetic by adding explicit unsigned suffixes (`0u`, `8u`, 
`10u`, etc.) to numeric literals used in pointer arithmetic and comparisons.
   
   3. **Correct pointer type conversion**: Improved pointer casting from 
`uintptr_t` to `void*` by using proper format specifiers (`PRIxPTR`) instead of 
direct pointer casting, ensuring safe and compliant pointer operations.
   
   ### Why This Change is Needed
   
   MISRA C:2012 is a widely adopted coding standard for safety-critical 
systems. These violations could lead to:
   - Unintended side effects from global variable access
   - Undefined behavior from mixed signed/unsigned operations
   - Potential pointer aliasing issues
   
   This change improves code safety and maintainability without affecting 
functionality.
   
   ## Impact
   
   **Stability**: No impact - changes are purely cosmetic and improve code 
quality
   **Compatibility**: No breaking changes - all modifications are internal to 
assert.c
   **Code Quality**: Positive - improves MISRA C:2012 compliance
   
   ## 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