Fix Rule 14.3 detection for bounded expressions - #8819
Open
jfdeverge wants to merge 1 commit into
Open
Conversation
jfdeverge
force-pushed
the
dev/fix_misra_14_3
branch
from
August 31, 2026 15:33
a1c4a25 to
8dc01be
Compare
jfdeverge
force-pushed
the
dev/fix_misra_14_3
branch
from
August 31, 2026 16:02
8dc01be to
d37f6b1
Compare
| " if ((((sint64)((uint32)tmp)) - 1LL) < 0LL) {}\n" | ||
| " if ((((sint64)((uint32)tmp)) - 1LL) > 4294967295LL) {}\n" | ||
| "}\n", settingsUnix64); | ||
| ASSERT_EQUALS("[test.cpp:9:43]: (style) Comparing expression of type 'signed long long' against value 4294967295. Condition is always false. [compareValueOutOfTypeRangeError]\n", |
Collaborator
There was a problem hiding this comment.
The text/ID of the warning seems incorrect. 4294967295 is within range for signed long long.
Contributor
Author
There was a problem hiding this comment.
Hello! The condition is essentially (sint64), the diagnostic log is correct. But the check is only possible because there is a (uint32) inside.
Collaborator
|
I have created this ticket: https://trac.cppcheck.net/ticket/15000 |
Contributor
Author
|
I will update the commit message with Fix #15000 ... |
…ded cast/arithmetic expressions
jfdeverge
force-pushed
the
dev/fix_misra_14_3
branch
from
September 1, 2026 12:26
d37f6b1 to
3e3fa63
Compare
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.
There was missing detection of 'MISRA C:2012 Rule 14.3" on some specific code structure generated by Matlab Simulink coder.
We identified these issues by comparing its results with reports previously generated by our company’s internal tool on the same software.
The bug report would have looked like below.
Problem
Cppcheck did not report a MISRA C:2012 Rule 14.3 violation when a comparison
used an integer expression whose range was provably bounded by casts and
constant arithmetic. The existing check handled a variable compared with a
value outside the variable's declared type range, but did not evaluate this
equivalent expression form.
Minimal Reproducer
After the clamp and casts, the left-hand expression cannot exceed
UINT32_MAX - 1. Therefore the final condition is always false and shouldproduce the
compareValueOutOfTypeRangeErrordiagnostic, which the MISRApostprocessor maps to Rule 14.3.
Observed Behavior
Before the fix, the final comparison produced no diagnostic. This allowed the
generated-code pattern to pass through the cppcheck-based MISRA pipeline
without the expected Rule 14.3 finding.
Fix
The condition checker now:
or subtraction by constant expressions;
provably always true or always false; and
compareValueOutOfTypeRangeErrordiagnostic path.Uncertain or unsupported ranges remain unreported to avoid speculative
findings. Interval arithmetic includes overflow guards.
Regression Coverage
The exact typedef-based reproducer is covered by
TestCondition::compareOutOfTypeRangeintest/testcondition.cpp. The focusedtest, the complete
TestConditionsuite, and the registered CTest target passwith the fix.