Skip to content
Open
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
6 changes: 6 additions & 0 deletions lib/valueflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5861,6 +5861,12 @@ static void valueFlowSubFunction(const TokenList& tokenlist,
continue;
}

if (argvar->isReference()) {
argvalues.remove_if([](const ValueFlow::Value& v) {
return v.isReverse();
});
}

if (argvalues.empty())
continue;

Expand Down
1 change: 1 addition & 0 deletions lib/vf_analyzers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1606,6 +1606,7 @@ ValuePtr<Analyzer> makeAnalyzer(const Token* exprTok, ValueFlow::Value value, co

ValuePtr<Analyzer> makeReverseAnalyzer(const Token* exprTok, ValueFlow::Value value, const Settings& settings)
{
value.setFlow(ValueFlow::Value::Flow::REVERSE);
if (value.isContainerSizeValue())
return ContainerExpressionAnalyzer(exprTok, std::move(value), settings);
return ExpressionAnalyzer(exprTok, std::move(value), settings);
Expand Down
14 changes: 13 additions & 1 deletion lib/vfvalue.h
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,19 @@
};
UnknownFunctionReturn unknownFunctionReturn{UnknownFunctionReturn::no};

long long : 24; // padding
enum class Flow : std::uint8_t {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think a name like Direction or DirectionFlow would be better.

UNKNOWN,
FORWARD,
REVERSE
} flow = Flow::UNKNOWN;
bool isReverse() const {
return flow == Flow::REVERSE;
}
void setFlow(Flow f) {
flow = f;
}

long long : 16; // padding

Check warning

Code scanning / Cppcheck Premium

A bit-field shall have an appropriate type Warning

A bit-field shall have an appropriate type
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Why would long long be appropriate for 24 bits, but not for 16? Is this a FP?


/** Path id */
MathLib::bigint path{};
Expand Down
15 changes: 15 additions & 0 deletions test/testnullpointer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3020,6 +3020,21 @@ class TestNullPointer : public TestFixture {
" f(nullptr, nullptr);\n"
"}\n", dinit(CheckOptions, $.inconclusive = true));
ASSERT_EQUALS("", errout_str());

check("struct T {\n" // #14308
" bool b{};\n"
" T* next{};\n"
"};\n"
"bool g(const T*& r) {\n"
" const T* t = r;\n"
" r = t->next;\n"
" return t->b;\n"
"}\n"
"void f(const T* tok) {\n"
" if (g(tok)) {}\n"
" if (tok) {}\n"
"}\n", dinit(CheckOptions, $.inconclusive = true));
ASSERT_EQUALS("", errout_str());
}

// Check if pointer is null and the dereference it
Expand Down
Loading