From 7d8af7bdca1e2e4220a7312c1b1dbdf09dd8b929 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 7 Apr 2017 13:18:53 +0200 Subject: [PATCH] Fixed #7979 (crash (nr 2): CheckFunctions::checkIgnoredReturnValue()) --- lib/checkfunctions.cpp | 12 ++++++++++++ test/testfunctions.cpp | 6 ++++++ 2 files changed, 18 insertions(+) diff --git a/lib/checkfunctions.cpp b/lib/checkfunctions.cpp index c85354e58..9918e3709 100644 --- a/lib/checkfunctions.cpp +++ b/lib/checkfunctions.cpp @@ -160,6 +160,18 @@ void CheckFunctions::checkIgnoredReturnValue() if (Token::Match(tok, "%var%|(|, {")) tok = tok->linkAt(1); + if (Token::Match(tok->previous(), "%name% (")) { + bool semicolon = false; + for (const Token *tok2 = tok->tokAt(2); tok2 && tok2->str() != ")"; tok2 = tok2->next()) { + if (tok2->str() == ";") + semicolon = true; + else if (Token::Match(tok2, "[({]")) + tok2 = tok2->link(); + } + if (semicolon) + tok = tok->link(); + } + if (tok->varId() || !Token::Match(tok, "%name% (")) continue; diff --git a/test/testfunctions.cpp b/test/testfunctions.cpp index 95ef04f00..12a81abe2 100644 --- a/test/testfunctions.cpp +++ b/test/testfunctions.cpp @@ -912,6 +912,12 @@ private: " int x({mystrcmp(a,b)});\n" "}", "test.cpp", &settings2); ASSERT_EQUALS("", errout.str()); + + // #7979 - code is not well configured + check("void foo() {\n" + " DEBUG(x(); mystrcmp(a,b););\n" + "}", "test.cpp", &settings2); + ASSERT_EQUALS("", errout.str()); } };