From f5f2a2ce2aba3d28354cbdd84f30d886f418e5a4 Mon Sep 17 00:00:00 2001 From: Kimmo Varis Date: Sun, 26 Dec 2010 22:02:20 +0200 Subject: [PATCH] Improve message for container type range check. See thread: https://sourceforge.net/apps/phpbb/cppcheck/viewtopic.php?f=3&t=192&start=0 --- lib/checkstl.cpp | 8 +++++--- test/teststl.cpp | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp index c2f1fa15e..08ecd90d3 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -662,11 +662,13 @@ void CheckStl::stlBoundries() // Error message for bad boundry usage.. void CheckStl::stlBoundriesError(const Token *tok, const std::string &container_name) { - reportError(tok, Severity::error, "stlBoundries", container_name + " range check should use != and not < since the order of the pointers isn't guaranteed"); + reportError(tok, Severity::error, "stlBoundries", + "Dangerous container iterator compare using < operator for " + container_name + "\n" + "Using < operator with container type iterators is dangerous since the order of " + "the items is not guaranteed. One should use != operator instead when comparing " + "iterators in the container."); } - - void CheckStl::if_find() { if (!_settings->_checkCodingStyle) diff --git a/test/teststl.cpp b/test/teststl.cpp index 419c4bb76..4071bef6e 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -924,7 +924,7 @@ private: " ;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:4]: (error) " + stlCont[i] + " range check should use != and not < since the order of the pointers isn't guaranteed\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (error) Dangerous container iterator compare using < operator for " + stlCont[i] + "\n", errout.str()); } }