CheckIO: Refactoring. Split out CheckIO::checkFormatString() from CheckIO::checkWrongPrintfScanfArguments().

This commit is contained in:
Daniel Marjamäki 2015-10-10 20:08:15 +02:00
parent 0849ad4707
commit 37d9a95ef1
2 changed files with 755 additions and 740 deletions

View File

@ -491,7 +491,6 @@ static inline bool typesMatch(const std::string& iToTest, const std::string& iTy
void CheckIO::checkWrongPrintfScanfArguments() void CheckIO::checkWrongPrintfScanfArguments()
{ {
const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase(); const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase();
const bool printWarning = _settings->isEnabled("warning");
const bool isWindows = _settings->isWindowsPlatform(); const bool isWindows = _settings->isWindowsPlatform();
std::size_t functions = symbolDatabase->functionScopes.size(); std::size_t functions = symbolDatabase->functionScopes.size();
@ -567,7 +566,19 @@ void CheckIO::checkWrongPrintfScanfArguments()
if (!formatStringTok) if (!formatStringTok)
continue; continue;
const std::string& formatString = formatStringTok->str(); checkFormatString(tok, formatStringTok, argListTok, scan, scanf_s);
}
}
}
void CheckIO::checkFormatString(const Token * const tok,
const Token * const formatStringTok,
const Token * argListTok,
const bool scan,
const bool scanf_s)
{
const bool printWarning = _settings->isEnabled("warning");
const std::string &formatString = formatStringTok->str();
// Count format string parameters.. // Count format string parameters..
unsigned int numFormat = 0; unsigned int numFormat = 0;
@ -1344,8 +1355,6 @@ void CheckIO::checkWrongPrintfScanfArguments()
// Mismatching number of parameters => warning // Mismatching number of parameters => warning
if ((numFormat + numSecure) != numFunction) if ((numFormat + numSecure) != numFunction)
wrongPrintfScanfArgumentsError(tok, tok->originalName().empty() ? tok->str() : tok->originalName(), numFormat + numSecure, numFunction); wrongPrintfScanfArgumentsError(tok, tok->originalName().empty() ? tok->str() : tok->originalName(), numFormat + numSecure, numFunction);
}
}
} }
// We currently only support string literals, variables, and functions. // We currently only support string literals, variables, and functions.

View File

@ -94,6 +94,12 @@ private:
ArgumentInfo operator = (const ArgumentInfo &); // not implemented ArgumentInfo operator = (const ArgumentInfo &); // not implemented
}; };
void checkFormatString(const Token * const tok,
const Token * const formatStringTok,
const Token * argListTok,
const bool scan,
const bool scanf_s);
// Reporting errors.. // Reporting errors..
void coutCerrMisusageError(const Token* tok, const std::string& streamName); void coutCerrMisusageError(const Token* tok, const std::string& streamName);
void fflushOnInputStreamError(const Token *tok, const std::string &varname); void fflushOnInputStreamError(const Token *tok, const std::string &varname);