From 0cebcc8fa9e803e8adb8ce4394bccea8bfa303f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Thu, 16 Dec 2010 21:41:50 +0100 Subject: [PATCH] Fixed #2300 (false positive: possible nullpointer dereference) --- lib/checknullpointer.cpp | 4 ++-- test/testnullpointer.cpp | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/checknullpointer.cpp b/lib/checknullpointer.cpp index 3d778312f..766c0243c 100644 --- a/lib/checknullpointer.cpp +++ b/lib/checknullpointer.cpp @@ -497,8 +497,8 @@ void CheckNullPointer::nullPointerByCheckAndDeRef() continue; } - // abort function.. - if (Token::simpleMatch(tok2, ") ; }") && + // calling unknown function (abort/init).. + if (Token::simpleMatch(tok2, ") ;") && Token::Match(tok2->link()->tokAt(-2), "[;{}] %var% (")) { break; diff --git a/test/testnullpointer.cpp b/test/testnullpointer.cpp index f3e684e57..1b12745ad 100644 --- a/test/testnullpointer.cpp +++ b/test/testnullpointer.cpp @@ -747,6 +747,16 @@ private: " }\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + // ticket: #2300 - calling unknown function that may initialize the pointer + check("Fred *fred;\n" + "void a() {\n" + " if (!fred) {\n" + " initfred();\n" + " fred->x = 0;\n" + " }\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } };