Skip to content

Commit

Permalink
Fix #13409 Crash in valueFlowUnknownFunctionReturn() (#7095)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github authored Dec 11, 2024
1 parent 9820403 commit 8c2390e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
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

0 comments on commit 8c2390e

Please sign in to comment.