Skip to content

Commit 0c1e2ce

Browse files
Fix #11289 FP wrongPrintfScanfArgNum - snprintf with parameter pack (#4644)
1 parent b7693cc commit 0c1e2ce

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

lib/checkio.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1306,6 +1306,8 @@ void CheckIO::checkFormatString(const Token * const tok,
13061306
// Count printf/scanf parameters..
13071307
int numFunction = 0;
13081308
while (argListTok2) {
1309+
if (Token::Match(argListTok2, "%name% ...")) // bailout for parameter pack
1310+
return;
13091311
numFunction++;
13101312
argListTok2 = argListTok2->nextArgument(); // Find next argument
13111313
}

test/testio.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ class TestIO : public TestFixture {
8080
TEST_CASE(testPrintfAuto); // #8992
8181
TEST_CASE(testPrintfParenthesis); // #8489
8282
TEST_CASE(testStdDistance); // #10304
83+
TEST_CASE(testParameterPack); // #11289
8384
}
8485

8586
#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)
@@ -4868,6 +4869,16 @@ class TestIO : public TestFixture {
48684869
"}", /*inconclusive*/ false, /*portability*/ true);
48694870
ASSERT_EQUALS("", errout.str());
48704871
}
4872+
4873+
void testParameterPack() { // #11289
4874+
check("template <typename... Args> auto f(const char* format, const Args&... args) {\n"
4875+
" return snprintf(nullptr, 0, format, args...);\n"
4876+
"}\n"
4877+
"void g() {\n"
4878+
" f(\"%d%d\", 1, 2);\n"
4879+
"}\n");
4880+
ASSERT_EQUALS("", errout.str());
4881+
}
48714882
};
48724883

48734884
REGISTER_TEST(TestIO)

0 commit comments

Comments
 (0)