Command line options: Added "--all" and "--style", removed "-w"

This commit is contained in:
Daniel Marjamäki 2007-07-20 15:43:39 +00:00
parent 6ee93c2d62
commit eb0361d6b5
6 changed files with 61 additions and 49 deletions

View File

@ -48,7 +48,7 @@ TOKEN *findfunction(TOKEN *tok)
// Writing dynamic data in buffer without bounds checking
//---------------------------------------------------------------------------
extern bool ShowWarnings;
extern bool ShowAll;
static void _DynamicDataCheck(TOKEN *ftok, TOKEN *tok)
{
@ -75,8 +75,8 @@ static void _DynamicDataCheck(TOKEN *ftok, TOKEN *tok)
tok2 = gettok(tok2,3);
}
// If ShowWarnings, only strlen(var2) counts
if ( ShowWarnings )
// If ShowAll, only strlen(var2) counts
if ( ShowAll )
{
if (match(tok2,"strlen ( var )") &&
strcmp(getstr(tok2,2),var2)==0)
@ -86,7 +86,7 @@ static void _DynamicDataCheck(TOKEN *ftok, TOKEN *tok)
}
}
// If not ShowWarnings, all usage of "var2" counts
// If not ShowAll, all usage of "var2" counts
else
{
if (strcmp(tok2->str,var2)==0)
@ -358,3 +358,4 @@ void WarningDangerousFunctions()

View File

@ -17,7 +17,7 @@
//---------------------------------------------------------------------------
extern bool ShowWarnings;
extern bool ShowAll;
//---------------------------------------------------------------------------
@ -396,7 +396,7 @@ static void _ClassMembers_CheckVar(const char *classname, const char *varname)
if ( match(tok, "var = new type ;") ||
match(tok, "var = new type (") )
{
if ( ! ShowWarnings && ! IsStandardType(getstr(tok,3)) )
if ( ! ShowAll && ! IsStandardType(getstr(tok,3)) )
continue;
err |= ( Alloc != No && Alloc != New );
Alloc = New;
@ -404,7 +404,7 @@ static void _ClassMembers_CheckVar(const char *classname, const char *varname)
else if ( match(tok, "var = new type [") )
{
if ( ! ShowWarnings && ! IsStandardType(getstr(tok,3)) )
if ( ! ShowAll && ! IsStandardType(getstr(tok,3)) )
continue;
err |= ( Alloc != No && Alloc != NewA );
Alloc = NewA;
@ -414,7 +414,7 @@ static void _ClassMembers_CheckVar(const char *classname, const char *varname)
else if ( match(tok, "var = strdup (") ||
match(tok, "var = ( type * ) malloc ("))
{
if ( ! ShowWarnings &&
if ( ! ShowAll &&
tok->next->next->str[0] == '(' &&
! IsStandardType(getstr(tok,3)) )
continue;
@ -499,3 +499,4 @@ void CheckMemoryLeak()

View File

@ -11,7 +11,7 @@ std::vector<std::string> VariableNames;
std::list<STATEMENT> Statements;
extern bool Debug;
extern bool ShowWarnings;
extern bool ShowAll;
@ -51,7 +51,7 @@ static void AppendStatement(STATEMENT::etype Type, TOKEN *tok, std::string Var="
if ( PointerType )
{
if ( ! ShowWarnings && ! IsStandardType(PointerType) )
if ( ! ShowAll && ! IsStandardType(PointerType) )
return;
}
@ -466,3 +466,4 @@ void CreateStatementList()

View File

@ -8,7 +8,7 @@ FOR %%s IN (npp41\scintilla\src\*.cxx) DO (
ECHO %%s
ECHO ---------------------------------- >> scintilla.txt
ECHO %%s >> scintilla.txt
cppcheck -w %%s 2>> scintilla.txt
cppcheck --all %%s 2>> scintilla.txt
)
@ -22,7 +22,8 @@ FOR %%s IN (npp41\PowerEditor\src\*.cpp) DO (
ECHO %%s
ECHO ---------------------------------- >> npp41.txt
ECHO %%s >> npp41.txt
cppcheck -w %%s 2>> npp41.txt
cppcheck --all %%s 2>> npp41.txt
)

View File

@ -1,7 +1,4 @@
// Todo: Output progress? Using commandline option "--progress"?
#include <iostream>
#include <sstream>
@ -16,7 +13,8 @@
//---------------------------------------------------------------------------
bool Debug = false;
bool ShowWarnings = false;
bool ShowAll = false;
bool CheckCodingStyle = false;
//---------------------------------------------------------------------------
static void CppCheck(const char FileName[]);
@ -31,19 +29,16 @@ int main(int argc, char* argv[])
const char *fname = NULL;
for (int i = 1; i < argc; i++)
{
#ifdef __linux__
if(strcasecmp(argv[i],"--debug") == 0)
#else
if (stricmp(argv[i],"--debug") == 0)
#endif
if (strcmp(argv[i],"--debug") == 0)
Debug = true;
#ifdef __linux__
else if (strcasecmp(argv[i],"-w") == 0)
#else
else if (stricmp(argv[i],"-w") == 0)
#endif
ShowWarnings = true;
// Show all messages
else if (strcmp(argv[i],"--all") == 0)
ShowAll = true;
// Checking coding style.
else if (strcmp(argv[i],"--style")==0)
CheckCodingStyle = true;
else
fname = argv[i];
@ -51,8 +46,14 @@ int main(int argc, char* argv[])
if (!fname)
{
std::cout << "checkcode [-w] filename\n";
std::cout << "-w : enables extra warnings\n";
std::cout << "cppcheck [--all] [--style] filename\n";
std::cout << " --all Show all messages.\n"
" By default this is off, a message is only shown"
" if cppcheck is sure it has found a bug."
" By turning on all warnings, you'll probably get"
" false positives, but some of the positives might"
" be real bugs.\n";
std::cout << " --style Check coding style\n";
return 0;
}
@ -83,12 +84,9 @@ static void CppCheck(const char FileName[])
CheckMemset();
if ( ShowWarnings )
{
// Including header which is not needed
// Todo: This is really slow!
if ( CheckCodingStyle )
WarningIncludeHeader();
}
SimplifyTokenList();
@ -105,9 +103,30 @@ static void CppCheck(const char FileName[])
CheckBufferOverrun();
if (ShowAll)
{
// Check for "if (a=b)"
// Check for case without break
// Warnings
if (ShowWarnings)
// Check that all class constructors are ok.
// Temporarily inactivated to avoid any false positives
CheckConstructors();
// Dangerous usage of strtok
WarningStrTok();
}
// Dangerous functions, such as 'gets' and 'scanf'
WarningDangerousFunctions();
// Invalid function usage..
InvalidFunctionUsage();
if (CheckCodingStyle)
{
// Check that all private functions are called.
CheckUnusedPrivateFunctions();
@ -130,27 +149,14 @@ static void CppCheck(const char FileName[])
CheckOperatorEq1();
// Check that all class constructors are ok.
// Temporarily inactivated to avoid any false positives
//CheckConstructors();
// if (a) delete a;
WarningRedundantCode();
// if (condition);
WarningIf();
// Dangerous usage of strtok
WarningStrTok();
}
// Dangerous functions, such as 'gets' and 'scanf'
WarningDangerousFunctions();
// Invalid function usage..
InvalidFunctionUsage();
// Clean up tokens..
DeallocateTokens();
@ -178,3 +184,4 @@ static void CppCheck(const char FileName[])

View File

@ -0,0 +1 @@
Uninitialized member variable 'clKalle::i'