Skip to content

Fix MISRA 10.8 violation in okj_measure_container#68

Merged
ionux merged 4 commits into
mainfrom
claude/fix-misra-cast-violation-L4MMg
Mar 25, 2026
Merged

Fix MISRA 10.8 violation in okj_measure_container#68
ionux merged 4 commits into
mainfrom
claude/fix-misra-cast-violation-L4MMg

Conversation

@ionux

@ionux ionux commented Mar 25, 2026

Copy link
Copy Markdown
Owner

Summary\n\n- Replace (uint16_t)(p - start) pointer-subtraction cast with an incrementally maintained uint16_t len counter\n- This avoids casting a composite expression (ptrdiff_t) to a different essential type category, which violates MISRA Rule 10.8\n- All existing tests pass\n\n## Test plan\n\n- [x] Full test suite passes (make clean && make)\n- [ ] Verify with MISRA static analysis tooling that Rule 10.8 is no longer flagged for okj_measure_container\n\nhttps://claude.ai/code/session_01L2o12dqmUBCrvj7Lo2WExs

claude added 4 commits March 25, 2026 02:35
Replace pointer-subtraction cast `(uint16_t)(p - start)` with
an incrementally maintained uint16_t counter, avoiding a cast
from a composite expression (ptrdiff_t) to a different essential
type category.

https://claude.ai/code/session_01L2o12dqmUBCrvj7Lo2WExs
Add `len == p - start` invariant to both the outer and inner loops
in okj_measure_container so the WP plugin can prove the postcondition
`\result <= end - start` without timeout.

https://claude.ai/code/session_01L2o12dqmUBCrvj7Lo2WExs
Add `assert len == p - start` after each paired p++/len++ site
so the prover can maintain the loop invariant across all control
flow paths without timing out.

https://claude.ai/code/session_01L2o12dqmUBCrvj7Lo2WExs
Replace the len-counter approach (which introduced Frama-C
timeouts) with a simpler decomposition: store the pointer
difference in a local `long` variable before casting to
uint16_t. This makes the cast operand a simple lvalue rather
than a composite expression, satisfying MISRA 10.8 without
changing any loop logic or Frama-C annotations.

https://claude.ai/code/session_01L2o12dqmUBCrvj7Lo2WExs
@ionux ionux merged commit f385ef3 into main Mar 25, 2026
3 checks passed
@ionux ionux deleted the claude/fix-misra-cast-violation-L4MMg branch March 25, 2026 03:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants