From ffe657128f01963666fef32d6b6e468c984c64fd Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Tue, 20 Nov 2012 06:12:14 +0100 Subject: [PATCH] Fixed #4364 (Segfault in CheckStl::stlBoundries) --- lib/checkstl.cpp | 5 +---- test/teststl.cpp | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp index 243f31763..bb0d3c560 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -721,10 +721,7 @@ void CheckStl::stlBoundries() if (tok->link()) tok = tok->link(); else - while (tok && tok->str() != ">") - tok = tok->next(); - if (!tok) - break; + continue; if (Token::Match(tok, "> :: iterator|const_iterator %var% =|;")) { const unsigned int iteratorid(tok->tokAt(3)->varId()); diff --git a/test/teststl.cpp b/test/teststl.cpp index 00a88172d..c5ffaa442 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -92,6 +92,7 @@ private: TEST_CASE(stlBoundries1); TEST_CASE(stlBoundries2); TEST_CASE(stlBoundries3); + TEST_CASE(stlBoundries4); // #4364 // if (str.find("ab")) TEST_CASE(if_find); @@ -1255,6 +1256,28 @@ private: ASSERT_EQUALS("[test.cpp:3]: (error) Invalid iterator 'current' used.\n", errout.str()); } + void stlBoundries4() { + + check("void f() {\n" + " std::forward_list>>::iterator it;\n" + " for (it = ab.begin(); ab.end() > it; ++it) {}\n" + "}"); + ASSERT_EQUALS("[test.cpp:3]: (error) Dangerous iterator comparison using operator< on 'std::forward_list'.\n", errout.str()); + + // don't crash + check("void f() {\n" + " if (list < 0) ;\n" + "}"); + ASSERT_EQUALS("", errout.str()); + + check("void f() {\n" + " if (list < 0) {\n" + " std::forward_list>>::iterator it;\n" + " for (it = ab.begin(); ab.end() > it; ++it) {}\n" + " }\n" + "}"); + ASSERT_EQUALS("[test.cpp:4]: (error) Dangerous iterator comparison using operator< on 'std::forward_list'.\n", errout.str()); + } void if_find() {