Fixed #8624 (Crash below CheckOther::checkDuplicateExpression)

This commit is contained in:
Daniel Marjamäki 2018-06-14 22:39:26 +02:00
parent c30f21ed2a
commit 593f7eee38
2 changed files with 22 additions and 3 deletions

View File

@ -433,11 +433,13 @@ bool isUniqueExpression(const Token* tok)
const Scope * scope = fun->nestedIn;
if (!scope)
return true;
std::string returnType = fun->retType ? fun->retType->name() : fun->retDef->stringifyList(fun->tokenDef);
const std::string returnType = fun->retType ? fun->retType->name() : fun->retDef->stringifyList(fun->tokenDef);
for (const Function& f:scope->functionList) {
std::string freturnType = f.retType ? f.retType->name() : f.retDef->stringifyList(f.tokenDef);
if (f.type != Function::eFunction)
continue;
const std::string freturnType = f.retType ? f.retType->name() : f.retDef->stringifyList(f.tokenDef);
if (f.argumentList.size() == fun->argumentList.size() &&
f.type == Function::eFunction &&
returnType == freturnType &&
f.name() != fun->name()) {
return false;

View File

@ -135,6 +135,7 @@ private:
TEST_CASE(duplicateVarExpression);
TEST_CASE(duplicateVarExpressionUnique);
TEST_CASE(duplicateVarExpressionAssign);
TEST_CASE(duplicateVarExpressionCrash);
TEST_CASE(checkSignOfUnsignedVariable);
TEST_CASE(checkSignOfPointer);
@ -4225,6 +4226,22 @@ private:
ASSERT_EQUALS("", errout.str());
}
void duplicateVarExpressionCrash() {
// Issue #8624
check("struct X {\n"
" X();\n"
" int f() const;\n"
"};\n"
"void run() {\n"
" X x;\n"
" int a = x.f();\n"
" int b = x.f();\n"
" (void)a;\n"
" (void)b;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void checkSignOfUnsignedVariable() {
check(
"void foo() {\n"