Skip to content

Commit abed6c6

Browse files
committed
fix
1 parent c3b8295 commit abed6c6

2 files changed

Lines changed: 33 additions & 2 deletions

File tree

lib/checkother.cpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2850,15 +2850,32 @@ 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);
28532854
const int var1 = tok->tokAt(varIndex)->varId();
28542855
const int var2 = tok->tokAt(varIndex + 2)->varId();
28552856
const auto alloc1 = utils::as_const(inconclusive).find(var1);
28562857
const auto alloc2 = utils::as_const(inconclusive).find(var2);
2858+
std::string allocArg;
2859+
bool inconclusiveArg;
28572860
if (alloc1 != inconclusive.end()) {
2858-
invalidFreeError(tok, allocation[var1], alloc1->second);
2861+
allocArg = allocation[var1];
2862+
inconclusiveArg = alloc1->second;
28592863
} else if (alloc2 != inconclusive.end()) {
2860-
invalidFreeError(tok, allocation[var2], alloc2->second);
2864+
allocArg = allocation[var2];
2865+
inconclusiveArg = alloc2->second;
2866+
} else {
2867+
continue;
28612868
}
2869+
bool bail = false;
2870+
for (const auto &value : op->values()) {
2871+
if (value.isSymbolicValue() && value.intvalue == 0) {
2872+
bail = true;
2873+
break;
2874+
}
2875+
}
2876+
if (bail)
2877+
continue;
2878+
invalidFreeError(tok, allocArg, inconclusiveArg);
28622879
}
28632880

28642881
// If the previously-allocated variable is passed in to another function

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)