Fixed #7704 (QString::sprintf format string checking)
This commit is contained in:
parent
8a66535399
commit
4d157af61f
10
cfg/qt.cfg
10
cfg/qt.cfg
|
@ -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=""/>
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in New Issue