From aa4f61acdf646a26e667d73d67688820eceac829 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 31 Dec 2018 08:24:39 +0100 Subject: [PATCH] CTU: Avoid FP in else block --- lib/ctu.cpp | 2 +- test/testnullpointer.cpp | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/ctu.cpp b/lib/ctu.cpp index 0ee6ab0f0..4d15d26a6 100644 --- a/lib/ctu.cpp +++ b/lib/ctu.cpp @@ -374,7 +374,7 @@ static bool isUnsafeFunction(const Tokenizer *tokenizer, const Settings *setting if (!argvar->isPointer()) return false; for (const Token *tok2 = scope->bodyStart; tok2 != scope->bodyEnd; tok2 = tok2->next()) { - if (Token::simpleMatch(tok2, ") {")) { + if (Token::Match(tok2, ")|else {")) { tok2 = tok2->linkAt(1); if (Token::findmatch(tok2->link(), "return|throw", tok2)) return false; diff --git a/test/testnullpointer.cpp b/test/testnullpointer.cpp index a0a15a317..64db1006c 100644 --- a/test/testnullpointer.cpp +++ b/test/testnullpointer.cpp @@ -2741,6 +2741,17 @@ private: "}"); ASSERT_EQUALS("", errout.str()); + // else + ctu("void dostuff(int mask, int *p) {\n" + " if (mask == 13) ;\n" + " else *p = 45;\n" + "}\n" + "\n" + "void f() {\n" + " dostuff(0, 0);\n" + "}"); + ASSERT_EQUALS("", errout.str()); + // ?, &&, || ctu("void dostuff(int mask, int *p) {\n" " x = (mask & 1) ? *p : 0;\n"