Cppcheck
Functions | Variables
checkleakautovar.cpp File Reference
#include "checkleakautovar.h"
#include "astutils.h"
#include "checkmemoryleak.h"
#include "checknullpointer.h"
#include "mathlib.h"
#include "platform.h"
#include "settings.h"
#include "errortypes.h"
#include "symboldatabase.h"
#include "token.h"
#include "tokenize.h"
#include "tokenlist.h"
#include "utils.h"
#include "vfvalue.h"
#include <algorithm>
#include <array>
#include <cstddef>
#include <iostream>
#include <list>
#include <vector>

Go to the source code of this file.

Functions

static bool isAutoDeallocType (const Type *type)
 
static bool isAutoDealloc (const Variable *var)
 Is variable type some class with automatic deallocation? More...
 
template<std::size_t N>
static bool isVarTokComparison (const Token *tok, const Token **vartok, const std::array< std::pair< std::string, std::string >, N > &ops)
 
static bool isVarUsedInTree (const Token *tok, nonneg int varid)
 
static bool isPointerReleased (const Token *startToken, const Token *endToken, nonneg int varid)
 
static bool isLocalVarNoAutoDealloc (const Token *varTok)
 
static const TokenisFunctionCall (const Token *nameToken)
 checks if nameToken is a name of a function in a function call: func(arg) or func<temp1_arg>(arg) More...
 
static const TokengetOutparamAllocation (const Token *tok, const Settings &settings)
 

Variables

static const CWE CWE672 (672U)
 
static const CWE CWE415 (415U)
 
static constexpr int NEW_ARRAY = -2
 
static constexpr int NEW = -1
 
static const std::array< std::pair< std::string, std::string >, 4 > alloc_failed_conds {{{"==", "0"}, {"<", "0"}, {"==", "-1"}, {"<=", "-1"}}}
 
static const std::array< std::pair< std::string, std::string >, 4 > alloc_success_conds {{{"!=", "0"}, {">", "0"}, {"!=", "-1"}, {">=", "0"}}}
 

Function Documentation

◆ getOutparamAllocation()

static const Token* getOutparamAllocation ( const Token tok,
const Settings settings 
)
static

◆ isAutoDealloc()

static bool isAutoDealloc ( const Variable var)
static

Is variable type some class with automatic deallocation?

Parameters
varvariable token
Returns
true unless it can be seen there is no automatic deallocation
Todo:
false negative: check constructors for side effects

Definition at line 85 of file checkleakautovar.cpp.

References isAutoDeallocType(), Variable::type(), ValueType::type, and Variable::valueType().

Referenced by isLocalVarNoAutoDealloc().

◆ isAutoDeallocType()

static bool isAutoDeallocType ( const Type type)
static

◆ isFunctionCall()

static const Token* isFunctionCall ( const Token nameToken)
static

checks if nameToken is a name of a function in a function call: func(arg) or func<temp1_arg>(arg)

Parameters
nameTokenFunction name token
Returns
opening parenthesis token or NULL if not a function call

Definition at line 289 of file checkleakautovar.cpp.

References Token::isCast(), Token::isName(), Token::isStandardType(), Token::link(), Token::next(), and Token::str().

Referenced by CheckLeakAutoVar::checkScope(), and CheckLeakAutoVar::checkTokenInsideExpression().

◆ isLocalVarNoAutoDealloc()

static bool isLocalVarNoAutoDealloc ( const Token varTok)
static

◆ isPointerReleased()

static bool isPointerReleased ( const Token startToken,
const Token endToken,
nonneg int  varid 
)
static

Definition at line 244 of file checkleakautovar.cpp.

References Token::Match(), and Token::next().

Referenced by CheckLeakAutoVar::checkScope().

◆ isVarTokComparison()

template<std::size_t N>
static bool isVarTokComparison ( const Token tok,
const Token **  vartok,
const std::array< std::pair< std::string, std::string >, N > &  ops 
)
static

Definition at line 97 of file checkleakautovar.cpp.

Referenced by CheckLeakAutoVar::checkScope().

◆ isVarUsedInTree()

static bool isVarUsedInTree ( const Token tok,
nonneg int  varid 
)
static

Variable Documentation

◆ alloc_failed_conds

const std::array<std::pair<std::string, std::string>, 4> alloc_failed_conds {{{"==", "0"}, {"<", "0"}, {"==", "-1"}, {"<=", "-1"}}}
static

Definition at line 60 of file checkleakautovar.cpp.

Referenced by CheckLeakAutoVar::checkScope().

◆ alloc_success_conds

const std::array<std::pair<std::string, std::string>, 4> alloc_success_conds {{{"!=", "0"}, {">", "0"}, {"!=", "-1"}, {">=", "0"}}}
static

Definition at line 61 of file checkleakautovar.cpp.

Referenced by CheckLeakAutoVar::checkScope().

◆ CWE415

const CWE CWE415(415U) ( 415U  )
static

◆ CWE672

const CWE CWE672(672U) ( 672U  )
static

◆ NEW

constexpr int NEW = -1
staticconstexpr

◆ NEW_ARRAY

constexpr int NEW_ARRAY = -2
staticconstexpr