From d144197d7e387cf49efad357b39d31b9f8a2cd37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Wed, 23 Apr 2014 19:49:16 +0200 Subject: [PATCH] Fixed segfault --- lib/checkother.cpp | 2 +- test/testincompletestatement.cpp | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 86b5e85ca..8271bfb7a 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -2197,7 +2197,7 @@ void CheckOther::checkIncompleteStatement() // no warning if this is the last statement in a ({}) for (const Token *tok2 = tok->next(); tok2; tok2 = tok2->next()) { if (tok2->str() == "(") - tok2 = tok->link(); + tok2 = tok2->link(); else if (Token::Match(tok2, "[;{}]")) { bailout = Token::simpleMatch(tok2, "; } )"); break; diff --git a/test/testincompletestatement.cpp b/test/testincompletestatement.cpp index 7a3346b9c..4d69ba015 100644 --- a/test/testincompletestatement.cpp +++ b/test/testincompletestatement.cpp @@ -59,6 +59,7 @@ private: TEST_CASE(test3); TEST_CASE(test4); TEST_CASE(test5); + TEST_CASE(test6); TEST_CASE(test_numeric); TEST_CASE(intarray); TEST_CASE(structarraynull); @@ -123,6 +124,15 @@ private: ASSERT_EQUALS("[test.cpp:3]: (warning) Redundant code: Found a statement that begins with numeric constant.\n", errout.str()); } + void test6() { + // dont crash + check("void f() {\n" + " 1 == (two + three);\n" + " 2 != (two + three);\n" + " (one + two) != (two + three);\n" + "}"); + } + void test_numeric() { check("struct P\n" "{\n"