Fixed #6226 (false negative: printf format check for user defined array type)
This commit is contained in:
parent
e2f72b4cb1
commit
d5908f03b7
|
@ -1549,6 +1549,20 @@ bool CheckIO::ArgumentInfo::isStdVectorOrString()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if (variableInfo->type()) {
|
||||||
|
const Scope * classScope = variableInfo->type()->classScope;
|
||||||
|
if (classScope) {
|
||||||
|
std::list<Function>::const_iterator functions;
|
||||||
|
for (functions = classScope->functionList.begin();
|
||||||
|
functions != classScope->functionList.end(); ++functions) {
|
||||||
|
if (functions->name() == "operator[]") {
|
||||||
|
if (Token::Match(functions->retDef, "%type% &")) {
|
||||||
|
typeToken = functions->retDef;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -3100,6 +3100,19 @@ private:
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (warning) %s in format string (no. 1) requires 'char *' but the argument type is 'std::string'.\n"
|
ASSERT_EQUALS("[test.cpp:4]: (warning) %s in format string (no. 1) requires 'char *' but the argument type is 'std::string'.\n"
|
||||||
"[test.cpp:4]: (warning) %s in format string (no. 2) requires 'char *' but the argument type is 'int'.\n", errout.str());
|
"[test.cpp:4]: (warning) %s in format string (no. 2) requires 'char *' but the argument type is 'int'.\n", errout.str());
|
||||||
|
|
||||||
|
check("template <class T, size_t S>\n"
|
||||||
|
"struct Array {\n"
|
||||||
|
" T data[S];\n"
|
||||||
|
" T & operator [] (size_t i) { return data[i]; }\n"
|
||||||
|
"};\n"
|
||||||
|
"void foo() {\n"
|
||||||
|
" Array<int, 10> array1;\n"
|
||||||
|
" Array<float, 10> array2;\n"
|
||||||
|
" printf(\"%u %u\", array1[0], array2[0]);\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("[test.cpp:9]: (warning) %u in format string (no. 1) requires 'unsigned int' but the argument type is 'int'.\n"
|
||||||
|
"[test.cpp:9]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'float'.\n", errout.str());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void testPosixPrintfScanfParameterPosition() { // #4900 - No support for parameters in format strings
|
void testPosixPrintfScanfParameterPosition() { // #4900 - No support for parameters in format strings
|
||||||
|
|
Loading…
Reference in New Issue