Repository navigation
Fix #15006: FP invalidFree with new array #8880
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
5049fe0
9932a2d
457bc1f
060a665
a32cd61
192c2ee
7be7430
e8ebeee
cd85f60
ff2b855
6eac65f
873d25a
307b0d3
6820464
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3741,6 +3741,34 @@ static void valueFlowSymbolicOperators(const SymbolDatabase& symboldatabase, con | |
| continue; | ||
| if (Token::Match(tok, "<<|>>|/|-") && !astIsLHS(vartok)) | ||
| continue; | ||
| if (Token::Match(tok, "+|-") && constant->intvalue != 0) { | ||
|
ludviggunne marked this conversation as resolved.
|
||
| const ValueType *varVt = vartok->valueType(); | ||
| const ValueType *tokVt = tok->valueType(); | ||
| if (varVt && tokVt && | ||
| varVt->sign == tokVt->sign && | ||
| varVt->type == tokVt->type && | ||
| varVt->pointer == tokVt->pointer) { | ||
| std::unordered_set<nonneg int> ids; | ||
| for (const auto &value : vartok->values()) { | ||
| if (!value.isSymbolicValue()) | ||
| continue; | ||
| if (!value.isKnown()) | ||
| continue; | ||
| if (!value.tokvalue) | ||
| continue; | ||
| if (!ids.insert(value.tokvalue->exprId()).second) | ||
| continue; | ||
| const bool add = tok->str() == "+"; | ||
| if (add && MathLib::additionWouldOverflow(value.intvalue, constant->intvalue)) | ||
| continue; | ||
| if (!add && MathLib::subtractionWouldOverflow(value.intvalue, constant->intvalue)) | ||
| continue; | ||
| ValueFlow::Value newValue(value); | ||
| newValue.intvalue = add ? newValue.intvalue + constant->intvalue : newValue.intvalue - constant->intvalue; | ||
| setTokenValue(tok, std::move(newValue), settings); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AI review For unsigned non-pointer operands this offset is only correct modulo 2^N. The condition code still uses it for ordering, which gives new false positives. Example: |
||
| } | ||
| } | ||
| } | ||
| if (Token::Match(tok, "<<|>>|^|+|-|%or%") && constant->intvalue != 0) | ||
| continue; | ||
| if (Token::Match(tok, "*|/") && constant->intvalue != 1) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.