Fixed #5151 (false negative: improper formatstring - vector::at())
This commit is contained in:
parent
b0ce42565e
commit
a6ef3a224a
|
@ -1398,6 +1398,20 @@ CheckIO::ArgumentInfo::ArgumentInfo(const Token * tok, const Settings *settings)
|
|||
tempToken->insertToken("wchar_t");
|
||||
}
|
||||
typeToken = tempToken;
|
||||
return;
|
||||
}
|
||||
|
||||
// check for std::vector::at() and std::string::at()
|
||||
else if (Token::Match(tok1->previous(), "%var% . at (") &&
|
||||
Token::Match(tok1->linkAt(2), ") [,)]")) {
|
||||
varTok = tok1->previous();
|
||||
variableInfo = varTok->variable();
|
||||
|
||||
if (!isStdVectorOrString()) {
|
||||
variableInfo = 0;
|
||||
typeToken = 0;
|
||||
}
|
||||
|
||||
return;
|
||||
} else if (!(tok1->str() == "." || tok1->type() == Token::eVariable || tok1->type() == Token::eFunction))
|
||||
return;
|
||||
|
|
|
@ -2091,6 +2091,13 @@ private:
|
|||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("std::vector<char> v;\n" // #5151
|
||||
"void foo() {\n"
|
||||
" printf(\"%c %u %f\", v.at(32), v.at(32), v.at(32));\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:3]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'char'.\n"
|
||||
"[test.cpp:3]: (warning) %f in format string (no. 3) requires 'double' but the argument type is 'char'.\n", errout.str());
|
||||
|
||||
}
|
||||
|
||||
void testPosixPrintfScanfParameterPosition() { // #4900 - No support for parameters in format strings
|
||||
|
|
Loading…
Reference in New Issue