Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion lib/programmemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@
#include <utility>
#include <vector>

ExprIdToken::ExprIdToken(const Token* tok) : tok(tok), exprid(tok ? tok->exprId() : 0) {}
ExprIdToken::ExprIdToken(const Token* tok)
: tok(tok)
{
assert(tok);
exprid = tok->exprId();
}

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

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

void ProgramMemory::setValue(const Token* expr, const ValueFlow::Value& value) {
if (!expr)
return;

copyOnWrite();

ValueFlow::Value subvalue = value;
Expand Down
2 changes: 2 additions & 0 deletions lib/valueflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6321,6 +6321,8 @@ const Token* ValueFlow::solveExprValue(const Token* expr,
const std::function<std::vector<MathLib::bigint>(const Token*)>& eval,
ValueFlow::Value& value)
{
if (!expr)
return nullptr;
if (!value.isIntValue() && !value.isIteratorValue() && !value.isSymbolicValue())
return expr;
if (value.isSymbolicValue() && !Token::Match(expr, "+|-"))
Expand Down
8 changes: 6 additions & 2 deletions lib/vf_analyzers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -941,8 +941,11 @@ struct MultiValueFlowAnalyzer : ValueFlowAnalyzer {
MultiValueFlowAnalyzer(const std::unordered_map<const Variable*, ValueFlow::Value>& args, const Settings& set)
: ValueFlowAnalyzer(set) {
for (const auto& p:args) {
values[p.first->declarationId()] = p.second;
vars[p.first->declarationId()] = p.first;
const auto declId = p.first->declarationId();
if (declId == 0)
continue; // TODO: should never happen?
Comment on lines +945 to +946
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This occurs in e.g. TestAutoVariables::testinvaliddealloc.

The Variable has no mNameToken and points to void* which appears to be the injected parameter for free(). The errorPath in the values seems to support this:

Address of variable taken here.
Calling function 'free', 1st argument '&c2' value is lifetime=c2

Not sure if something with the injecting is lacking data. But I do not think this needs to be solved in the scope of this PR.

@pfultz2 Any thoughts?

values[declId] = p.second;
vars[declId] = p.first;
}
}

Expand Down Expand Up @@ -1075,6 +1078,7 @@ struct MultiValueFlowAnalyzer : ValueFlowAnalyzer {
const Variable* var = vars.at(p.first);
if (!var)
continue;
assert(var->nameToken());
ps[var->nameToken()] = p.second;
}
return ps;
Expand Down