diff --git a/lib/checkpostfixoperator.cpp b/lib/checkpostfixoperator.cpp index 7294e688d..4e7851457 100644 --- a/lib/checkpostfixoperator.cpp +++ b/lib/checkpostfixoperator.cpp @@ -55,7 +55,7 @@ void CheckPostfixOperator::postfixOperator() else if (tok->strAt(-2) == ",") { int i(1); - while (tok->strAt(i) != ")") + while (tok->strAt(i) != ")" && tok->tokAt(i) != 0) { if (tok->strAt(i) == ";") { diff --git a/test/testpostfixoperator.cpp b/test/testpostfixoperator.cpp index b789d977e..d3955ca85 100644 --- a/test/testpostfixoperator.cpp +++ b/test/testpostfixoperator.cpp @@ -70,6 +70,13 @@ private: TEST_CASE(testiterator); TEST_CASE(test2168); TEST_CASE(pointer); // #2321 - postincrement of pointer is OK + TEST_CASE(testHangWithInvalidCode); // #2847 - cppcheck hangs with 100% cpu load + } + + void testHangWithInvalidCode() + { + check("a,b--\n"); + ASSERT_EQUALS("", errout.str()); } void testsimple()