From 0a2f11c2cda930447d39b7e3931c9f8e49ce6174 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 29 Mar 2011 18:45:32 +0200 Subject: [PATCH] Fixed #2695 (False positive: null pointer dereference and ternary operator (?:)) --- lib/checknullpointer.cpp | 4 ++-- test/testnullpointer.cpp | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/checknullpointer.cpp b/lib/checknullpointer.cpp index 491a9c1dd..f3818743d 100644 --- a/lib/checknullpointer.cpp +++ b/lib/checknullpointer.cpp @@ -444,8 +444,8 @@ void CheckNullPointer::nullPointerStructByDeRefAndChec() --indentlevel2; } - // label. goto destination.. - else if (tok2->isName() && Token::simpleMatch(tok2->next(), ":")) + // label / ?: + else if (tok2->str() == ":") break; // Reassignment of the struct diff --git a/test/testnullpointer.cpp b/test/testnullpointer.cpp index 16d609211..413556fb1 100644 --- a/test/testnullpointer.cpp +++ b/test/testnullpointer.cpp @@ -493,6 +493,19 @@ private: "}\n"); ASSERT_EQUALS("", errout.str()); + check("int f(Item *item) {\n" + " x = item ? ab(item->x) : 0;\n" + " if (item) { }\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + + check("int f(Item *item) {\n" + " item->x = 0;\n" + " a = b ? c : d;\n" + " if (item) { }\n" + "}\n"); + TODO_ASSERT_EQUALS("error", "", errout.str()); + check("BOOL GotoFlyAnchor()\n" // #2243 "{\n" " const SwFrm* pFrm = GetCurrFrm();\n"