Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #13592: False positive (regression): warning: printf format string requires 1 parameter but 4 are given. [wrongPrintfScanfArgNum] #7269

Merged
merged 2 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3718,7 +3718,7 @@ void Tokenizer::simplifyParenthesizedLibraryFunctions()
if (!Token::simpleMatch(tok, ") ("))
continue;
Token *rpar = tok, *lpar = tok->link();
if (!lpar)
if (!lpar || Token::Match(lpar->previous(), "%name%"))
continue;
const Token *ftok = rpar->previous();
if (mSettings.library.isNotLibraryFunction(ftok))
Expand Down
11 changes: 11 additions & 0 deletions test/testio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class TestIO : public TestFixture {
TEST_CASE(testParameterPack); // #11289

TEST_CASE(testDefaultSignInt); // #13363
TEST_CASE(testPrintfWithGeneric); // #13592
}

struct CheckOptions
Expand Down Expand Up @@ -4952,6 +4953,16 @@ class TestIO : public TestFixture {
check(code, dinit(CheckOptions, $.defaultSign = 'u'));
ASSERT_EQUALS("", errout_str());
}

void testPrintfWithGeneric() { // #13592
const char code[] =
"void f(void) {\n"
" float x = 27.0f;\n"
" printf(\"%s\\n\", _Generic(x, double: cbrt, float: cbrtf)(x));\n"
"}\n";
check(code);
ASSERT_EQUALS("", errout_str());
}
};

REGISTER_TEST(TestIO)
Loading