Incomplete statement: Check for statements that begin with a constant
This commit is contained in:
parent
c77b81fddd
commit
815dd364ed
|
@ -658,3 +658,46 @@ void CheckCharVariable()
|
|||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// Incomplete statement..
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
void CheckIncompleteStatement()
|
||||
{
|
||||
int parlevel = 0;
|
||||
|
||||
for ( const TOKEN *tok = tokens; tok; tok = tok->next )
|
||||
{
|
||||
if ( Match(tok,"; %str%") && !Match(gettok(tok,2), ",") )
|
||||
{
|
||||
std::ostringstream errmsg;
|
||||
errmsg << FileLine(tok->next) << ": Redundant code: Found a statement that begins with string constant";
|
||||
ReportErr(errmsg.str());
|
||||
}
|
||||
|
||||
if ( Match(tok,"; %num%") && !Match(gettok(tok,2), ",") )
|
||||
{
|
||||
std::ostringstream errmsg;
|
||||
errmsg << FileLine(tok->next) << ": Redundant code: Found a statement that begins with numeric constant";
|
||||
ReportErr(errmsg.str());
|
||||
}
|
||||
/*
|
||||
if ( tok->str[0] == '(' )
|
||||
++parlevel;
|
||||
else if ( tok->str[0] == ')' )
|
||||
--parlevel;
|
||||
|
||||
if ( parlevel == 0 && Match(tok, "[;{}] %var% ;") )
|
||||
{
|
||||
std::ostringstream errmsg;
|
||||
errmsg << FileLine(tok->next) << ": Redundant code: Found a statement that only contains a variable";
|
||||
ReportErr(errmsg.str());
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
|
@ -43,6 +43,8 @@ void CheckStructMemberUsage();
|
|||
// Using char variable as array index / as operand in bit operation
|
||||
void CheckCharVariable();
|
||||
|
||||
// Incomplete statement. A statement that only contains a constant or variable
|
||||
void CheckIncompleteStatement();
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
#endif
|
||||
|
|
4
main.cpp
4
main.cpp
|
@ -343,6 +343,10 @@ static void CppCheck(const char FileName[], unsigned int FileId)
|
|||
|
||||
// Unused struct members..
|
||||
CheckStructMemberUsage();
|
||||
|
||||
// Check for various types of incomplete statements that could for example
|
||||
// mean that an ';' has been added by accident
|
||||
CheckIncompleteStatement();
|
||||
}
|
||||
|
||||
// Clean up tokens..
|
||||
|
|
|
@ -305,6 +305,10 @@ void TokenizeCode(std::istream &code, const unsigned int FileIndex)
|
|||
char *pToken = CurrentToken;
|
||||
for (char ch = (char)code.get(); !code.eof(); ch = (char)code.get())
|
||||
{
|
||||
// Todo
|
||||
if ( ch < 0 )
|
||||
continue;
|
||||
|
||||
// Preprocessor stuff?
|
||||
if (ch == '#' && !CurrentToken[0])
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue