Fix #10357 FP stlcstrParam due to incorrect overload resolution (#3813)

* Fix #10357 FP stlcstrParam due to incorrect overload resolution

* Variable shadowing
This commit is contained in:
chrchr-github 2022-02-10 11:17:06 +01:00 committed by GitHub
parent a50452517d
commit 24e9859158
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 3 deletions

View File

@ -5041,7 +5041,7 @@ const Function* Scope::findFunction(const Token *tok, bool requireConst) const
for (std::multimap<std::string, const Function *>::const_iterator it = scope->functionMap.find(tok->str()); it != scope->functionMap.cend() && it->first == tok->str(); ++it) {
const Function *func = it->second;
if (!isCall || args == func->argCount() ||
(func->isVariadic() && args >= (func->argCount() - 1)) ||
(func->isVariadic() && args >= (func->minArgCount() - 1)) ||
(args < func->argCount() && args >= func->minArgCount())) {
matches.push_back(func);
}

View File

@ -6580,8 +6580,8 @@ static void valueFlowLibraryFunction(Token *tok, const std::string &returnValue,
productParams(argValues, [&](const std::unordered_map<nonneg int, ValueFlow::Value>& arg) {
ProgramMemory pm{};
for (const auto& p : arg) {
const Token* tok = lookupVarId[p.first];
pm.setValue(tok, p.second);
const Token* varTok = lookupVarId[p.first];
pm.setValue(varTok, p.second);
}
MathLib::bigint result = 0;
bool error = false;

View File

@ -3830,6 +3830,13 @@ private:
" return ref.c_str();\n"
"}");
ASSERT_EQUALS("[test.cpp:7]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call.\n", errout.str());
check("void f(const wchar_t* w, int i = 0, ...);\n" // #10357
"void f(const std::string& s, int i = 0);\n"
"void g(const std::wstring& p) {\n"
" f(p.c_str());\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void uselessCalls() {