From 9e54714894d98d9347ddca7b2aee63ed30d28692 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Thu, 15 Dec 2011 17:01:39 +0100 Subject: [PATCH] CheckNullPointer::isPointerDeref: better checking if pointer is not dereferenced --- lib/checknullpointer.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/checknullpointer.cpp b/lib/checknullpointer.cpp index e2d3001ba..048fba9ad 100644 --- a/lib/checknullpointer.cpp +++ b/lib/checknullpointer.cpp @@ -252,7 +252,7 @@ bool CheckNullPointer::isPointerDeRef(const Token *tok, bool &unknown) // This is most useful in inconclusive checking if (inconclusive) { // Not a dereference.. - if (Token::Match(tok->previous(), "[;{}] %var% =")) + if (Token::Match(tok->previous(), "[;{}(] %var% =")) return false; // OK to delete a null @@ -265,7 +265,15 @@ bool CheckNullPointer::isPointerDeRef(const Token *tok, bool &unknown) return false; // OK to pass pointer to function - if (Token::Match(tok->previous(), ", %var% [,)]")) + if (Token::Match(tok->previous(), "[(,] %var% [,)]")) + return false; + + // Compare pointer + if (Token::Match(tok->previous(), "(|&&|%oror%|==|!= %var% &&|%oror%|)")) + return false; + + // Taking address + if (Token::Match(tok->previous(), "return|= %var% ;")) return false; // unknown if it's a dereference