sched: Fix CANCEL_FLAG_* macro definitions MISRA C:2012 Rule 10.4 violations #18306
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 (1uinstead of1):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 updatedlibs/libc/sched/task_setcancelstate.c: 3 comparisons updatedlibs/libc/sched/task_setcanceltype.c: 3 comparisons updatedsched/task/task_cancelpt.c: 2 comparisons updatedAll bitwise AND operations now compare against
0uinstead of0to 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) in bit shift operations0)This could lead to:
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
Test Steps
cd nuttx cmake -B build -DBOARD_CONFIG=sim:nsh -GNinja cmake --build build -j