Skip to content

Commit e64ff0b

Browse files
committed
do not set values if there is no expression [skip ci]
1 parent b067f37 commit e64ff0b

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

lib/programmemory.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@
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) : tok(tok), exprid(tok ? tok->exprId() : 0)
49+
{
50+
assert(tok);
51+
}
4952

5053
nonneg int ExprIdToken::getExpressionId() const {
5154
return tok ? tok->exprId() : exprid;
@@ -57,6 +60,9 @@ std::size_t ExprIdToken::Hash::operator()(ExprIdToken etok) const
5760
}
5861

5962
void ProgramMemory::setValue(const Token* expr, const ValueFlow::Value& value) {
63+
if (!expr)
64+
return;
65+
6066
copyOnWrite();
6167

6268
(*mValues)[expr] = value;

lib/valueflow.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6313,6 +6313,8 @@ const Token* ValueFlow::solveExprValue(const Token* expr,
63136313
const std::function<std::vector<MathLib::bigint>(const Token*)>& eval,
63146314
ValueFlow::Value& value)
63156315
{
6316+
if (!expr)
6317+
return nullptr;
63166318
if (!value.isIntValue() && !value.isIteratorValue() && !value.isSymbolicValue())
63176319
return expr;
63186320
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)