CheckIO: Refactoring. Split out CheckIO::checkFormatString() from CheckIO::checkWrongPrintfScanfArguments().
This commit is contained in:
parent
0849ad4707
commit
37d9a95ef1
|
@ -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.
|
||||||
|
|
|
@ -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);
|
||||||
|
|
Loading…
Reference in New Issue