Skip to content

Commit 4d157af

Browse files
IOBYTEdanmar
authored andcommitted
Fixed danmar#7704 (QString::sprintf format string checking)
1 parent 8a66535 commit 4d157af

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

cfg/qt.cfg

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,16 @@
6868
<function name="SIGNAL">
6969
<ignorefunction>true</ignorefunction>
7070
</function>
71+
<!-- QString & QString::sprintf(const char * cformat, ...); -->
72+
<function name="QString::sprintf">
73+
<noreturn>false</noreturn>
74+
<leak-ignore/>
75+
<formatstr/>
76+
<arg nr="1">
77+
<formatstr/>
78+
<not-uninit/>
79+
</arg>
80+
</function>
7181
<define name="Q_DECL_EXPORT" value=""/>
7282
<define name="Q_DECL_IMPORT" value=""/>
7383
<define name="Q_DECLARE_FLAGS(x,y)" value=""/>

test/testio.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class TestIO : public TestFixture {
3232
void run() {
3333
LOAD_LIB_2(settings.library, "std.cfg");
3434
LOAD_LIB_2(settings.library, "windows.cfg");
35+
LOAD_LIB_2(settings.library, "qt.cfg");
3536

3637
TEST_CASE(coutCerrMisusage);
3738

@@ -57,6 +58,8 @@ class TestIO : public TestFixture {
5758
TEST_CASE(testMicrosoftSecurePrintfArgument);
5859
TEST_CASE(testMicrosoftSecureScanfArgument);
5960

61+
TEST_CASE(testQStringFormatArguments);
62+
6063
TEST_CASE(testTernary); // ticket #6182
6164
TEST_CASE(testUnsignedConst); // ticket #6132
6265

@@ -2819,6 +2822,14 @@ class TestIO : public TestFixture {
28192822
ASSERT_EQUALS("", errout.str());
28202823
}
28212824

2825+
void testQStringFormatArguments() {
2826+
check("void foo(float f) {\n"
2827+
" QString string;\n"
2828+
" string.sprintf(\"%d\", f);\n"
2829+
"}", false, false, Settings::Win32A);
2830+
ASSERT_EQUALS("[test.cpp:3]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'float'.\n", errout.str());
2831+
}
2832+
28222833
void testTernary() { // ticket #6182
28232834
check("void test(const std::string &val) {\n"
28242835
" printf(\"%s\n\", val.empty() ? \"I like to eat bananas\" : val.c_str());\n"

0 commit comments

Comments
 (0)