| 40 | static const CWE CWE758(758U); // Reliance on Undefined, Unspecified, or Implementation-Defined Behavior |
| 41 | |
| 42 | void 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 | |
| 76 | void CheckVaargImpl::wrongParameterTo_va_start_error(const Token *tok, const std::string& paramIsName, const std::string& paramShouldName) |
| 77 | { |