Fixed #5151 (false negative: improper formatstring - vector::at())

This commit is contained in:
Robert Reif 2013-11-08 12:44:05 +01:00 committed by Daniel Marjamäki
parent b0ce42565e
commit a6ef3a224a
2 changed files with 21 additions and 0 deletions

View File

@ -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;

View File

@ -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