Skip to content

Commit 018d27e

Browse files
committed
fix
1 parent c3b8295 commit 018d27e

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

‎lib/checkother.cpp‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2850,6 +2850,13 @@ void CheckOtherImpl::checkInvalidFree()
28502850

28512851
const int varIndex = tok->strAt(1) == "(" ? 2 :
28522852
tok->strAt(3) == "(" ? 4 : 1;
2853+
const Token *op = tok->tokAt(varIndex + 1);
2854+
if (std::any_of(op->values().cbegin(),
2855+
op->values().cend(),
2856+
[&](const ValueFlow::Value &value) {
2857+
return value.isSymbolicValue() && value.intvalue == 0;
2858+
}))
2859+
continue;
28532860
const int var1 = tok->tokAt(varIndex)->varId();
28542861
const int var2 = tok->tokAt(varIndex + 2)->varId();
28552862
const auto alloc1 = utils::as_const(inconclusive).find(var1);

‎lib/valueflow.cpp‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3737,6 +3737,20 @@ static void valueFlowSymbolicOperators(const SymbolDatabase& symboldatabase, con
37373737
continue;
37383738
if (Token::Match(tok, "<<|>>|/|-") && !astIsLHS(vartok))
37393739
continue;
3740+
if (Token::Match(tok, "+|-") && constant->intvalue != 0) {
3741+
std::unordered_set<nonneg int> ids;
3742+
for (const auto &value : vartok->values()) {
3743+
if (!value.isSymbolicValue())
3744+
continue;
3745+
if (!value.tokvalue)
3746+
continue;
3747+
if (!ids.insert(value.tokvalue->exprId()).second)
3748+
continue;
3749+
ValueFlow::Value newValue(value);
3750+
newValue.intvalue += tok->str() == "-" ? -constant->intvalue : constant->intvalue;
3751+
setTokenValue(tok, std::move(newValue), settings);
3752+
}
3753+
}
37403754
if (Token::Match(tok, "<<|>>|^|+|-|%or%") && constant->intvalue != 0)
37413755
continue;
37423756
if (Token::Match(tok, "*|/") && constant->intvalue != 1)

0 commit comments

Comments
 (0)