21 #ifndef checkuninitvarH
22 #define checkuninitvarH
66 friend class TestUninitVar;
72 enum Alloc { NO_ALLOC, NO_CTOR_CALL, CTOR_CALL, ARRAY };
80 :
Check(myName(), tokenizer, settings, errorLogger) {}
86 checkUninitVar.
check();
89 bool diag(
const Token* tok);
92 void checkScope(
const Scope* scope,
const std::set<std::string> &arrayTypeDefs);
93 void checkStruct(
const Token *tok,
const Variable &structvar);
94 bool checkScopeForVariable(
const Token *tok,
const Variable& var,
bool*
const possibleInit,
bool*
const noreturn, Alloc*
const alloc,
const std::string &membervar, std::map<nonneg int, VariableValue>& variableValue);
95 const Token* checkExpr(
const Token* tok,
const Variable& var,
const Alloc alloc,
bool known,
bool*
bailout =
nullptr)
const;
96 bool checkIfForWhileHead(
const Token *startparentheses,
const Variable& var,
bool suppressErrors,
bool isuninit, Alloc alloc,
const std::string &membervar);
97 bool checkLoopBody(
const Token *tok,
const Variable& var,
const Alloc alloc,
const std::string &membervar,
const bool suppressErrors);
98 const Token* checkLoopBodyRecursive(
const Token *start,
const Variable& var,
const Alloc alloc,
const std::string &membervar,
bool &
bailout)
const;
99 void checkRhs(
const Token *tok,
const Variable &var, Alloc alloc,
nonneg int number_of_if,
const std::string &membervar);
100 static int isFunctionParUsage(
const Token *vartok,
const Library &library,
bool pointer, Alloc alloc,
int indirect = 0);
101 int isFunctionParUsage(
const Token *vartok,
bool pointer, Alloc alloc,
int indirect = 0)
const;
102 bool isMemberVariableAssignment(
const Token *tok,
const std::string &membervar)
const;
103 bool isMemberVariableUsage(
const Token *tok,
bool isPointer, Alloc alloc,
const std::string &membervar)
const;
117 void uninitdataError(
const Token *tok,
const std::string &varname);
118 void uninitvarError(
const Token *tok,
const std::string &varname,
ErrorPath errorPath);
120 uninitvarError(tok, varname,
ErrorPath{});
123 if (alloc == NO_CTOR_CALL || alloc == CTOR_CALL)
124 uninitdataError(tok, varname);
126 uninitvarError(tok, varname);
128 void uninitStructMemberError(
const Token *tok,
const std::string &membername);
144 return "Uninitialized variables";
148 return "Uninitialized variables\n"
149 "- using uninitialized local variables\n"
150 "- using allocated data before it has been initialized\n";
static bool isVariableUsage(const Settings &settings, const Token *vartok, MathLib::bigint *value)
Checking for uninitialized variables.
std::string classInfo() const override
get information about this class, used to generate documentation
void valueFlowUninit()
ValueFlow-based checking for uninitialized variables.
static std::string myName()
void check()
Check for uninitialized variables.
void uninitvarError(const Token *tok, const std::string &varname, Alloc alloc)
void uninitvarError(const Token *tok, const std::string &varname)
void uninitdataError(const Token *tok, const std::string &varname)
CheckUninitVar()
This constructor is used when registering the CheckUninitVar.
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const override
get error messages
void uninitStructMemberError(const Token *tok, const std::string &membername)
std::set< const Token * > mUninitDiags
void uninitvarError(const Token *tok, const ValueFlow::Value &v)
CheckUninitVar(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
This constructor is used when running checks.
void runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) override
Run checks against the normal token list.
Base class used for whole-program analysis.
Interface class that cppcheck uses to communicate with the checks.
virtual bool analyseWholeProgram(const CTU::FileInfo *ctu, const std::list< FileInfo * > &fileInfo, const Settings &, ErrorLogger &)
virtual FileInfo * loadFileInfoFromXml(const tinyxml2::XMLElement *xmlElement) const
virtual FileInfo * getFileInfo(const Tokenizer &, const Settings &) const
This is an interface, which the class responsible of error logging should implement.
Library definitions handling.
This is just a container for general settings so that we don't need to pass individual values to func...
The token list that the TokenList generates is a linked-list of this class.
The main purpose is to tokenize the source code.
const Settings & getSettings() const
Information about a member variable.
std::list< ErrorPathItem > ErrorPath
Whole program analysis (ctu=Cross Translation Unit)
VariableValue(MathLib::bigint val=0)
static void valueFlowUninit(TokenList &tokenlist, ErrorLogger &errorLogger, const Settings &settings)
#define bailout(tokenlist, errorLogger, tok, what)