From 509dd9a989263707f328ebc739d3a258f3b19b35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 29 Jan 2013 17:12:14 +0100 Subject: [PATCH] Fixed #4523 (false positive: (error) Possible null pointer dereference) --- lib/checknullpointer.cpp | 2 ++ test/testnullpointer.cpp | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/lib/checknullpointer.cpp b/lib/checknullpointer.cpp index f50663921..520a013bb 100644 --- a/lib/checknullpointer.cpp +++ b/lib/checknullpointer.cpp @@ -857,6 +857,8 @@ void CheckNullPointer::nullPointerByDeRefAndChec() } back = back->previous(); } + } else if (Token::Match(tok1->tokAt(-4), "%varid% = ( * %varid% )", varid)) { + reassign = true; } if (reassign) { diff --git a/test/testnullpointer.cpp b/test/testnullpointer.cpp index c58a32063..5a72c9be3 100644 --- a/test/testnullpointer.cpp +++ b/test/testnullpointer.cpp @@ -695,6 +695,12 @@ private: "}\n"); ASSERT_EQUALS("", errout.str()); + check("void f(struct ABC *abc) {\n" // #4523 + " abc = (*abc).next;\n" + " if (abc) { }\n" + "}"); + ASSERT_EQUALS("", errout.str()); + check("int f(Item *item) {\n" " x = item ? ab(item->x) : 0;\n" " if (item) { }\n"