Skip to content

Commit 1569700

Browse files
committed
do not set values if there is no expression
1 parent fa13e63 commit 1569700

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

lib/programmemory.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,14 @@
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+
}
4953

5054
nonneg int ExprIdToken::getExpressionId() const {
51-
return tok ? tok->exprId() : exprid;
55+
return tok->exprId();
5256
}
5357

5458
std::size_t ExprIdToken::Hash::operator()(ExprIdToken etok) const
@@ -57,6 +61,9 @@ std::size_t ExprIdToken::Hash::operator()(ExprIdToken etok) const
5761
}
5862

5963
void ProgramMemory::setValue(const Token* expr, const ValueFlow::Value& value) {
64+
if (!expr)
65+
return;
66+
6067
copyOnWrite();
6168

6269
(*mValues)[expr] = value;

lib/programmemory.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ class Settings;
3939
// Class used to handle heterogeneous lookup in unordered_map(since we can't use C++20 yet)
4040
struct ExprIdToken {
4141
const Token* tok = nullptr;
42-
nonneg int exprid = 0;
4342

4443
// cppcheck-suppress noExplicitConstructor
4544
// NOLINTNEXTLINE(google-explicit-constructor)

lib/valueflow.cpp

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