cppcheck-verify: fixed some false positives for array declarations

This commit is contained in:
Daniel Marjamäki 2010-09-12 17:41:48 +02:00
parent 52e64ceea6
commit c185f34947
1 changed files with 18 additions and 5 deletions

View File

@ -24,18 +24,31 @@
#include <sstream> #include <sstream>
#include <string> #include <string>
// Check that array indexes are within bounds /**
* Check that array indexes are within bounds
* 1. Locate array access through: [ .. ]
* 2. Try to determine if index is within bounds.
* 3. If it fails to determine that the index is within bounds then write warning
* \param tokenizer The tokenizer
* \param errout output stream to write warnings to
*/
static void arrayIndex(const Tokenizer &tokenizer, std::ostream &errout) static void arrayIndex(const Tokenizer &tokenizer, std::ostream &errout)
{ {
// Check that all array indexes are within bounds..
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next())
{ {
// 1. Locate array access through: [ .. ]
if (tok->str() == "[") if (tok->str() == "[")
{ {
// TODO: try to determine if the array index is within bounds // 2. try to determine if the array index is within bounds
;
// Write error message: // array declaration
if (Token::simpleMatch(tok, "[ ]"))
continue;
if (Token::Match(tok->tokAt(-2), "%type% %var% [ %num% ] ;|="))
continue;
// 3. If it fails to determine that the index is within bounds then write warning
errout << tokenizer.fileLine(tok) errout << tokenizer.fileLine(tok)
<< " failed to determine if given array index is within bounds" << " failed to determine if given array index is within bounds"
<< std::endl; << std::endl;