From 6493db6ca26217597eadb404b528652feaadbd8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Wed, 28 Nov 2018 13:58:01 +0100 Subject: [PATCH] Try to clarify message for container access out of bounds a little more. --- lib/checkstl.cpp | 4 ++-- test/teststl.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp index 9df22f387..88dc15dde 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -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) diff --git a/test/teststl.cpp b/test/teststl.cpp index acacd34e1..f0e24ec51 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -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());