Fixed #1302 (False positive: Confusion between POSIX open() and class member)

This commit is contained in:
Daniel Marjamäki 2010-01-26 20:10:52 +01:00
parent db0466eb19
commit fa305d70bc
2 changed files with 27 additions and 0 deletions

View File

@ -152,7 +152,12 @@ CheckMemoryLeak::AllocType CheckMemoryLeak::getAllocationType(const Token *tok2,
return File;
if (Token::Match(tok2, "open|openat|creat|mkstemp|mkostemp ("))
{
// is there a user function with this name?
if (tokenizer && Token::findmatch(tokenizer->tokens(), ("%type% *|&| " + tok2->str()).c_str()))
return No;
return Fd;
}
if (Token::simpleMatch(tok2, "popen ("))
return Pipe;

View File

@ -122,6 +122,7 @@ private:
void run()
{
TEST_CASE(testFunctionReturnType);
TEST_CASE(open);
}
CheckMemoryLeak::AllocType functionReturnType(const char code[])
@ -164,6 +165,27 @@ private:
ASSERT_EQUALS(CheckMemoryLeak::NewArray, functionReturnType(code));
}
}
void open()
{
const char code[] = "class A {\n"
" static int open() {\n"
" return 1;\n"
" }\n"
"\n"
" A() {\n"
" int ret = open();\n"
" }\n"
"};\n";
Tokenizer tokenizer;
std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp");
// there is no allocation
const Token *tok = Token::findmatch(tokenizer.tokens(), "ret =");
CheckMemoryLeak check(&tokenizer, 0);
ASSERT_EQUALS(CheckMemoryLeak::No, check.getAllocationType(tok->tokAt(2), 1));
}
};
static TestMemleak testMemleak;