Skip to content

Commit 0e8c953

Browse files
Fix #14060 FN containerOutOfBounds with multi-parameter std::stack::emplace() (regression) (#7726)
1 parent fa13e63 commit 0e8c953

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

lib/vf_analyzers.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1489,7 +1489,12 @@ struct ContainerExpressionAnalyzer : ExpressionAnalyzer {
14891489
const Library::Container::Action action = container->getAction(tok->astParent()->strAt(1));
14901490
if (action == Library::Container::Action::PUSH || action == Library::Container::Action::POP || action == Library::Container::Action::APPEND) { // TODO: handle more actions?
14911491
std::vector<const Token*> args = getArguments(tok->tokAt(3));
1492-
if (args.size() < 2 || action == Library::Container::Action::APPEND)
1492+
bool isVariadic = false;
1493+
if (const Library::Function* libFunc = settings.library.getFunction(tok->tokAt(2))) {
1494+
const auto& argChecks = libFunc->argumentChecks;
1495+
isVariadic = argChecks.find(-1) != argChecks.end() && argChecks.at(-1).variadic;
1496+
}
1497+
if (args.size() < 2 || action == Library::Container::Action::APPEND || isVariadic)
14931498
return Action::Read | Action::Write | Action::Incremental;
14941499
}
14951500
}

test/testvalueflow.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7172,6 +7172,15 @@ class TestValueFlow : public TestFixture {
71727172
"}\n";
71737173
ASSERT_EQUALS(true, tokenValues(code, "a . size", ValueFlow::Value::ValueType::CONTAINER_SIZE).empty());
71747174

7175+
code = "void f() {\n" // #14060
7176+
" std::stack<std::pair<int, int>> s;\n"
7177+
" s.emplace(0, 0);\n"
7178+
" s.pop();\n"
7179+
" bool x = s.empty();\n"
7180+
" return x;\n"
7181+
"}\n";
7182+
ASSERT_EQUALS(true, testValueOfXKnown(code, 6U, 1));
7183+
71757184
code = "std::vector<int> g();\n"
71767185
"std::vector<int> f() {\n"
71777186
" std::vector<int> v = g();\n"

0 commit comments

Comments
 (0)