Fix MISRA 10.8 violation in okj_measure_container#68
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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\n\n- Replace
(uint16_t)(p - start)pointer-subtraction cast with an incrementally maintaineduint16_t lencounter\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 forokj_measure_container\n\nhttps://claude.ai/code/session_01L2o12dqmUBCrvj7Lo2WExs