Set a max for the combination of arguments that can be passsed through valueFlowSubFunction (#2579)

* Set a max for the combination of arguments that can be passsed

* Skip mismatch path ids when computing the cross product
This commit is contained in:
Paul Fultz II 2020-04-01 15:33:09 -05:00 committed by GitHub
parent b59f49e286
commit 6cc58e1086
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 44 additions and 0 deletions

View File

@ -4705,9 +4705,26 @@ static void valueFlowInjectParameter(TokenList* tokenlist, ErrorLogger* errorLog
args.back()[p.first] = p.second.front();
}
for (const auto& p:vars) {
if (args.size() > 256) {
std::string fname = "<unknown>";
Function* f = functionScope->function;
if (f)
fname = f->name();
if (settings->debugwarnings)
bailout(tokenlist, errorLogger, functionScope->bodyStart, "Too many argument passed to " + fname);
break;
}
std::for_each(std::next(p.second.begin()), p.second.end(), [&](const ValueFlow::Value& value) {
Args new_args;
for (auto arg:args) {
if (value.path != 0) {
for(const auto& q:arg) {
if (q.second.path == 0)
continue;
if (q.second.path != value.path)
return;
}
}
arg[p.first] = value;
new_args.push_back(arg);
}

View File

@ -3111,6 +3111,33 @@ private:
ASSERT_EQUALS(true, testValueOfX(code, 7U, 0));
ASSERT_EQUALS(true, testValueOfX(code, 7U, 17));
ASSERT_EQUALS(true, testValueOfX(code, 7U, 42));
code = "void g(int, int) {}\n"
"void f(int x, int y) {\n"
" g(x, y);\n"
"}\n"
"void h() {\n"
" f(0, 0);\n"
" f(1, 1);\n"
" f(2, 2);\n"
" f(3, 3);\n"
" f(4, 4);\n"
" f(5, 5);\n"
" f(6, 6);\n"
" f(7, 7);\n"
" f(8, 8);\n"
" f(9, 9);\n"
"}\n";
ASSERT_EQUALS(true, testValueOfX(code, 3U, 0));
ASSERT_EQUALS(true, testValueOfX(code, 3U, 1));
ASSERT_EQUALS(true, testValueOfX(code, 3U, 2));
ASSERT_EQUALS(true, testValueOfX(code, 3U, 3));
ASSERT_EQUALS(true, testValueOfX(code, 3U, 4));
ASSERT_EQUALS(true, testValueOfX(code, 3U, 5));
ASSERT_EQUALS(true, testValueOfX(code, 3U, 6));
ASSERT_EQUALS(true, testValueOfX(code, 3U, 7));
ASSERT_EQUALS(true, testValueOfX(code, 3U, 8));
ASSERT_EQUALS(true, testValueOfX(code, 3U, 9));
}
void valueFlowFunctionReturn() {
const char *code;