Fixed crash in CheckMemoryLeak::functionReturnType() for unary operator:: (#7172)

This commit is contained in:
PKEuS 2015-11-27 11:18:40 +01:00
parent 0ba3d25917
commit 3b4160600d
2 changed files with 20 additions and 1 deletions

View File

@ -343,7 +343,7 @@ CheckMemoryLeak::AllocType CheckMemoryLeak::functionReturnType(const Function* f
return No; return No;
const Token* tok = tok2->astOperand1(); const Token* tok = tok2->astOperand1();
if (Token::Match(tok, ".|::")) if (Token::Match(tok, ".|::"))
tok = tok->astOperand2(); tok = tok->astOperand2() ? tok->astOperand2() : tok->astOperand1();
varid = tok->varId(); varid = tok->varId();
break; break;
} }

View File

@ -362,6 +362,7 @@ private:
TEST_CASE(gnucfg); TEST_CASE(gnucfg);
TEST_CASE(trac3991); TEST_CASE(trac3991);
TEST_CASE(crash);
} }
std::string getcode(const char code[], const char varname[], bool classfunc=false) { std::string getcode(const char code[], const char varname[], bool classfunc=false) {
@ -3893,6 +3894,24 @@ private:
"}", true); "}", true);
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
void crash() {
check("class ComponentDC {\n"
" ::Component * getComponent();\n"
"};\n"
"::Component * ComponentDC::getComponent() {\n"
" return ((::Component *)myComponent);\n"
"}\n"
"class MultiComponentDC : public ComponentDC {\n"
" virtual void addChild(InterfaceNode *);\n"
"};\n"
"void MultiComponentDC::addChild(InterfaceNode *childNode) {\n"
" ComponentDC *cdc = dynamic_cast<ComponentDC *>(childNode);\n"
" if (cdc)\n"
" ::Component *c = cdc->getComponent();\n"
"}");
ASSERT_EQUALS("", errout.str());
}
}; };
REGISTER_TEST(TestMemleakInFunction) REGISTER_TEST(TestMemleakInFunction)