MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / va_start_argument

Method va_start_argument

lib/checkvaarg.cpp:42–74  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

40static const CWE CWE758(758U); // Reliance on Undefined, Unspecified, or Implementation-Defined Behavior
41
42void CheckVaargImpl::va_start_argument()
43{
44 const SymbolDatabase* const symbolDatabase = mTokenizer->getSymbolDatabase();
45 const std::size_t functions = symbolDatabase->functionScopes.size();
46 const bool printWarnings = mSettings.severity.isEnabled(Severity::warning);
47
48 logChecker("CheckVaarg::va_start_argument");
49
50 for (std::size_t i = 0; i < functions; ++i) {
51 const Scope* scope = symbolDatabase->functionScopes[i];
52 const Function* function = scope->function;
53 if (!function)
54 continue;
55 for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) {
56 if (!tok->scope()->isExecutable())
57 tok = tok->scope()->bodyEnd;
58 else if (Token::simpleMatch(tok, "va_start (")) {
59 const Token* param2 = tok->tokAt(2)->nextArgument();
60 if (!param2)
61 continue;
62 const Variable* var = param2->variable();
63 if (var && var->isReference())
64 referenceAs_va_start_error(param2, var->name());
65 if (var && var->index() + 2 < function->argCount() && printWarnings) {
66 auto it = function->argumentList.end();
67 std::advance(it, -2);
68 wrongParameterTo_va_start_error(tok, var->name(), it->name());
69 }
70 tok = tok->linkAt(1);
71 }
72 }
73 }
74}
75
76void CheckVaargImpl::wrongParameterTo_va_start_error(const Token *tok, const std::string& paramIsName, const std::string& paramShouldName)
77{

Callers 1

runChecksMethod · 0.80

Calls 11

nextMethod · 0.80
scopeMethod · 0.80
variableMethod · 0.80
linkAtMethod · 0.80
simpleMatchFunction · 0.70
sizeMethod · 0.45
isEnabledMethod · 0.45
nextArgumentMethod · 0.45
tokAtMethod · 0.45
nameMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected