Skip to content

Commit 0cb2ddb

Browse files
committed
do not set values if there is no expression
1 parent 08272b3 commit 0cb2ddb

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

lib/programmemory.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,12 @@
4545
#include <utility>
4646
#include <vector>
4747

48-
ExprIdToken::ExprIdToken(const Token* tok) : tok(tok), exprid(tok ? tok->exprId() : 0) {}
48+
ExprIdToken::ExprIdToken(const Token* tok)
49+
: tok(tok)
50+
{
51+
assert(tok);
52+
exprid = tok->exprId();
53+
}
4954

5055
ExprIdToken::ExprIdToken(nonneg int exprId) : exprid(exprId) {}
5156

@@ -59,6 +64,9 @@ std::size_t ExprIdToken::Hash::operator()(ExprIdToken etok) const
5964
}
6065

6166
void ProgramMemory::setValue(const Token* expr, const ValueFlow::Value& value) {
67+
if (!expr)
68+
return;
69+
6270
copyOnWrite();
6371

6472
ValueFlow::Value subvalue = value;

lib/valueflow.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6321,6 +6321,8 @@ const Token* ValueFlow::solveExprValue(const Token* expr,
63216321
const std::function<std::vector<MathLib::bigint>(const Token*)>& eval,
63226322
ValueFlow::Value& value)
63236323
{
6324+
if (!expr)
6325+
return nullptr;
63246326
if (!value.isIntValue() && !value.isIteratorValue() && !value.isSymbolicValue())
63256327
return expr;
63266328
if (value.isSymbolicValue() && !Token::Match(expr, "+|-"))

lib/vf_analyzers.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -941,8 +941,11 @@ struct MultiValueFlowAnalyzer : ValueFlowAnalyzer {
941941
MultiValueFlowAnalyzer(const std::unordered_map<const Variable*, ValueFlow::Value>& args, const Settings& set)
942942
: ValueFlowAnalyzer(set) {
943943
for (const auto& p:args) {
944-
values[p.first->declarationId()] = p.second;
945-
vars[p.first->declarationId()] = p.first;
944+
const auto declId = p.first->declarationId();
945+
if (declId == 0)
946+
continue; // TODO: should never happen?
947+
values[declId] = p.second;
948+
vars[declId] = p.first;
946949
}
947950
}
948951

@@ -1075,6 +1078,7 @@ struct MultiValueFlowAnalyzer : ValueFlowAnalyzer {
10751078
const Variable* var = vars.at(p.first);
10761079
if (!var)
10771080
continue;
1081+
assert(var->nameToken());
10781082
ps[var->nameToken()] = p.second;
10791083
}
10801084
return ps;

0 commit comments

Comments
 (0)