Refactoring of the CheckNullPointer::isPointer. Use the symbol database. Ticket: #2629
This commit is contained in:
parent
e26a7819d3
commit
a77993db75
|
@ -21,6 +21,7 @@
|
||||||
#include "checknullpointer.h"
|
#include "checknullpointer.h"
|
||||||
#include "executionpath.h"
|
#include "executionpath.h"
|
||||||
#include "mathlib.h"
|
#include "mathlib.h"
|
||||||
|
#include "symboldatabase.h"
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
// Register this check class (by creating a static instance of it)
|
// 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)
|
bool CheckNullPointer::isPointer(const unsigned int varid)
|
||||||
{
|
{
|
||||||
// Check if given variable is a pointer
|
// Check if given variable is a pointer
|
||||||
const Token *tok = Token::findmatch(_tokenizer->tokens(), "%varid%", varid);
|
const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase();
|
||||||
tok = tok->tokAt(-2);
|
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
|
// maybe not a pointer
|
||||||
if (!Token::Match(tok, "%type% * %varid% [;)=]", varid))
|
if (!Token::Match(tok, "%type% * %varid% [;)=]", varid))
|
||||||
|
|
Loading…
Reference in New Issue