fix #3121 ([False Positive] Incorrect obsoleted functions)

This commit is contained in:
seb777 2011-09-24 10:54:58 +02:00
parent a685f1f5b7
commit 424f349b88
2 changed files with 25 additions and 3 deletions

View File

@ -21,6 +21,7 @@
//---------------------------------------------------------------------------
#include "checkobsoletefunctions.h"
#include "symboldatabase.h"
//---------------------------------------------------------------------------
@ -40,13 +41,19 @@ void CheckObsoleteFunctions::obsoleteFunctions()
if (_tokenizer->isJavaOrCSharp())
return;
const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase();
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())
{
if (tok->isName() && tok->varId()==0 && tok->strAt(1) == "(" && !Token::Match(tok->previous(), ".|::|:|,"))
{
// function declaration?
if (tok->previous() && tok->previous()->isName())
if (symbolDatabase->findFunctionByToken(tok))
{
_obsoleteStandardFunctions.erase(tok->str());
_obsoletePosixFunctions.erase(tok->str());
continue;
}
std::map<std::string,std::string>::const_iterator it = _obsoleteStandardFunctions.find(tok->str());
if (it != _obsoleteStandardFunctions.end())

View File

@ -48,6 +48,9 @@ private:
// dangerous function
TEST_CASE(testgets);
// declared function ticket #3121
TEST_CASE(test_declared_function);
}
void check(const char code[])
@ -213,8 +216,20 @@ private:
ASSERT_EQUALS("[test.cpp:3]: (information) Found obsolete function 'gets'. It is recommended to use the function 'fgets' instead\n", errout.str());
}
// ticket #3121
void test_declared_function()
{
check("ftime ( int a )\n"
"{\n"
" return a;\n"
"}\n"
"int main ()\n"
"{\n"
" int b ; b = ftime ( 1 ) ;\n"
" return 0 ;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
};
REGISTER_TEST(TestObsoleteFunctions)