Fixed crash in CheckMemoryLeak::functionReturnType() for unary operator:: (#7172)
This commit is contained in:
parent
0ba3d25917
commit
3b4160600d
|
@ -343,7 +343,7 @@ CheckMemoryLeak::AllocType CheckMemoryLeak::functionReturnType(const Function* f
|
|||
return No;
|
||||
const Token* tok = tok2->astOperand1();
|
||||
if (Token::Match(tok, ".|::"))
|
||||
tok = tok->astOperand2();
|
||||
tok = tok->astOperand2() ? tok->astOperand2() : tok->astOperand1();
|
||||
varid = tok->varId();
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -362,6 +362,7 @@ private:
|
|||
|
||||
TEST_CASE(gnucfg);
|
||||
TEST_CASE(trac3991);
|
||||
TEST_CASE(crash);
|
||||
}
|
||||
|
||||
std::string getcode(const char code[], const char varname[], bool classfunc=false) {
|
||||
|
@ -3893,6 +3894,24 @@ private:
|
|||
"}", true);
|
||||
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)
|
||||
|
|
Loading…
Reference in New Issue