From 24e98591586aa689d3a4d6095f70da3358bc1989 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Thu, 10 Feb 2022 11:17:06 +0100 Subject: [PATCH] Fix #10357 FP stlcstrParam due to incorrect overload resolution (#3813) * Fix #10357 FP stlcstrParam due to incorrect overload resolution * Variable shadowing --- lib/symboldatabase.cpp | 2 +- lib/valueflow.cpp | 4 ++-- test/teststl.cpp | 7 +++++++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index ee1f58eb7..ff5a6707f 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -5041,7 +5041,7 @@ const Function* Scope::findFunction(const Token *tok, bool requireConst) const for (std::multimap::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); } diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 6b2917509..da419e99c 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -6580,8 +6580,8 @@ static void valueFlowLibraryFunction(Token *tok, const std::string &returnValue, productParams(argValues, [&](const std::unordered_map& 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; diff --git a/test/teststl.cpp b/test/teststl.cpp index 66687cf3d..744cedbbb 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -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() {