Fixed #7704 (QString::sprintf format string checking)

This commit is contained in:
Robert Reif 2016-08-20 08:47:52 +02:00 committed by Daniel Marjamäki
parent 8a66535399
commit 4d157af61f
2 changed files with 21 additions and 0 deletions

View File

@ -68,6 +68,16 @@
<function name="SIGNAL">
<ignorefunction>true</ignorefunction>
</function>
<!-- QString & QString::sprintf(const char * cformat, ...); -->
<function name="QString::sprintf">
<noreturn>false</noreturn>
<leak-ignore/>
<formatstr/>
<arg nr="1">
<formatstr/>
<not-uninit/>
</arg>
</function>
<define name="Q_DECL_EXPORT" value=""/>
<define name="Q_DECL_IMPORT" value=""/>
<define name="Q_DECLARE_FLAGS(x,y)" value=""/>

View File

@ -32,6 +32,7 @@ private:
void run() {
LOAD_LIB_2(settings.library, "std.cfg");
LOAD_LIB_2(settings.library, "windows.cfg");
LOAD_LIB_2(settings.library, "qt.cfg");
TEST_CASE(coutCerrMisusage);
@ -57,6 +58,8 @@ private:
TEST_CASE(testMicrosoftSecurePrintfArgument);
TEST_CASE(testMicrosoftSecureScanfArgument);
TEST_CASE(testQStringFormatArguments);
TEST_CASE(testTernary); // ticket #6182
TEST_CASE(testUnsignedConst); // ticket #6132
@ -2819,6 +2822,14 @@ private:
ASSERT_EQUALS("", errout.str());
}
void testQStringFormatArguments() {
check("void foo(float f) {\n"
" QString string;\n"
" string.sprintf(\"%d\", f);\n"
"}", false, false, Settings::Win32A);
ASSERT_EQUALS("[test.cpp:3]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'float'.\n", errout.str());
}
void testTernary() { // ticket #6182
check("void test(const std::string &val) {\n"
" printf(\"%s\n\", val.empty() ? \"I like to eat bananas\" : val.c_str());\n"