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"