tweaked the error message somewhat for id arrayIndexThenCheck

This commit is contained in:
Daniel Marjamäki 2011-08-05 09:10:07 +02:00
parent ac6d67dc4d
commit 0186fc0650
2 changed files with 7 additions and 3 deletions

View File

@ -2209,5 +2209,9 @@ void CheckBufferOverrun::arrayIndexThenCheck()
void CheckBufferOverrun::arrayIndexThenCheckError(const Token *tok, const std::string &indexName)
{
reportError(tok, Severity::style, "arrayIndexThenCheck", "array index " + indexName + " is used before bounds check");
reportError(tok, Severity::style, "arrayIndexThenCheck",
"Array index " + indexName + " is used before limits check\n"
"Defensive programming: The variable " + indexName + " is used as array index and then there is a check that it is within limits. This can "
"mean that the array might be accessed out-of-bounds. Reorder conditions such as '(a[i] && i < 10)' to '(i < 10 && a[i])'. That way the "
"array will not be accessed when the index is out of limits.");
}

View File

@ -3026,13 +3026,13 @@ private:
" if (s[i] == 'x' && i < y) {\n"
" }"
"}");
ASSERT_EQUALS("[test.cpp:2]: (style) array index i is used before bounds check\n", errout.str());
ASSERT_EQUALS("[test.cpp:2]: (style) Array index i is used before limits check\n", errout.str());
check("void f(const char s[]) {\n"
" for (i = 0; s[i] == 'x' && i < y; ++i) {\n"
" }"
"}");
ASSERT_EQUALS("[test.cpp:2]: (style) array index i is used before bounds check\n", errout.str());
ASSERT_EQUALS("[test.cpp:2]: (style) Array index i is used before limits check\n", errout.str());
}
};