38 #include <initializer_list>
41 #include <unordered_set>
80 while (parent && parent->
isCast())
86 std::map<nonneg int, VariableValue> ret;
87 if (!tok || !tok->
scope()->isExecutable())
89 while (tok && tok->
str() !=
"{") {
90 if (tok->
str() ==
"}") {
91 if (tok->
link()->isBinaryOp())
92 tok = tok->
link()->previous();
121 std::set<std::string> arrayTypeDefs;
123 if (
Token::Match(tok,
"%name% [") && tok->variable() &&
Token::Match(tok->variable()->typeStartToken(),
"%type% %var% ;"))
124 arrayTypeDefs.insert(tok->variable()->typeStartToken()->str());
163 tok = tok->
link()->next();
174 if (var.
isArray() && !stdtype) {
180 while (tok && tok->
str() !=
";")
192 if (parent->str() ==
"=") {
221 if (!allocFuncCallToken)
224 if (!allocFunc || allocFunc->
initData)
231 std::map<nonneg int, VariableValue> variableValue;
244 typeToken = typeToken->
tokAt(2);
254 bool innerunion =
false;
267 const Token *tok2 = tok;
268 if (tok->
str() ==
"}")
305 if (tok->
isName() || tok->
str() ==
".") {
306 while (tok && tok->
str() ==
".")
308 const std::map<nonneg int, VariableValue>::const_iterator it = variableValue.find(tok ? tok->
varId() : ~0U);
309 if (it != variableValue.end()) {
310 *alwaysTrue = (it->second != 0LL);
311 *alwaysFalse = (it->second == 0LL);
316 if (variableValue.empty()) {
320 const Token *vartok, *numtok;
331 while (vartok && vartok->
str() ==
".")
334 const std::map<nonneg int, VariableValue>::const_iterator it = variableValue.find(vartok ? vartok->
varId() : ~0U);
335 if (it == variableValue.end())
338 if (tok->
str() ==
"==")
340 else if (tok->
str() ==
"!=")
344 *alwaysFalse = !(*alwaysTrue);
347 else if (tok->
str() ==
"!") {
348 bool t=
false,f=
false;
356 else if (tok->
str() ==
"||") {
357 bool t1=
false, f1=
false;
359 bool t2=
false, f2=
false;
362 *alwaysTrue = (t1 || t2);
363 *alwaysFalse = (f1 && f2);
366 else if (tok->
str() ==
"&&") {
367 bool t1=
false, f1=
false;
369 bool t2=
false, f2=
false;
372 *alwaysTrue = (t1 && t2);
373 *alwaysFalse = (f1 || f2);
403 const bool suppressErrors(possibleInit && *possibleInit);
407 *possibleInit =
false;
409 int number_of_if = 0;
414 for (; tok; tok = tok->
next()) {
416 if (tok->
str() ==
"}") {
417 if (number_of_if && possibleInit)
418 *possibleInit =
true;
432 bool possibleInitInner =
false;
436 if (possibleInitInner) {
439 *possibleInit =
true;
451 variableValue.erase(tok->
varId());
456 bool alwaysTrue =
false;
457 bool alwaysFalse =
false;
460 if (!membervar.empty()) {
470 if (!alwaysTrue &&
checkIfForWhileHead(tok->
next(), var, suppressErrors,
bool(number_of_if == 0), *alloc, membervar))
476 const Token *condVarTok =
nullptr;
480 const std::map<nonneg int,VariableValue>::const_iterator it = variableValue.find(condVarTok->
varId());
481 if (it != variableValue.cend() && it->second != 0)
484 condVarId = condVarTok->
varId();
491 const Token *numtok = (lhs == vartok) ? rhs : lhs;
495 const std::map<nonneg int,VariableValue>::const_iterator it = variableValue.find(vartok->
varId());
498 condVarId = vartok->
varId();
500 if (condition->
str() ==
"!=")
501 condVarValue = !condVarValue;
510 if (tok->
str() ==
"{") {
511 bool possibleInitIf((!alwaysTrue && number_of_if > 0) || suppressErrors);
512 bool noreturnIf =
false;
513 std::map<nonneg int, VariableValue> varValueIf(variableValue);
514 const bool initif = !alwaysFalse &&
checkScopeForVariable(tok->
next(), var, &possibleInitIf, &noreturnIf, alloc, membervar, varValueIf);
520 if (!alwaysTrue && noreturnIf && number_of_if > 0) {
522 std::string condition;
523 for (
const Token *tok2 = tok->
linkAt(-1); tok2 != tok; tok2 = tok2->
next()) {
524 condition += tok2->str();
525 if (tok2->isName() && tok2->next()->isName())
528 reportError(tok,
Severity::debug,
"bailoutUninitVar",
"bailout uninitialized variable checking for '" + var.
name() +
"'. can't determine if this condition can be false when previous condition is false: " + condition);
533 if (alwaysTrue && (initif || noreturnIf))
536 if (!alwaysFalse && !initif && !noreturnIf)
537 variableValue = varValueIf;
539 if (initif && condVarId > 0)
540 variableValue[condVarId] = !condVarValue;
546 if (initif || possibleInitIf) {
548 if (number_of_if >= 2)
555 bool possibleInitElse((!alwaysFalse && number_of_if > 0) || suppressErrors);
556 bool noreturnElse =
false;
557 std::map<nonneg int, VariableValue> varValueElse(variableValue);
558 const bool initelse = !alwaysTrue &&
checkScopeForVariable(tok->
next(), var, &possibleInitElse, &noreturnElse, alloc, membervar, varValueElse);
560 if (!alwaysTrue && !initelse && !noreturnElse)
561 variableValue = varValueElse;
563 if (initelse && condVarId > 0 && !noreturnIf && !noreturnElse)
564 variableValue[condVarId] = condVarValue;
569 if ((alwaysFalse || initif || noreturnIf) &&
570 (alwaysTrue || initelse || noreturnElse))
573 if (initif || initelse || possibleInitElse)
575 if (!initif && !noreturnIf)
576 variableValue.insert(varValueIf.cbegin(), varValueIf.cend());
577 if (!initelse && !noreturnElse)
578 variableValue.insert(varValueElse.cbegin(), varValueElse.cend());
596 const Token *errorToken =
nullptr;
598 [&](
const Token *child) {
599 if (child->isUnaryOp(
"&"))
600 return ChildrenToVisit::none;
601 if (child->str() ==
"," || child->str() ==
"{" || child->isConstOp())
602 return ChildrenToVisit::op1_and_op2;
603 if (child->str() ==
"." && Token::Match(child->astOperand1(),
"%varid%", var.declarationId()) && child->astOperand2() && child->astOperand2()->str() == membervar) {
605 return ChildrenToVisit::done;
635 if (tok2 && tok2->
str() ==
"{") {
636 const bool init =
checkLoopBody(tok2, var, *alloc, membervar, (number_of_if > 0) || suppressErrors);
643 bool initcond =
false;
644 if (!suppressErrors) {
646 initcond =
checkIfForWhileHead(startCond, var,
false,
bool(number_of_if == 0), *alloc, membervar);
677 if (tok->
str() ==
"struct" || tok->
str() ==
"union") {
704 if (tok->
str() ==
"?") {
709 const bool err = (number_of_if == 0) ? (used1 || used0) : (used1 && used0);
717 if (
Token::Match(tok,
"return|break|continue|throw|goto")) {
722 while (tok && tok->
str() !=
";") {
725 if (!membervar.empty()) {
730 return v.isUninitValue() && !v.isInconclusive();
746 else if (tok->
str() ==
"?") {
751 const bool err = (number_of_if == 0) ? (used1 || used0) : (used1 && used0);
760 return (noreturn ==
nullptr);
768 while (rhs && rhs->
isCast())
772 if (allocFunc && !allocFunc->
initData) {
800 if (!membervar.empty()) {
802 checkRhs(tok, var, *alloc, number_of_if, membervar);
824 const Token *parent = tok;
827 if (parent->
str() ==
"[") {
830 uninitvarError(errorToken, errorToken->expressionString(), *alloc);
839 uninitvarError(errorToken, errorToken->expressionString(), *alloc);
861 bool bailout1 =
false;
867 if ((bailout1 || !known) &&
Token::Match(tok,
"%oror%|&&|?"))
884 const Token *
const endpar = startparentheses->
link();
886 suppressErrors =
true;
887 for (
const Token *tok = startparentheses->
next(); tok && tok != endpar; tok = tok->
next()) {
890 if (membervar.empty())
892 if (tok->strAt(2) == membervar) {
905 uninitvarError(errorToken, errorToken->expressionString(), alloc);
911 tok = tok->linkAt(1);
912 if ((!isuninit || !membervar.empty()) && tok->str() ==
"&&")
913 suppressErrors =
true;
921 assert(start->
str() ==
"{");
923 const Token *errorToken =
nullptr;
926 for (
const Token *tok = start->
next(); tok != end; tok = tok->
next()) {
929 tok = tok->linkAt(1);
943 const Token *bodyStart = top->
link()->next();
946 errorToken = errorToken1;
958 if (tok->str() ==
"{") {
960 if (tok->scope() && tok->scope()->type == Scope::ScopeType::eSwitch) {
970 tok = elseBody->
link();
971 if (errorToken1 && errorToken2)
974 errorToken = errorToken2;
979 errorToken = errorToken1;
985 bool conditionalUsage =
false;
986 for (
const Token* parent = tok; parent; parent = parent->
astParent()) {
988 conditionalUsage =
true;
993 if (!membervar.empty()) {
998 const Token *rpar =
nullptr;
999 for (
const Token *tok2 = tok->
next(); tok2; tok2 = tok2->
next()) {
1000 if (tok2->str() ==
"=")
1004 if (!rpar && tok2->
str() ==
"(")
1005 rpar = tok2->
link();
1006 else if (tok2->str() ==
")") {
1014 if (tok2->str() ==
";" || (!rpar && tok2->
str() ==
","))
1027 if (!conditionalUsage)
1031 }
else if (
Token::Match(tok->previous(),
"[(,] %name% [,)]")) {
1037 if (!conditionalUsage)
1040 errorToken = errtok;
1041 }
else if (tok->strAt(1) ==
"=") {
1042 bool varIsUsedInRhs =
false;
1045 return ChildrenToVisit::none;
1046 if (t->varId() == var.declarationId()) {
1047 varIsUsedInRhs = true;
1048 return ChildrenToVisit::done;
1054 if (!varIsUsedInRhs) {
1073 if (!suppressErrors && !
bailout && errorToken) {
1074 if (membervar.empty())
1088 while (
nullptr != (tok = tok->
next())) {
1089 if (tok->
str() ==
"=")
1100 }
else if (tok->
str() ==
";" || (
indent==0 && tok->
str() ==
","))
1102 else if (tok->
str() ==
"(")
1104 else if (tok->
str() ==
")") {
1111 const bool err = (number_of_if == 0) ? (used1 || used0) : (used1 && used0);
1138 const bool cpp = vartok->
isCpp();
1139 const Token *valueExpr = vartok;
1145 if (valueExpr->
astParent()->isUnaryOp(
"&") && valueExpr->
astParent()->astParent() && valueExpr->
astParent()->astParent()->isUnaryOp(
"*"))
1146 valueExpr = valueExpr->
astParent()->astParent();
1163 const Token *derefValue =
nullptr;
1165 const int arrayDim = (vartok->
variable() && vartok->
variable()->isArray()) ? vartok->
variable()->dimensions().size() : 1;
1167 derefValue = valueExpr;
1172 if (derefValueParent->
str() ==
"*") {
1177 }
else if (derefValueParent->
str() ==
"[") {
1183 if (deref >= arrayDim)
1185 }
else if (derefValueParent->
str() ==
".")
1187 derefValue = derefValueParent;
1188 if (deref < arrayDim)
1189 valueExpr = derefValue;
1191 if (deref < arrayDim) {
1193 derefValue =
nullptr;
1198 while (parent && (parent->
isCast() || parent->
str() ==
"+")) {
1203 derefValue = parent;
1210 if (derefValue && derefValue->
astParent() && derefValue->
astParent()->isUnaryOp(
"&"))
1246 return (use>0) ? valueExpr :
nullptr;
1250 return (use>0) ? derefValue :
nullptr;
1252 if (valueExpr->
astParent()->isUnaryOp(
"&")) {
1256 return (use>0) ? valueExpr :
nullptr;
1265 const Token *tok = derefValue ? derefValue : valueExpr;
1272 if (alloc ==
ARRAY || !derefValue || !derefValue->
isUnaryOp(
"*") || !pointer)
1275 while (deref && deref->
isCast())
1286 if (
Token::Match((derefValue ? derefValue : vartok)->astParent(),
"(|=") &&
astIsRhs(derefValue ? derefValue : vartok)) {
1287 const Token *rhstok = derefValue ? derefValue : vartok;
1312 if (
const auto* vt = valueExpr->
valueType()) {
1313 if (vt->type == ValueType::Type::VOID)
1316 if ((alloc ==
CTOR_CALL || alloc ==
ARRAY) && vt->pointer && vt->type != ValueType::Type::CHAR && vt->type != ValueType::Type::WCHAR_T)
1337 return derefValue ? derefValue : valueExpr;
1353 bool unknown =
false;
1359 int argumentNumber = 0;
1360 const Token *start = vartok;
1362 if (start->
str() ==
")")
1363 start = start->
link();
1364 else if (start->
str() ==
",")
1372 return (!pointer || alloc ==
NO_ALLOC);
1376 const bool address(vartok->
previous()->
str() ==
"&");
1384 if (!address && !array &&
Token::Match(argStart,
"%type% %name%| [,)]"))
1386 if (pointer && !address && alloc ==
NO_ALLOC &&
Token::Match(argStart,
"%type% * %name% [,)]"))
1390 if (
Token::Match(argStart,
"const %type% & %name% [,)]")) {
1392 if (vartok->
variable() && vartok->
variable()->valueType() && vartok->
variable()->valueType()->type == ValueType::Type::RECORD)
1405 if (indirect == 0 && pointer && !address && isnullbad && alloc ==
NO_ALLOC)
1407 bool hasIndirect =
false;
1408 const bool isuninitbad = library.
isuninitargbad(start->
previous(), argumentNumber + 1, indirect, &hasIndirect);
1410 return (isnullbad || hasIndirect) && isuninitbad;
1411 return isuninitbad && (!address || isnullbad);
1442 }
else if (tok->
strAt(1) ==
"=")
1449 }
else if (tok->
strAt(-1) ==
"&") {
1452 int argumentNumber = 0;
1453 const Token *ftok = tok;
1455 if (ftok->
str() ==
")")
1456 ftok = ftok->
link();
1457 else if (ftok->
str() ==
",")
1463 ftok = ftok ? ftok->
previous() :
nullptr;
1477 const Variable *arg =
function ?
function->getArgumentVar(argumentNumber) :
nullptr;
1481 if (
Token::Match(argStart,
"const struct| %type% * const| %name% [,)]"))
1496 tok->
strAt(2) == membervar) {
1507 return !parent || !parent->
isUnaryOp(
"&");
1522 tok->
astParent()->astParent()->astParent()->astOperand2() == tok->
astParent()->astParent())
1544 errorPath.emplace_back(tok,
"");
1548 "$symbol:" + varname +
"\nUninitialized variable: $symbol",
1559 const Token* ltok = tok;
1564 errorPath.emplace_back(tok,
"");
1571 "$symbol:" + varname +
"\nUninitialized variable: $symbol",
1576 std::string vars = v.
subexpressions.size() == 1 ?
"variable: " :
"variables: ";
1579 vars += prefix + varname +
"." + var;
1585 "$symbol:" + varname +
"\nUninitialized " + vars,
1594 "uninitStructMember",
1600 logChecker(
"CheckUninitVar::valueFlowUninit");
1604 std::unordered_set<nonneg int> ids;
1605 for (
const bool subfunction : {
false,
true}) {
1610 tok = tok->linkAt(1);
1613 if (ids.count(tok->exprId()) > 0)
1615 if (!tok->variable() && !tok->isUnaryOp(
"*") && !tok->isUnaryOp(
"&"))
1626 auto v = std::find_if(
1628 if (v == tok->values().cend())
1630 if (v->tokvalue && ids.count(v->tokvalue->exprId()) > 0)
1632 if (subfunction == (v->path == 0))
1634 if (v->isInconclusive())
1636 if (v->indirect > 1 || v->indirect < 0)
1638 bool uninitderef =
false;
1639 if (tok->variable()) {
1641 const bool isarray = tok->variable()->isArray();
1642 if (isarray && tok->variable()->isMember())
1645 uninitderef = deref && v->indirect == 0;
1646 const bool isleaf =
isLeafDot(tok) || uninitderef;
1647 if (!isleaf &&
Token::Match(tok->astParent(),
". %name%") && (tok->astParent()->next()->varId() || tok->astParent()->next()->isEnumerator()))
1656 if (!(
Token::Match(tok->astParent(),
". %name% (|[") && uninitderef) &&
1664 ids.insert(tok->exprId());
1666 ids.insert(v->tokvalue->exprId());
1682 inline namespace CheckUninitVar_internal
1691 std::list<CTU::FileInfo::UnsafeUsage> unsafeUsage;
1694 std::string
toString()
const override
1704 if (unsafeUsage.empty())
1707 auto *fileInfo =
new MyFileInfo;
1708 fileInfo->unsafeUsage = unsafeUsage;
1715 if (unsafeUsage.empty())
1718 auto *fileInfo =
new MyFileInfo;
1719 fileInfo->unsafeUsage = unsafeUsage;
1727 bool foundErrors =
false;
1730 const std::map<std::string, std::list<const CTU::FileInfo::CallBase *>> callsMap = ctu->
getCallsMap();
1733 const MyFileInfo *fi =
dynamic_cast<const MyFileInfo*
>(fi1);
1739 const std::list<ErrorMessage::FileLocation> &locationList =
1743 "Using argument ARG",
1746 if (locationList.empty())
const Token * astIsVariableComparison(const Token *tok, const std::string &comp, const std::string &rhs, const Token **vartok)
Is given syntax tree a variable comparison against value.
bool isLikelyStreamRead(const Token *op)
do we see a likely write of rhs through overloaded operator s >> x; a & x;
const Token * findAllocFuncCallToken(const Token *expr, const Library &library)
Find a allocation function call in expression, so result of expression is allocated memory/resource.
bool astIsLHS(const Token *tok)
bool isLeafDot(const Token *tok)
bool astIsRHS(const Token *tok)
ExprUsage getExprUsage(const Token *tok, int indirect, const Settings &settings)
bool isVariableChangedByFunctionCall(const Token *tok, int indirect, nonneg int varid, const Settings &settings, bool *inconclusive)
Is variable changed by function call? In case the answer of the question is inconclusive,...
bool isUnevaluated(const Token *tok)
bool isVariableChanged(const Token *tok, int indirect, const Settings &settings, int depth)
void visitAstNodes(T *ast, const TFunc &visitor)
Visit AST nodes recursively.
static bool operator!=(const VariableValue &v, MathLib::bigint i)
static bool operator==(const VariableValue &v, MathLib::bigint i)
static void conditionAlwaysTrueOrFalse(const Token *tok, const std::map< nonneg int, VariableValue > &variableValue, bool *alwaysTrue, bool *alwaysFalse)
static std::map< nonneg int, VariableValue > getVariableValues(const Token *tok)
static bool astIsRhs(const Token *tok)
static const CWE CWE_USE_OF_UNINITIALIZED_VARIABLE(457U)
static VariableValue operator!(VariableValue v)
static bool isVoidCast(const Token *tok)
static bool isVariableUsage(const Settings &settings, const Token *vartok, MathLib::bigint *value)
static bool isVariableUsed(const Token *tok, const Variable &var)
static bool astIsLhs(const Token *tok)
static const Token * getAstParentSkipPossibleCastAndAddressOf(const Token *vartok, bool *unknown)
std::string callArgumentExpression
static std::list< ErrorMessage::FileLocation > getErrorPath(InvalidValueType invalidValue, const UnsafeUsage &unsafeUsage, const std::map< std::string, std::list< const CallBase * >> &callsMap, const char info[], const FunctionCall **const functionCallPtr, bool warning)
std::map< std::string, std::list< const CallBase * > > getCallsMap() const
bool isPointerDeRef(const Token *tok, bool &unknown) const
Is there a pointer dereference? Everything that should result in a nullpointer dereference error mess...
Checking for uninitialized variables.
bool diag(const Token *tok)
void valueFlowUninit()
ValueFlow-based checking for uninitialized variables.
void check()
Check for uninitialized variables.
void checkRhs(const Token *tok, const Variable &var, Alloc alloc, nonneg int number_of_if, const std::string &membervar)
void uninitdataError(const Token *tok, const std::string &varname)
const Token * checkLoopBodyRecursive(const Token *start, const Variable &var, const Alloc alloc, const std::string &membervar, bool &bailout) const
recursively check loop, return error token
void uninitStructMemberError(const Token *tok, const std::string &membername)
bool isMemberVariableAssignment(const Token *tok, const std::string &membervar) const
std::set< const Token * > mUninitDiags
static int isFunctionParUsage(const Token *vartok, const Library &library, bool pointer, Alloc alloc, int indirect=0)
static const Token * isVariableUsage(const Token *vartok, const Library &library, bool pointer, Alloc alloc, int indirect=0)
bool checkIfForWhileHead(const Token *startparentheses, const Variable &var, bool suppressErrors, bool isuninit, Alloc alloc, const std::string &membervar)
bool isMemberVariableUsage(const Token *tok, bool isPointer, Alloc alloc, const std::string &membervar) const
void checkStruct(const Token *tok, const Variable &structvar)
void uninitvarError(const Token *tok, const ValueFlow::Value &v)
bool analyseWholeProgram(const CTU::FileInfo *ctu, const std::list< Check::FileInfo * > &fileInfo, const Settings &settings, ErrorLogger &errorLogger) override
Analyse all file infos for all TU.
const Token * checkExpr(const Token *tok, const Variable &var, const Alloc alloc, bool known, bool *bailout=nullptr) const
void checkScope(const Scope *scope, const std::set< std::string > &arrayTypeDefs)
bool checkLoopBody(const Token *tok, const Variable &var, const Alloc alloc, const std::string &membervar, const bool suppressErrors)
Check::FileInfo * loadFileInfoFromXml(const tinyxml2::XMLElement *xmlElement) const override
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)
Check::FileInfo * getFileInfo(const Tokenizer &tokenizer, const Settings &settings) const override
Parse current TU and extract file info.
Base class used for whole-program analysis.
void reportError(const Token *tok, const Severity severity, const std::string &id, const std::string &msg)
report an error
const Settings *const mSettings
const Tokenizer *const mTokenizer
void logChecker(const char id[])
log checker
This is an interface, which the class responsible of error logging should implement.
virtual void reportErr(const ErrorMessage &msg)=0
Information about found errors and warnings is directed here.
Wrapper for error messages, provided by reportErr()
const Variable * getArgumentVar(nonneg int num) const
std::list< Variable > argumentList
argument list, must remain list due to clangimport usage!
Library definitions handling.
ArgumentChecks::Direction getArgDirection(const Token *ftok, int argnr) const
bool isuninitargbad(const Token *ftok, int argnr, int indirect=0, bool *hasIndirect=nullptr) const
bool isnullargbad(const Token *ftok, int argnr) const
const AllocFunc * getAllocFuncInfo(const Token *tok) const
get allocation info for function
static bigint toBigNumber(const std::string &str)
for conversion of numeric literals - for atoi-like conversions please use strToInt()
std::list< Variable > varlist
std::vector< Scope * > nestedList
Function * function
function info for this function
const Token * bodyStart
'{' token
const Token * bodyEnd
'}' token
nonneg int numConstructors
bool isExecutable() const
This is just a container for general settings so that we don't need to pass individual values to func...
bool isEnabled(const ValueFlow::Value *value, bool inconclusiveCheck=false) const
Returns true if given value can be shown.
bool debugwarnings
Is –debug-warnings given?
std::vector< const Scope * > functionScopes
Fast access to function scopes.
std::list< Scope > scopeList
Information about all namespaces/classes/structures.
std::vector< const Scope * > classAndStructScopes
Fast access to class and struct scopes.
The token list that the TokenList generates is a linked-list of this class.
const ValueFlow::Value * getValue(const MathLib::bigint val) const
static bool Match(const Token *tok, const char pattern[], nonneg int varid=0)
Match given token (or list of tokens) to a pattern list.
static const Token * findmatch(const Token *const startTok, const char pattern[], const nonneg int varId=0)
bool hasKnownIntValue() const
MathLib::bigint getKnownIntValue() const
const ValueType * valueType() const
const std::string & strAt(int index) const
void astOperand1(Token *tok)
void function(const Function *f)
Associate this token with given function.
std::string expressionString() const
bool isUnaryOp(const std::string &s) const
const Token * tokAt(int index) const
void astOperand2(Token *tok)
void scope(const Scope *s)
Associate this token with given scope.
void link(Token *linkToToken)
Create link to given token.
const Token * linkAt(int index) const
nonneg int linenr() const
bool isStandardType() const
void variable(const Variable *v)
Associate this token with given variable.
bool isComparisonOp() const
const std::list< ValueFlow::Value > & values() const
static bool simpleMatch(const Token *tok, const char(&pattern)[count])
Match given token (or list of tokens) to a pattern list.
void astParent(Token *tok)
The main purpose is to tokenize the source code.
bool isScopeNoReturn(const Token *endScopeToken, bool *unknown=nullptr) const
Check if inner scope ends with a call to a noreturn function.
const Token * tokens() const
bool isC() const
Is the code C.
const SymbolDatabase * getSymbolDatabase() const
bool isCPP() const
Is the code CPP.
bool isStructType() const
enum Type::NeedInitialization needInitialization
bool isUninitValue() const
bool isInconclusive() const
std::vector< std::string > subexpressions
enum ValueType::Type type
nonneg int pointer
0=>not pointer, 1=>*, 2=>**, 3=>***, etc
const Token * containerTypeToken
The container type token.
Information about a member variable.
bool hasDefault() const
Does variable have a default value.
bool isClass() const
Is variable a user defined (or unknown) type.
bool isExtern() const
Is variable extern.
bool isReference() const
Is reference variable.
bool isStlType() const
Checks if the variable is an STL type ('std::') E.g.
const Type * type() const
Get Type pointer of known type.
bool isPointerToArray() const
Is variable a pointer to an array.
bool isThrow() const
Is variable a throw type.
const Scope * typeScope() const
Get Scope pointer of known type.
const std::string & name() const
Get name string.
bool isArray() const
Is variable an array.
const Token * nameToken() const
Get name token.
nonneg int declarationId() const
Get declaration ID (varId used for variable in its declaration).
const Token * typeStartToken() const
Get type start token.
bool isPointer() const
Is pointer variable.
bool isStatic() const
Is variable static.
const ValueType * valueType() const
std::string toString(Color c)
static const std::string emptyString
std::list< ErrorPathItem > ErrorPath
@ error
Programming error.
CPPCHECKLIB std::list< FileInfo::UnsafeUsage > getUnsafeUsage(const Tokenizer &tokenizer, const Settings &settings, bool(*isUnsafeUsage)(const Settings &settings, const Token *argtok, MathLib::bigint *value))
CPPCHECKLIB std::string toString(const std::list< FileInfo::UnsafeUsage > &unsafeUsage)
CPPCHECKLIB std::list< FileInfo::UnsafeUsage > loadUnsafeUsageListFromXml(const tinyxml2::XMLElement *xmlElement)
std::string myArgumentName
@ DIR_IN
Input to called function. Data is treated as read-only.
@ DIR_OUT
Output to caller. Data is passed by reference or address and is potentially written.
static void indent(std::string &str, const nonneg int indent1, const nonneg int indent2)
#define bailout(tokenlist, errorLogger, tok, what)