Try to clarify message for container access out of bounds a little more.

This commit is contained in:
Daniel Marjamäki 2018-11-28 13:58:01 +01:00
parent 0f2f807798
commit 6493db6ca2
2 changed files with 4 additions and 4 deletions

View File

@ -111,9 +111,9 @@ void CheckStl::outOfBoundsError(const Token *tok, const ValueFlow::Value *contai
errmsg = "Out of bounds access of item in container '$symbol'";
else if (containerSize->intvalue == 0) {
if (containerSize->condition)
errmsg = "Accessing an item in container '$symbol'. " + ValueFlow::eitherTheConditionIsRedundant(containerSize->condition) + " or '$symbol' can be empty.";
errmsg = ValueFlow::eitherTheConditionIsRedundant(containerSize->condition) + " or $symbol is accessed out of bounds when $symbol is empty.";
else
errmsg = "Accessing an item in container '$symbol' that is empty.";
errmsg = "Out of bounds access in $symbol because $symbol is empty.";
} else if (index) {
errmsg = "Accessing $symbol[" + MathLib::toString(index->intvalue) + "] is out of bounds when $symbol size is " + MathLib::toString(containerSize->intvalue) + ".";
if (containerSize->condition)

View File

@ -201,7 +201,7 @@ private:
" std::string s;\n"
" s[10] = 1;\n"
"}");
ASSERT_EQUALS("test.cpp:3:error:Accessing an item in container 's' that is empty.\n", errout.str());
ASSERT_EQUALS("test.cpp:3:error:Out of bounds access in s because s is empty.\n", errout.str());
checkNormal("void f() {\n"
" std::string s = \"abcd\";\n"
@ -213,7 +213,7 @@ private:
" v.front();\n"
" if (v.empty()) {}\n"
"}\n");
ASSERT_EQUALS("test.cpp:2:warning:Accessing an item in container 'v'. Either the condition 'v.empty()' is redundant or 'v' can be empty.\n"
ASSERT_EQUALS("test.cpp:2:warning:Either the condition 'v.empty()' is redundant or v is accessed out of bounds when v is empty.\n"
"test.cpp:3:note:condition 'v.empty()'\n"
"test.cpp:2:note:Access out of bounds\n", errout.str());