Repository navigation
Fix #15265 FP uninitvar: ProgramMemoryState::assume() drops a condition on a variable assigned an unknown value - #9067
Draft
autoantwort wants to merge 1 commit into
Draft
autoantwort wants to merge 1 commit into
autoantwort wants to merge 1 commit into
Conversation
…on on a variable assigned an unknown value A variable assigned an unknown value is stored in the program memory as unknown. Since 35dc425 (#13930) ProgramMemoryState::replace() keeps an unknown value (skipUnknown), and assume() stores the state with the condition applied through it, so the condition is dropped: on the false path of 'if (err == 0)' err is not known to be non-zero. 4b66976 (#15042) made this visible in more cases. The true path that is assumed again at the end of its block keeps an unknown value as before: with the condition, the path past the if knows values that the forward analysis does not lower when only other paths modify the tracked value (knownConditionTrueFalse FP). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Trac: https://trac.cppcheck.net/ticket/15265
On the path where
err == 0is falsesqis not set, but thensqis not read either.Cause:
int err = calcA();storeserrin the program memory as an unknown value.ProgramMemoryState::assume()applies the condition (err == 0is false) to a copy of the state and stores it withProgramMemoryState::replace(), which since 35dc425 (#13930) usesskipUnknown = trueand so keeps the unknown value oferr: the condition is lost. 4b66976 (#15042) made this visible in more cases (e.g. when the read is inside anotherif).Fix:
assume()stores the state with the condition applied withoutskipUnknown. Exception: when the true path is assumed again at the end of its block (origin != nullptr, to carry it past theif)skipUnknownstays, otherwise the path past theifknows values that the forward analysis does not lower when only other paths modify the tracked value (new knownConditionTrueFalse FP, covered byTestCondition::knownConditionAfterIfNull).Not fixed here:
legacyUninitvarerror in the second example of the ticket.pis a parameter (since 4b66976); that is a separate issue of the forward analysis.Verification: new tests fail without the fix,
testrunnerpasses. On a large internal code base (checked together with the fixes for #15264, #15266 and #15267) the only change from this fix vs main is the removed FP.This PR was created by Claude Code (an AI coding agent) on behalf of @autoantwort.
🤖 Generated with Claude Code