|
Cppcheck
|
Check that uninitialized variables aren't used (using ExecutionPath) More...
Static Public Member Functions | |
| UninitVar (Check *c, const SymbolDatabase *db, bool isc) | |
| Startup constructor. | |
| static void | analyseFunctions (const Token *const tokens, std::set< std::string > &func) |
Static Public Attributes | |
| static std::set< std::string > | uvarFunctions |
| Functions that don't handle uninitialized variables well. | |
Private Member Functions | |
| ExecutionPath * | copy () |
| Create a copy of this check. | |
| void | operator= (const UninitVar &) |
| no implementation => compiler error if used | |
| UninitVar (Check *c, const Variable *v, const SymbolDatabase *db, bool isc) | |
| internal constructor for creating extra checks | |
| bool | is_equal (const ExecutionPath *e) const |
| is other execution path equal? | |
| void | parserhs (const Token *tok2, std::list< ExecutionPath * > &checks) const |
| Parse right hand side expression in statement. | |
| const Token * | parse (const Token &tok, std::list< ExecutionPath * > &checks) const |
| parse tokens. | |
| bool | parseCondition (const Token &tok, std::list< ExecutionPath * > &checks) |
| Parse condition. | |
| void | parseLoopBody (const Token *tok, std::list< ExecutionPath * > &checks) const |
| Parse loop body. | |
Static Private Member Functions | |
| static void | alloc_pointer (std::list< ExecutionPath * > &checks, unsigned int varid) |
| allocating pointer. | |
| static void | init_pointer (std::list< ExecutionPath * > &checks, const Token *tok) |
| Initializing a pointer value. | |
| static void | dealloc_pointer (std::list< ExecutionPath * > &checks, const Token *tok) |
| Deallocate a pointer. | |
| static void | pointer_assignment (std::list< ExecutionPath * > &checks, const Token *tok1, const Token *tok2) |
| Pointer assignment: p = x; if p is a pointer and x is an array/pointer then bail out. | |
| static void | init_strncpy (std::list< ExecutionPath * > &checks, const Token *tok) |
| Initialize an array with strncpy. | |
| static void | init_memset_nonzero (std::list< ExecutionPath * > &checks, const Token *tok) |
| Initialize an array with memset (not zero). | |
| static bool | use (std::list< ExecutionPath * > &checks, const Token *tok, const int mode) |
| use - called from the use* functions below. | |
| static bool | use (std::list< ExecutionPath * > &checks, const Token *tok) |
| Reading variable. | |
| static void | use_array (std::list< ExecutionPath * > &checks, const Token *tok) |
| Reading array elements. | |
| static void | use_array_mem (std::list< ExecutionPath * > &checks, const Token *tok) |
| Reading array elements with a "mem.." function. | |
| static bool | use_pointer (std::list< ExecutionPath * > &checks, const Token *tok) |
| Bad pointer usage. | |
| static bool | use_dead_pointer (std::list< ExecutionPath * > &checks, const Token *tok) |
| Using variable. | |
| static bool | use_array_or_pointer_data (std::list< ExecutionPath * > &checks, const Token *tok) |
| Using variable. | |
Private Attributes | |
| const SymbolDatabase * | symbolDatabase |
| pointer to symbol database | |
| const bool | isC |
| const Variable * | var |
| variable for this check | |
| bool | alloc |
| is this variable allocated? | |
| bool | strncpy_ |
| is this variable initialized with strncpy (not always zero-terminated) | |
| bool | memset_nonzero |
| is this variable initialized but not zero-terminated (memset) | |
Check that uninitialized variables aren't used (using ExecutionPath)
Definition at line 54 of file checkuninitvar.cpp.
| UninitVar::UninitVar | ( | Check * | c, |
| const SymbolDatabase * | db, | ||
| bool | isc | ||
| ) | [inline, explicit, static] |
Startup constructor.
Definition at line 57 of file checkuninitvar.cpp.
| UninitVar::UninitVar | ( | Check * | c, |
| const Variable * | v, | ||
| const SymbolDatabase * | db, | ||
| bool | isc | ||
| ) | [inline, private] |
internal constructor for creating extra checks
Definition at line 71 of file checkuninitvar.cpp.
| static void UninitVar::alloc_pointer | ( | std::list< ExecutionPath * > & | checks, |
| unsigned int | varid | ||
| ) | [inline, static, private] |
allocating pointer.
For example : p = malloc(10);
Definition at line 99 of file checkuninitvar.cpp.
References alloc, ExecutionPath::bailOutVar(), Variable::isArray(), Variable::isPointer(), var, and ExecutionPath::varId.
Referenced by parse().
| static void UninitVar::analyseFunctions | ( | const Token *const | tokens, |
| std::set< std::string > & | func | ||
| ) | [inline, static] |
Definition at line 925 of file checkuninitvar.cpp.
References Token::eIncDecOp, Token::isName(), Token::isStandardType(), Token::link(), Token::Match(), Token::next(), Token::str(), Token::tokAt(), and Token::varId().
Referenced by CheckUninitVar::analyse(), and CheckUninitVar::executionPaths().
| ExecutionPath* UninitVar::copy | ( | ) | [inline, private, virtual] |
Create a copy of this check.
Implements ExecutionPath.
Definition at line 63 of file checkuninitvar.cpp.
References UninitVar().
| static void UninitVar::dealloc_pointer | ( | std::list< ExecutionPath * > & | checks, |
| const Token * | tok | ||
| ) | [inline, static, private] |
Deallocate a pointer.
For example: free(p);
Definition at line 141 of file checkuninitvar.cpp.
References alloc, Variable::isArray(), Variable::isPointer(), Variable::name(), ExecutionPath::owner, CheckUninitVar::uninitvarError(), var, ExecutionPath::varId, and Token::varId().
Referenced by parse().
| static void UninitVar::init_memset_nonzero | ( | std::list< ExecutionPath * > & | checks, |
| const Token * | tok | ||
| ) | [inline, static, private] |
Initialize an array with memset (not zero).
Definition at line 221 of file checkuninitvar.cpp.
References memset_nonzero, ExecutionPath::varId, and Token::varId().
Referenced by parse().
| static void UninitVar::init_pointer | ( | std::list< ExecutionPath * > & | checks, |
| const Token * | tok | ||
| ) | [inline, static, private] |
Initializing a pointer value.
For example: *p = 0;
Definition at line 116 of file checkuninitvar.cpp.
References alloc, Variable::isArray(), use_pointer(), var, ExecutionPath::varId, and Token::varId().
Referenced by parse().
| static void UninitVar::init_strncpy | ( | std::list< ExecutionPath * > & | checks, |
| const Token * | tok | ||
| ) | [inline, static, private] |
Initialize an array with strncpy.
Definition at line 206 of file checkuninitvar.cpp.
References strncpy_, ExecutionPath::varId, and Token::varId().
Referenced by parse().
| bool UninitVar::is_equal | ( | const ExecutionPath * | e | ) | const [inline, private, virtual] |
is other execution path equal?
Implements ExecutionPath.
Definition at line 76 of file checkuninitvar.cpp.
References alloc, memset_nonzero, strncpy_, and var.
| void UninitVar::operator= | ( | const UninitVar & | ) | [private] |
no implementation => compiler error if used
| const Token* UninitVar::parse | ( | const Token & | tok, |
| std::list< ExecutionPath * > & | checks | ||
| ) | const [inline, private, virtual] |
parse tokens.
Implements ExecutionPath.
Definition at line 404 of file checkuninitvar.cpp.
References alloc, alloc_pointer(), ExecutionPath::bailOut(), ExecutionPath::bailOutVar(), dealloc_pointer(), Token::eIncDecOp, Token::getStrLength(), init_memset_nonzero(), init_pointer(), init_strncpy(), Variable::isArray(), Token::isAssignmentOp(), isC, Variable::isConst(), Variable::isExtern(), Token::isName(), Variable::isPointer(), Variable::isStatic(), Token::isUpperCaseName(), Token::link(), Token::linkAt(), Token::Match(), Variable::name(), Variable::nameToken(), Scope::nestedIn, Token::next(), ExecutionPath::owner, CheckNullPointer::parseFunctionCall(), parserhs(), pointer_assignment(), Token::previous(), Variable::scope(), Token::simpleMatch(), Token::str(), Token::strAt(), symbolDatabase, Token::tokAt(), MathLib::toLongNumber(), Token::type(), Variable::typeEndToken(), Variable::typeStartToken(), UninitVar(), use(), use_array(), use_array_mem(), use_array_or_pointer_data(), use_dead_pointer(), use_pointer(), uvarFunctions, var, Token::variable(), ExecutionPath::varId, Token::varId(), and Scope::varlist.
Referenced by parseLoopBody().
| bool UninitVar::parseCondition | ( | const Token & | tok, |
| std::list< ExecutionPath * > & | checks | ||
| ) | [inline, private, virtual] |
Parse condition.
| tok | first token in condition. |
| checks | The execution paths. All execution paths in the list are executed in the current scope |
Reimplemented from ExecutionPath.
Definition at line 875 of file checkuninitvar.cpp.
References Token::Match(), Token::next(), CheckNullPointer::parseFunctionCall(), Token::simpleMatch(), skipBrackets(), Token::str(), use(), use_array(), use_array_mem(), use_array_or_pointer_data(), and Token::varId().
| void UninitVar::parseLoopBody | ( | const Token * | tok, |
| std::list< ExecutionPath * > & | checks | ||
| ) | const [inline, private, virtual] |
Parse loop body.
| tok | the first token in the loop body (the token after the {) |
| checks | The execution paths |
Reimplemented from ExecutionPath.
Definition at line 903 of file checkuninitvar.cpp.
References ExecutionPath::bailOutVar(), Token::linkAt(), Token::next(), parse(), Token::simpleMatch(), Token::str(), and Token::tokAt().
| void UninitVar::parserhs | ( | const Token * | tok2, |
| std::list< ExecutionPath * > & | checks | ||
| ) | const [inline, private] |
Parse right hand side expression in statement.
| tok2 | start token of rhs |
| checks | the execution paths |
Definition at line 363 of file checkuninitvar.cpp.
References ExecutionPath::bailOutVar(), Token::link(), Token::Match(), Token::next(), Token::previous(), Token::simpleMatch(), Token::str(), Token::strAt(), Token::tokAt(), use(), use_array_or_pointer_data(), and Token::varId().
Referenced by parse().
| static void UninitVar::pointer_assignment | ( | std::list< ExecutionPath * > & | checks, |
| const Token * | tok1, | ||
| const Token * | tok2 | ||
| ) | [inline, static, private] |
Pointer assignment: p = x; if p is a pointer and x is an array/pointer then bail out.
| checks | all available checks |
| tok1 | the "p" token |
| tok2 | the "x" token |
Definition at line 172 of file checkuninitvar.cpp.
References ExecutionPath::bailOutVar(), Variable::isArray(), Variable::isPointer(), var, ExecutionPath::varId, and Token::varId().
Referenced by parse().
| static bool UninitVar::use | ( | std::list< ExecutionPath * > & | checks, |
| const Token * | tok, | ||
| const int | mode | ||
| ) | [inline, static, private] |
use - called from the use* functions below.
| checks | all available checks |
| tok | variable token |
| mode | specific behaviour |
Definition at line 244 of file checkuninitvar.cpp.
References alloc, Variable::isArray(), Variable::isPointer(), Token::Match(), memset_nonzero, Variable::name(), ExecutionPath::owner, strncpy_, Variable::typeStartToken(), CheckUninitVar::uninitdataError(), CheckUninitVar::uninitstringError(), CheckUninitVar::uninitvarError(), var, ExecutionPath::varId, and Token::varId().
Referenced by parse(), parseCondition(), parserhs(), use(), use_array(), use_array_mem(), use_array_or_pointer_data(), use_dead_pointer(), and use_pointer().
| static bool UninitVar::use | ( | std::list< ExecutionPath * > & | checks, |
| const Token * | tok | ||
| ) | [inline, static, private] |
Reading variable.
Use this function in situations when it is invalid to read the data of the variable but not the address.
| checks | all available checks |
| tok | variable token |
Definition at line 305 of file checkuninitvar.cpp.
References use().
| static void UninitVar::use_array | ( | std::list< ExecutionPath * > & | checks, |
| const Token * | tok | ||
| ) | [inline, static, private] |
Reading array elements.
If the variable is not an array then the usage is ok.
| checks | all available checks |
| tok | variable token |
Definition at line 314 of file checkuninitvar.cpp.
References use().
Referenced by parse(), and parseCondition().
| static void UninitVar::use_array_mem | ( | std::list< ExecutionPath * > & | checks, |
| const Token * | tok | ||
| ) | [inline, static, private] |
Reading array elements with a "mem.." function.
It's ok if the array is not null-terminated.
| checks | all available checks |
| tok | variable token |
Definition at line 323 of file checkuninitvar.cpp.
References use().
Referenced by parse(), and parseCondition().
| static bool UninitVar::use_array_or_pointer_data | ( | std::list< ExecutionPath * > & | checks, |
| const Token * | tok | ||
| ) | [inline, static, private] |
Using variable.
. reading from uninitialized array or pointer data is invalid. Example: = x[0];
| checks | all available checks |
| tok | variable token |
Definition at line 354 of file checkuninitvar.cpp.
References use().
Referenced by parse(), parseCondition(), and parserhs().
| static bool UninitVar::use_dead_pointer | ( | std::list< ExecutionPath * > & | checks, |
| const Token * | tok | ||
| ) | [inline, static, private] |
Using variable.
. if it's a dead pointer the usage is invalid.
| checks | all available checks |
| tok | variable token |
Definition at line 343 of file checkuninitvar.cpp.
References use().
Referenced by parse().
| static bool UninitVar::use_pointer | ( | std::list< ExecutionPath * > & | checks, |
| const Token * | tok | ||
| ) | [inline, static, private] |
Bad pointer usage.
If the variable is not a pointer then the usage is ok.
| checks | all available checks |
| tok | variable token |
Definition at line 333 of file checkuninitvar.cpp.
References use().
Referenced by init_pointer(), and parse().
bool UninitVar::alloc [private] |
is this variable allocated?
Definition at line 90 of file checkuninitvar.cpp.
Referenced by alloc_pointer(), dealloc_pointer(), init_pointer(), is_equal(), parse(), and use().
const bool UninitVar::isC [private] |
Definition at line 84 of file checkuninitvar.cpp.
Referenced by parse().
bool UninitVar::memset_nonzero [private] |
is this variable initialized but not zero-terminated (memset)
Definition at line 96 of file checkuninitvar.cpp.
Referenced by init_memset_nonzero(), is_equal(), and use().
bool UninitVar::strncpy_ [private] |
is this variable initialized with strncpy (not always zero-terminated)
Definition at line 93 of file checkuninitvar.cpp.
Referenced by init_strncpy(), is_equal(), and use().
const SymbolDatabase* UninitVar::symbolDatabase [private] |
const Variable* UninitVar::var [private] |
variable for this check
Definition at line 87 of file checkuninitvar.cpp.
Referenced by alloc_pointer(), dealloc_pointer(), init_pointer(), is_equal(), parse(), pointer_assignment(), and use().
1.7.6.1