Function Usage: Make sure it's detected that func is used in code such as 'if ( func() ) { ..'
This commit is contained in:
parent
29a1468523
commit
ce14eb6590
|
@ -55,8 +55,8 @@ void CheckFunctionUsage::parseTokens( const Tokenizer &tokenizer )
|
|||
funcname = tok->tokAt(1);
|
||||
else if ( TOKEN::Match(tok, "%type% * %var% (") )
|
||||
funcname = tok->tokAt(2);
|
||||
else if ( TOKEN::Match(tok, "%type% :: %var% (") && !TOKEN::Match(tok, tok->strAt(2)) )
|
||||
funcname = tok->tokAt(2);
|
||||
else if ( TOKEN::Match(tok, "%type% :: %var% (") && !TOKEN::Match(tok, tok->strAt(2)) )
|
||||
funcname = tok->tokAt(2);
|
||||
|
||||
// Check that ") {" is found..
|
||||
for (const TOKEN *tok2 = funcname; tok2; tok2 = tok2->next)
|
||||
|
@ -91,33 +91,33 @@ void CheckFunctionUsage::parseTokens( const Tokenizer &tokenizer )
|
|||
{
|
||||
const TOKEN *funcname = 0;
|
||||
|
||||
if ( TOKEN::Match( tok, "[;{}.,()[=+-/&|] %var% [(),;]" ) ||
|
||||
TOKEN::Match(tok, ":: %var% (") ||
|
||||
TOKEN::Match(tok, "|= %var% (") ||
|
||||
TOKEN::Match(tok, "&= %var% (") ||
|
||||
TOKEN::Match(tok, "&& %var% (") ||
|
||||
TOKEN::Match(tok, "|| %var% (") )
|
||||
if ( TOKEN::Match( tok, "[;{}.,()[=+-/&|] %var% [(),;]" ) ||
|
||||
TOKEN::Match(tok, ":: %var% (") ||
|
||||
TOKEN::Match(tok, "|= %var% (") ||
|
||||
TOKEN::Match(tok, "&= %var% (") ||
|
||||
TOKEN::Match(tok, "&& %var% (") ||
|
||||
TOKEN::Match(tok, "|| %var% (") )
|
||||
funcname = tok->next;
|
||||
|
||||
// funcname ( => Assert that the end paranthesis isn't followed by {
|
||||
if ( TOKEN::Match(funcname, "%var% (") )
|
||||
{
|
||||
int parlevel = 0;
|
||||
for ( const TOKEN *tok2 = tok; tok2; tok2 = tok2->next )
|
||||
{
|
||||
if (TOKEN::Match(tok2, "("))
|
||||
++parlevel;
|
||||
|
||||
else if (TOKEN::Match(tok2, ")"))
|
||||
{
|
||||
--parlevel;
|
||||
if (parlevel == 0 && (TOKEN::Match(tok2, ") {") || TOKEN::Match(tok2, ") const")))
|
||||
funcname = NULL;
|
||||
if ( parlevel <= 0 )
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// funcname ( => Assert that the end paranthesis isn't followed by {
|
||||
if ( TOKEN::Match(funcname, "%var% (") )
|
||||
{
|
||||
int parlevel = 0;
|
||||
for ( const TOKEN *tok2 = funcname; tok2; tok2 = tok2->next )
|
||||
{
|
||||
if (TOKEN::Match(tok2, "("))
|
||||
++parlevel;
|
||||
|
||||
else if (TOKEN::Match(tok2, ")"))
|
||||
{
|
||||
--parlevel;
|
||||
if (parlevel == 0 && (TOKEN::Match(tok2, ") {") || TOKEN::Match(tok2, ") const")))
|
||||
funcname = NULL;
|
||||
if ( parlevel <= 0 )
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( funcname )
|
||||
{
|
||||
|
|
4
Makefile
4
Makefile
|
@ -1,6 +1,6 @@
|
|||
SRCS=CheckBufferOverrun.cpp CheckClass.cpp CheckHeaders.cpp CheckMemoryLeak.cpp CheckFunctionUsage.cpp CheckOther.cpp FileLister.cpp preprocessor.cpp tokenize.cpp cppcheck.cpp settings.cpp token.cpp
|
||||
OBJS=$(SRCS:%.cpp=%.o)
|
||||
TESTS=testbufferoverrun.o testcharvar.o testconstructors.o testdivision.o testincompletestatement.o testmemleak.o testpreprocessor.o testsimplifytokens.o testtokenize.o testunusedprivfunc.o testunusedvar.o settings.o cppcheck.o token.o
|
||||
TESTS=testbufferoverrun.o testcharvar.o testconstructors.o testdivision.o testfunctionusage.o testincompletestatement.o testmemleak.o testpreprocessor.o testsimplifytokens.o testtokenize.o testunusedprivfunc.o testunusedvar.o settings.o cppcheck.o token.o
|
||||
BIN = ${DESTDIR}/usr/bin
|
||||
|
||||
all: ${OBJS} main.o
|
||||
|
@ -39,6 +39,8 @@ testconstructors.o: testconstructors.cpp tokenize.h CheckClass.h testsuite.h
|
|||
g++ -Wall -pedantic -g -I. -o $@ -c $*.cpp
|
||||
testdivision.o: testdivision.cpp tokenize.h CheckOther.h testsuite.h
|
||||
g++ -Wall -pedantic -g -I. -o $@ -c $*.cpp
|
||||
testfunctionusage.o: testfunctionusage.cpp tokenize.h CheckFunctionUsage.h testsuite.h
|
||||
g++ -Wall -pedantic -g -I. -o $@ -c $*.cpp
|
||||
testincompletestatement.o: testincompletestatement.cpp testsuite.h tokenize.h CheckOther.h
|
||||
g++ -Wall -pedantic -g -I. -o $@ -c $*.cpp
|
||||
testmemleak.o: testmemleak.cpp tokenize.h CheckMemoryLeak.h testsuite.h
|
||||
|
|
|
@ -44,6 +44,7 @@
|
|||
<Unit filename="testcharvar.cpp" />
|
||||
<Unit filename="testconstructors.cpp" />
|
||||
<Unit filename="testdivision.cpp" />
|
||||
<Unit filename="testfunctionusage.cpp" />
|
||||
<Unit filename="testincompletestatement.cpp" />
|
||||
<Unit filename="testmemleak.cpp" />
|
||||
<Unit filename="testpreprocessor.cpp" />
|
||||
|
|
Loading…
Reference in New Issue