From 2205b9f8183a4dd742305d61622d1d568a063daa Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 11 Dec 2024 14:40:49 +0100 Subject: [PATCH 1/3] Update library.cpp --- lib/library.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/library.cpp b/lib/library.cpp index dae95a93b89..3b242417a22 100644 --- a/lib/library.cpp +++ b/lib/library.cpp @@ -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); } @@ -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); } @@ -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); } From 81cd42a42b0cac6a415f1b689380fc82bdcac9a6 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 11 Dec 2024 14:42:35 +0100 Subject: [PATCH 2/3] Update testvalueflow.cpp --- test/testvalueflow.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index c2167befdf4..1b14a378153 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -136,7 +136,8 @@ class TestValueFlow : public TestFixture { TEST_CASE(valueFlowDynamicBufferSize); - TEST_CASE(valueFlowSafeFunctionParameterValues); + TEST_CASE(valueFlowSafeFunctionParameterValues); + TEST_CASE(valueFlowUnknownFunctionReturn); TEST_CASE(valueFlowUnknownFunctionReturnRand); TEST_CASE(valueFlowUnknownFunctionReturnMalloc); @@ -7240,6 +7241,14 @@ class TestValueFlow : public TestFixture { ASSERT_EQUALS(100, values.back().intvalue); } + void valueFlowUnknownFunctionReturn() { + const char code[] = "template \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; From 51737d8f59a625b961d85ea84b898dab34c8522b Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 11 Dec 2024 14:50:04 +0100 Subject: [PATCH 3/3] Update testvalueflow.cpp --- test/testvalueflow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 1b14a378153..72934a39c38 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -136,7 +136,7 @@ class TestValueFlow : public TestFixture { TEST_CASE(valueFlowDynamicBufferSize); - TEST_CASE(valueFlowSafeFunctionParameterValues); + TEST_CASE(valueFlowSafeFunctionParameterValues); TEST_CASE(valueFlowUnknownFunctionReturn); TEST_CASE(valueFlowUnknownFunctionReturnRand); TEST_CASE(valueFlowUnknownFunctionReturnMalloc);