diff --git a/CheckOther.cpp b/CheckOther.cpp index cf715a386..22968e1fd 100644 --- a/CheckOther.cpp +++ b/CheckOther.cpp @@ -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()); + } +*/ + } +} \ No newline at end of file diff --git a/CheckOther.h b/CheckOther.h index 0e3a9c6a4..ad2d3d01c 100644 --- a/CheckOther.h +++ b/CheckOther.h @@ -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 diff --git a/main.cpp b/main.cpp index 76880d89b..411c7a935 100644 --- a/main.cpp +++ b/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.. diff --git a/tokenize.cpp b/tokenize.cpp index b0333813a..0b42e7b11 100644 --- a/tokenize.cpp +++ b/tokenize.cpp @@ -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]) {