From a77993db758bcb88513fe02a248ae3ded9d3c325 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 6 Mar 2011 21:23:33 +0100 Subject: [PATCH] Refactoring of the CheckNullPointer::isPointer. Use the symbol database. Ticket: #2629 --- lib/checknullpointer.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/checknullpointer.cpp b/lib/checknullpointer.cpp index 6241dceae..4681177d6 100644 --- a/lib/checknullpointer.cpp +++ b/lib/checknullpointer.cpp @@ -21,6 +21,7 @@ #include "checknullpointer.h" #include "executionpath.h" #include "mathlib.h" +#include "symboldatabase.h" //--------------------------------------------------------------------------- // Register this check class (by creating a static instance of it) @@ -166,8 +167,12 @@ bool CheckNullPointer::isPointerDeRef(const Token *tok, bool &unknown) bool CheckNullPointer::isPointer(const unsigned int varid) { // Check if given variable is a pointer - const Token *tok = Token::findmatch(_tokenizer->tokens(), "%varid%", varid); - tok = tok->tokAt(-2); + const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase(); + const Variable *variableInfo = symbolDatabase->getVariableFromVarId(varid); + const Token *tok = variableInfo ? variableInfo->typeStartToken() : NULL; + + if (Token::Match(tok, "%type% %type% * %varid% [;)=]", varid)) + return true; // maybe not a pointer if (!Token::Match(tok, "%type% * %varid% [;)=]", varid))