Added check: 'IsAlpha'

This commit is contained in:
Daniel Marjamäki 2007-06-05 04:51:01 +00:00
parent 7b07271134
commit cf7485ce0c
3 changed files with 38 additions and 0 deletions

View File

@ -59,6 +59,39 @@ void WarningIsDigit()
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
// Use standard function "isalpha" instead
//---------------------------------------------------------------------------
void WarningIsAlpha()
{
for (TOKEN *tok = tokens; tok; tok = tok->next)
{
bool err = false;
if ( tok->str[0] != '(' )
continue;
err |= match(tok, "( var >= 'A' && var <= 'Z' ) || ( var >= 'a' && var <= 'z' )");
err |= match(tok, "( var >= 'a' && var <= 'z' ) || ( var >= 'A' && var <= 'Z' )");
err |= match(tok, "( * var >= 'A' && * var <= 'Z' ) || ( * var >= 'a' && * var <= 'z' )");
err |= match(tok, "( * var >= 'a' && * var <= 'z' ) || ( * var >= 'A' && * var <= 'Z' )");
err |= match(tok, "( ( var >= 'A' ) && ( var <= 'Z' ) ) || ( ( var >= 'a' ) && ( var <= 'z' ) )");
err |= match(tok, "( ( var >= 'a' ) && ( var <= 'z' ) ) || ( ( var >= 'A' ) && ( var <= 'Z' ) )");
err |= match(tok, "( ( * var >= 'A' ) && ( * var <= 'Z' ) ) || ( ( * var >= 'a' ) && ( * var <= 'z' ) )");
err |= match(tok, "( ( * var >= 'a' ) && ( * var <= 'z' ) ) || ( ( * var >= 'A' ) && ( * var <= 'Z' ) )");
if (err)
{
std::ostringstream ostr;
ostr << FileLine(tok) << ": The condition can be simplified; use 'isalpha'";
ReportErr(ostr.str());
}
}
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
// Redundant code..
//---------------------------------------------------------------------------

View File

@ -10,6 +10,9 @@ void WarningOldStylePointerCast();
// Use standard functions instead
void WarningIsDigit();
// Use standard functions instead
void WarningIsAlpha();
// Redundant code
void WarningRedundantCode();

View File

@ -74,6 +74,7 @@ static void CppCheck(const char FileName[])
if ( ShowWarnings )
{
// Including header which is not needed
// Todo: This is really slow!
WarningIncludeHeader();
}
@ -110,6 +111,7 @@ static void CppCheck(const char FileName[])
// Use standard functions instead
WarningIsDigit();
WarningIsAlpha();
CheckOperatorEq1();