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
6 changes: 6 additions & 0 deletions lib/library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1205,6 +1205,8 @@ const Library::AllocFunc* Library::getAllocFuncInfo(const Token *tok) const
{
while (Token::simpleMatch(tok, "::"))
tok = tok->astOperand2() ? tok->astOperand2() : tok->astOperand1();
if (!tok)
return nullptr;
const std::string funcname = getFunctionName(tok);
return isNotLibraryFunction(tok) && mData->mFunctions.find(funcname) != mData->mFunctions.end() ? nullptr : getAllocDealloc(mData->mAlloc, funcname);
}
Expand All @@ -1214,6 +1216,8 @@ const Library::AllocFunc* Library::getDeallocFuncInfo(const Token *tok) const
{
while (Token::simpleMatch(tok, "::"))
tok = tok->astOperand2() ? tok->astOperand2() : tok->astOperand1();
if (!tok)
return nullptr;
const std::string funcname = getFunctionName(tok);
return isNotLibraryFunction(tok) && mData->mFunctions.find(funcname) != mData->mFunctions.end() ? nullptr : getAllocDealloc(mData->mDealloc, funcname);
}
Expand All @@ -1223,6 +1227,8 @@ const Library::AllocFunc* Library::getReallocFuncInfo(const Token *tok) const
{
while (Token::simpleMatch(tok, "::"))
tok = tok->astOperand2() ? tok->astOperand2() : tok->astOperand1();
if (!tok)
return nullptr;
const std::string funcname = getFunctionName(tok);
return isNotLibraryFunction(tok) && mData->mFunctions.find(funcname) != mData->mFunctions.end() ? nullptr : getAllocDealloc(mData->mRealloc, funcname);
}
Expand Down
9 changes: 9 additions & 0 deletions test/testvalueflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ class TestValueFlow : public TestFixture {
TEST_CASE(valueFlowDynamicBufferSize);

TEST_CASE(valueFlowSafeFunctionParameterValues);
TEST_CASE(valueFlowUnknownFunctionReturn);
TEST_CASE(valueFlowUnknownFunctionReturnRand);
TEST_CASE(valueFlowUnknownFunctionReturnMalloc);

Expand Down Expand Up @@ -7240,6 +7241,14 @@ class TestValueFlow : public TestFixture {
ASSERT_EQUALS(100, values.back().intvalue);
}

void valueFlowUnknownFunctionReturn() {
const char code[] = "template <typename T>\n" // #13409
"struct S {\n"
" std::max_align_t T::* m;\n"
" S(std::max_align_t T::* p) : m(p) {}\n"
"};\n";
(void)valueOfTok(code, ":"); // don't crash
}

void valueFlowUnknownFunctionReturnRand() {
const char *code;
Expand Down
Loading