53 const std::size_t functions = symbolDatabase->
functionScopes.size();
58 for (std::size_t i = 0; i < functions; ++i) {
64 if (!tok->scope()->isExecutable())
65 tok = tok->scope()->bodyEnd;
73 if (var && var->
index() + 2 < function->argCount() && printWarnings) {
74 auto it =
function->argumentList.end();
87 "va_start_wrongParameter",
"'" + paramIsName +
"' given to va_start() is not last named argument of the function. Did you intend to pass '" + paramShouldName +
"'?",
CWE688,
Certainty::normal);
93 "va_start_referencePassed",
"Using reference '" + paramName +
"' as parameter for va_start() results in undefined behaviour.",
CWE758,
Certainty::normal);
110 if (!var || var->isPointer() || var->isReference() || var->isArray() || !var->scope() || var->typeStartToken()->str() !=
"va_list")
112 if (!var->isLocal() && !var->isArgument())
115 bool open = var->isArgument();
116 bool exitOnEndOfStatement =
false;
118 const Token* tok = var->nameToken()->
next();
119 for (; tok && tok != var->
scope()->bodyEnd; tok = tok->
next()) {
124 if (
Token::Match(tok,
"va_start ( %varid%", var->declarationId())) {
129 }
else if (
Token::Match(tok,
"va_end ( %varid%", var->declarationId())) {
140 if (tok->
tokAt(2)->
varId() == var->declarationId()) {
148 exitOnEndOfStatement =
true;
149 else if (tok->
str() ==
"break") {
153 }
else if (tok->
str() ==
"goto" || (tok->
isCpp() && tok->
str() ==
"try")) {
156 }
else if (!open && tok->
varId() == var->declarationId())
158 else if (exitOnEndOfStatement && tok->
str() ==
";")
161 if (open && !var->isArgument())
169 "va_end_missing",
"va_list '" + varname +
"' was opened but not closed by va_end().",
CWE664,
Certainty::normal);
175 "va_list_usedBeforeStarted",
"va_list '" + varname +
"' used before va_start() was called.",
CWE664,
Certainty::normal);
181 "va_start_subsequentCalls",
"va_start() or va_copy() called subsequently on '" + varname +
"' without va_end() in between.",
CWE664,
Certainty::normal);
const Token * findNextTokenFromBreak(const Token *breakToken)
For a "break" token, locate the next token to execute.
const Token * findLambdaEndToken(const Token *first)
find lambda function end token
static const CWE CWE758(758U)
static const CWE CWE688(688U)
static const CWE CWE664(664U)
Checking for misusage of variable argument lists.
void wrongParameterTo_va_start_error(const Token *tok, const std::string ¶mIsName, const std::string ¶mShouldName)
void va_list_usedBeforeStartedError(const Token *tok, const std::string &varname)
void referenceAs_va_start_error(const Token *tok, const std::string ¶mName)
void va_end_missingError(const Token *tok, const std::string &varname)
void va_start_subsequentCallsError(const Token *tok, const std::string &varname)
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
Function * function
function info for this function
const Token * bodyStart
'{' token
const Token * bodyEnd
'}' token
SimpleEnableGroup< Severity > severity
bool isEnabled(T flag) const
const std::vector< const Variable * > & variableList() const
std::vector< const Scope * > functionScopes
Fast access to function scopes.
The token list that the TokenList generates is a linked-list of this class.
static bool Match(const Token *tok, const char pattern[], nonneg int varid=0)
Match given token (or list of tokens) to a pattern list.
const Token * tokAt(int index) const
void scope(const Scope *s)
Associate this token with given scope.
const Token * linkAt(int index) const
void variable(const Variable *v)
Associate this token with given variable.
const Token * nextArgument() const
static bool simpleMatch(const Token *tok, const char(&pattern)[count])
Match given token (or list of tokens) to a pattern list.
const SymbolDatabase * getSymbolDatabase() const
Information about a member variable.
bool isReference() const
Is reference variable.
const std::string & name() const
Get name string.
nonneg int index() const
Get index of variable in declared order.
@ error
Programming error.