replace 'unsigned' with 'nonneg' in checkio
This commit is contained in:
parent
5dc4f44091
commit
a038ba7dce
|
@ -101,9 +101,9 @@ static OpenMode getMode(const std::string& str)
|
|||
|
||||
struct Filepointer {
|
||||
OpenMode mode;
|
||||
unsigned int mode_indent;
|
||||
nonneg int mode_indent;
|
||||
enum Operation {NONE, UNIMPORTANT, READ, WRITE, POSITIONING, OPEN, CLOSE, UNKNOWN_OP} lastOperation;
|
||||
unsigned int op_indent;
|
||||
nonneg int op_indent;
|
||||
enum AppendMode { UNKNOWN_AM, APPEND, APPEND_EX };
|
||||
AppendMode append_mode;
|
||||
explicit Filepointer(OpenMode mode_ = UNKNOWN_OM)
|
||||
|
@ -121,7 +121,7 @@ void CheckIO::checkFileUsage()
|
|||
const bool printPortability = mSettings->isEnabled(Settings::PORTABILITY);
|
||||
const bool printWarnings = mSettings->isEnabled(Settings::WARNING);
|
||||
|
||||
std::map<unsigned int, Filepointer> filepointers;
|
||||
std::map<int, Filepointer> filepointers;
|
||||
|
||||
const SymbolDatabase* symbolDatabase = mTokenizer->getSymbolDatabase();
|
||||
for (const Variable* var : symbolDatabase->variableList()) {
|
||||
|
@ -140,13 +140,13 @@ void CheckIO::checkFileUsage()
|
|||
}
|
||||
|
||||
for (const Scope * scope : symbolDatabase->functionScopes) {
|
||||
unsigned int indent = 0;
|
||||
int indent = 0;
|
||||
for (const Token *tok = scope->bodyStart; tok != scope->bodyEnd; tok = tok->next()) {
|
||||
if (tok->str() == "{")
|
||||
indent++;
|
||||
else if (tok->str() == "}") {
|
||||
indent--;
|
||||
for (std::map<unsigned int, Filepointer>::iterator i = filepointers.begin(); i != filepointers.end(); ++i) {
|
||||
for (std::map<int, Filepointer>::iterator i = filepointers.begin(); i != filepointers.end(); ++i) {
|
||||
if (indent < i->second.mode_indent) {
|
||||
i->second.mode_indent = 0;
|
||||
i->second.mode = UNKNOWN_OM;
|
||||
|
@ -157,7 +157,7 @@ void CheckIO::checkFileUsage()
|
|||
}
|
||||
}
|
||||
} else if (tok->str() == "return" || tok->str() == "continue" || tok->str() == "break" || mSettings->library.isnoreturn(tok)) { // Reset upon return, continue or break
|
||||
for (std::map<unsigned int, Filepointer>::iterator i = filepointers.begin(); i != filepointers.end(); ++i) {
|
||||
for (std::map<int, Filepointer>::iterator i = filepointers.begin(); i != filepointers.end(); ++i) {
|
||||
i->second.mode_indent = 0;
|
||||
i->second.mode = UNKNOWN_OM;
|
||||
i->second.op_indent = 0;
|
||||
|
@ -166,7 +166,7 @@ void CheckIO::checkFileUsage()
|
|||
} else if (Token::Match(tok, "%var% =") &&
|
||||
(tok->strAt(2) != "fopen" && tok->strAt(2) != "freopen" && tok->strAt(2) != "tmpfile" &&
|
||||
(windows ? (tok->str() != "_wfopen" && tok->str() != "_wfreopen") : true))) {
|
||||
std::map<unsigned int, Filepointer>::iterator i = filepointers.find(tok->varId());
|
||||
std::map<int, Filepointer>::iterator i = filepointers.find(tok->varId());
|
||||
if (i != filepointers.end()) {
|
||||
i->second.mode = UNKNOWN_OM;
|
||||
i->second.lastOperation = Filepointer::UNKNOWN_OP;
|
||||
|
@ -236,7 +236,7 @@ void CheckIO::checkFileUsage()
|
|||
const Token* const end2 = tok->linkAt(1);
|
||||
if (scope->functionOf && scope->functionOf->isClassOrStruct() && !scope->function->isStatic() && ((tok->strAt(-1) != "::" && tok->strAt(-1) != ".") || tok->strAt(-2) == "this")) {
|
||||
if (!tok->function() || (tok->function()->nestedIn && tok->function()->nestedIn->isClassOrStruct())) {
|
||||
for (std::map<unsigned int, Filepointer>::iterator i = filepointers.begin(); i != filepointers.end(); ++i) {
|
||||
for (std::map<int, Filepointer>::iterator i = filepointers.begin(); i != filepointers.end(); ++i) {
|
||||
const Variable* var = symbolDatabase->getVariableFromVarId(i->first);
|
||||
if (!var || !(var->isLocal() || var->isGlobal() || var->isStatic())) {
|
||||
i->second.mode = UNKNOWN_OM;
|
||||
|
@ -326,7 +326,7 @@ void CheckIO::checkFileUsage()
|
|||
}
|
||||
}
|
||||
}
|
||||
for (std::map<unsigned int, Filepointer>::iterator i = filepointers.begin(); i != filepointers.end(); ++i) {
|
||||
for (std::map<int, Filepointer>::iterator i = filepointers.begin(); i != filepointers.end(); ++i) {
|
||||
i->second.op_indent = 0;
|
||||
i->second.mode = UNKNOWN_OM;
|
||||
i->second.lastOperation = Filepointer::UNKNOWN_OP;
|
||||
|
@ -451,12 +451,12 @@ void CheckIO::invalidScanfError(const Token *tok)
|
|||
// printf("", 1); // Too much arguments
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
static bool findFormat(unsigned int arg, const Token *firstArg,
|
||||
static bool findFormat(nonneg int arg, const Token *firstArg,
|
||||
const Token **formatStringTok, const Token **formatArgTok)
|
||||
{
|
||||
const Token* argTok = firstArg;
|
||||
|
||||
for (unsigned int i = 0; i < arg && argTok; ++i)
|
||||
for (int i = 0; i < arg && argTok; ++i)
|
||||
argTok = argTok->nextArgument();
|
||||
|
||||
if (Token::Match(argTok, "%str% [,)]")) {
|
||||
|
@ -514,7 +514,7 @@ void CheckIO::checkWrongPrintfScanfArguments()
|
|||
|
||||
if (formatStringArgNo >= 0) {
|
||||
// formatstring found in library. Find format string and first argument belonging to format string.
|
||||
if (!findFormat(static_cast<unsigned int>(formatStringArgNo), tok->tokAt(2), &formatStringTok, &argListTok))
|
||||
if (!findFormat(formatStringArgNo, tok->tokAt(2), &formatStringTok, &argListTok))
|
||||
continue;
|
||||
} else if (Token::simpleMatch(tok, "swprintf (")) {
|
||||
if (Token::Match(tok->tokAt(2)->nextArgument(), "%str%")) {
|
||||
|
@ -570,11 +570,11 @@ void CheckIO::checkFormatString(const Token * const tok,
|
|||
const std::string &formatString = formatStringTok->str();
|
||||
|
||||
// Count format string parameters..
|
||||
unsigned int numFormat = 0;
|
||||
unsigned int numSecure = 0;
|
||||
int numFormat = 0;
|
||||
int numSecure = 0;
|
||||
bool percent = false;
|
||||
const Token* argListTok2 = argListTok;
|
||||
std::set<unsigned int> parameterPositionsUsed;
|
||||
std::set<int> parameterPositionsUsed;
|
||||
for (std::string::const_iterator i = formatString.begin(); i != formatString.end(); ++i) {
|
||||
if (*i == '%') {
|
||||
percent = !percent;
|
||||
|
@ -603,7 +603,7 @@ void CheckIO::checkFormatString(const Token * const tok,
|
|||
bool _continue = false;
|
||||
bool skip = false;
|
||||
std::string width;
|
||||
unsigned int parameterPosition = 0;
|
||||
int parameterPosition = 0;
|
||||
bool hasParameterPosition = false;
|
||||
while (i != formatString.end() && *i != '[' && !std::isalpha((unsigned char)*i)) {
|
||||
if (*i == '*') {
|
||||
|
@ -618,7 +618,7 @@ void CheckIO::checkFormatString(const Token * const tok,
|
|||
} else if (std::isdigit(*i)) {
|
||||
width += *i;
|
||||
} else if (*i == '$') {
|
||||
parameterPosition = static_cast<unsigned int>(std::atoi(width.c_str()));
|
||||
parameterPosition = std::atoi(width.c_str());
|
||||
hasParameterPosition = true;
|
||||
width.clear();
|
||||
}
|
||||
|
@ -1282,7 +1282,7 @@ void CheckIO::checkFormatString(const Token * const tok,
|
|||
}
|
||||
|
||||
// Count printf/scanf parameters..
|
||||
unsigned int numFunction = 0;
|
||||
int numFunction = 0;
|
||||
while (argListTok2) {
|
||||
numFunction++;
|
||||
argListTok2 = argListTok2->nextArgument(); // Find next argument
|
||||
|
@ -1290,7 +1290,7 @@ void CheckIO::checkFormatString(const Token * const tok,
|
|||
|
||||
if (printWarning) {
|
||||
// Check that all parameter positions reference an actual parameter
|
||||
for (unsigned int i : parameterPositionsUsed) {
|
||||
for (int i : parameterPositionsUsed) {
|
||||
if ((i == 0) || (i > numFormat))
|
||||
wrongPrintfScanfPosixParameterPositionError(tok, tok->str(), i, numFormat);
|
||||
}
|
||||
|
@ -1362,7 +1362,7 @@ CheckIO::ArgumentInfo::ArgumentInfo(const Token * arg, const Settings *settings,
|
|||
}
|
||||
if (!valuetype->originalTypeName.empty())
|
||||
tempToken->originalName(valuetype->originalTypeName);
|
||||
for (unsigned int p = 0; p < valuetype->pointer; p++)
|
||||
for (int p = 0; p < valuetype->pointer; p++)
|
||||
tempToken->insertToken("*");
|
||||
tempToken = const_cast<Token*>(typeToken);
|
||||
return;
|
||||
|
@ -1678,8 +1678,8 @@ bool CheckIO::ArgumentInfo::isLibraryType(const Settings *settings) const
|
|||
|
||||
void CheckIO::wrongPrintfScanfArgumentsError(const Token* tok,
|
||||
const std::string &functionName,
|
||||
unsigned int numFormat,
|
||||
unsigned int numFunction)
|
||||
nonneg int numFormat,
|
||||
nonneg int numFunction)
|
||||
{
|
||||
const Severity::SeverityType severity = numFormat > numFunction ? Severity::error : Severity::warning;
|
||||
if (severity != Severity::error && !mSettings->isEnabled(Settings::WARNING))
|
||||
|
@ -1699,7 +1699,7 @@ void CheckIO::wrongPrintfScanfArgumentsError(const Token* tok,
|
|||
}
|
||||
|
||||
void CheckIO::wrongPrintfScanfPosixParameterPositionError(const Token* tok, const std::string& functionName,
|
||||
unsigned int index, unsigned int numFunction)
|
||||
nonneg int index, nonneg int numFunction)
|
||||
{
|
||||
if (!mSettings->isEnabled(Settings::WARNING))
|
||||
return;
|
||||
|
@ -1713,7 +1713,7 @@ void CheckIO::wrongPrintfScanfPosixParameterPositionError(const Token* tok, cons
|
|||
reportError(tok, Severity::warning, "wrongPrintfScanfParameterPositionError", errmsg.str(), CWE685, false);
|
||||
}
|
||||
|
||||
void CheckIO::invalidScanfArgTypeError_s(const Token* tok, unsigned int numFormat, const std::string& specifier, const ArgumentInfo* argInfo)
|
||||
void CheckIO::invalidScanfArgTypeError_s(const Token* tok, nonneg int numFormat, const std::string& specifier, const ArgumentInfo* argInfo)
|
||||
{
|
||||
const Severity::SeverityType severity = getSeverity(argInfo);
|
||||
if (!mSettings->isEnabled(severity))
|
||||
|
@ -1729,7 +1729,7 @@ void CheckIO::invalidScanfArgTypeError_s(const Token* tok, unsigned int numForma
|
|||
errmsg << ".";
|
||||
reportError(tok, severity, "invalidScanfArgType_s", errmsg.str(), CWE686, false);
|
||||
}
|
||||
void CheckIO::invalidScanfArgTypeError_int(const Token* tok, unsigned int numFormat, const std::string& specifier, const ArgumentInfo* argInfo, bool isUnsigned)
|
||||
void CheckIO::invalidScanfArgTypeError_int(const Token* tok, nonneg int numFormat, const std::string& specifier, const ArgumentInfo* argInfo, bool isUnsigned)
|
||||
{
|
||||
const Severity::SeverityType severity = getSeverity(argInfo);
|
||||
if (!mSettings->isEnabled(severity))
|
||||
|
@ -1793,7 +1793,7 @@ void CheckIO::invalidScanfArgTypeError_float(const Token* tok, unsigned int numF
|
|||
reportError(tok, severity, "invalidScanfArgType_float", errmsg.str(), CWE686, false);
|
||||
}
|
||||
|
||||
void CheckIO::invalidPrintfArgTypeError_s(const Token* tok, unsigned int numFormat, const ArgumentInfo* argInfo)
|
||||
void CheckIO::invalidPrintfArgTypeError_s(const Token* tok, nonneg int numFormat, const ArgumentInfo* argInfo)
|
||||
{
|
||||
const Severity::SeverityType severity = getSeverity(argInfo);
|
||||
if (!mSettings->isEnabled(severity))
|
||||
|
@ -1804,7 +1804,7 @@ void CheckIO::invalidPrintfArgTypeError_s(const Token* tok, unsigned int numForm
|
|||
errmsg << ".";
|
||||
reportError(tok, severity, "invalidPrintfArgType_s", errmsg.str(), CWE686, false);
|
||||
}
|
||||
void CheckIO::invalidPrintfArgTypeError_n(const Token* tok, unsigned int numFormat, const ArgumentInfo* argInfo)
|
||||
void CheckIO::invalidPrintfArgTypeError_n(const Token* tok, nonneg int numFormat, const ArgumentInfo* argInfo)
|
||||
{
|
||||
const Severity::SeverityType severity = getSeverity(argInfo);
|
||||
if (!mSettings->isEnabled(severity))
|
||||
|
@ -1815,7 +1815,7 @@ void CheckIO::invalidPrintfArgTypeError_n(const Token* tok, unsigned int numForm
|
|||
errmsg << ".";
|
||||
reportError(tok, severity, "invalidPrintfArgType_n", errmsg.str(), CWE686, false);
|
||||
}
|
||||
void CheckIO::invalidPrintfArgTypeError_p(const Token* tok, unsigned int numFormat, const ArgumentInfo* argInfo)
|
||||
void CheckIO::invalidPrintfArgTypeError_p(const Token* tok, nonneg int numFormat, const ArgumentInfo* argInfo)
|
||||
{
|
||||
const Severity::SeverityType severity = getSeverity(argInfo);
|
||||
if (!mSettings->isEnabled(severity))
|
||||
|
@ -1865,7 +1865,7 @@ static void printfFormatType(std::ostream& os, const std::string& specifier, boo
|
|||
os << "\'";
|
||||
}
|
||||
|
||||
void CheckIO::invalidPrintfArgTypeError_uint(const Token* tok, unsigned int numFormat, const std::string& specifier, const ArgumentInfo* argInfo)
|
||||
void CheckIO::invalidPrintfArgTypeError_uint(const Token* tok, nonneg int numFormat, const std::string& specifier, const ArgumentInfo* argInfo)
|
||||
{
|
||||
const Severity::SeverityType severity = getSeverity(argInfo);
|
||||
if (!mSettings->isEnabled(severity))
|
||||
|
@ -1879,7 +1879,7 @@ void CheckIO::invalidPrintfArgTypeError_uint(const Token* tok, unsigned int numF
|
|||
reportError(tok, severity, "invalidPrintfArgType_uint", errmsg.str(), CWE686, false);
|
||||
}
|
||||
|
||||
void CheckIO::invalidPrintfArgTypeError_sint(const Token* tok, unsigned int numFormat, const std::string& specifier, const ArgumentInfo* argInfo)
|
||||
void CheckIO::invalidPrintfArgTypeError_sint(const Token* tok, nonneg int numFormat, const std::string& specifier, const ArgumentInfo* argInfo)
|
||||
{
|
||||
const Severity::SeverityType severity = getSeverity(argInfo);
|
||||
if (!mSettings->isEnabled(severity))
|
||||
|
@ -1892,7 +1892,7 @@ void CheckIO::invalidPrintfArgTypeError_sint(const Token* tok, unsigned int numF
|
|||
errmsg << ".";
|
||||
reportError(tok, severity, "invalidPrintfArgType_sint", errmsg.str(), CWE686, false);
|
||||
}
|
||||
void CheckIO::invalidPrintfArgTypeError_float(const Token* tok, unsigned int numFormat, const std::string& specifier, const ArgumentInfo* argInfo)
|
||||
void CheckIO::invalidPrintfArgTypeError_float(const Token* tok, nonneg int numFormat, const std::string& specifier, const ArgumentInfo* argInfo)
|
||||
{
|
||||
const Severity::SeverityType severity = getSeverity(argInfo);
|
||||
if (!mSettings->isEnabled(severity))
|
||||
|
@ -1963,7 +1963,7 @@ void CheckIO::argumentType(std::ostream& os, const ArgumentInfo * argInfo)
|
|||
os << "Unknown";
|
||||
}
|
||||
|
||||
void CheckIO::invalidLengthModifierError(const Token* tok, unsigned int numFormat, const std::string& modifier)
|
||||
void CheckIO::invalidLengthModifierError(const Token* tok, nonneg int numFormat, const std::string& modifier)
|
||||
{
|
||||
if (!mSettings->isEnabled(Settings::WARNING))
|
||||
return;
|
||||
|
@ -1972,7 +1972,7 @@ void CheckIO::invalidLengthModifierError(const Token* tok, unsigned int numForma
|
|||
reportError(tok, Severity::warning, "invalidLengthModifierError", errmsg.str(), CWE704, false);
|
||||
}
|
||||
|
||||
void CheckIO::invalidScanfFormatWidthError(const Token* tok, unsigned int numFormat, int width, const Variable *var, char c)
|
||||
void CheckIO::invalidScanfFormatWidthError(const Token* tok, nonneg int numFormat, int width, const Variable *var, char c)
|
||||
{
|
||||
MathLib::bigint arrlen = 0;
|
||||
std::string varname;
|
||||
|
|
|
@ -115,21 +115,21 @@ private:
|
|||
void invalidScanfError(const Token *tok);
|
||||
void wrongPrintfScanfArgumentsError(const Token* tok,
|
||||
const std::string &functionName,
|
||||
unsigned int numFormat,
|
||||
unsigned int numFunction);
|
||||
nonneg int numFormat,
|
||||
nonneg int numFunction);
|
||||
void wrongPrintfScanfPosixParameterPositionError(const Token* tok, const std::string& functionName,
|
||||
unsigned int index, unsigned int numFunction);
|
||||
void invalidScanfArgTypeError_s(const Token* tok, unsigned int numFormat, const std::string& specifier, const ArgumentInfo* argInfo);
|
||||
void invalidScanfArgTypeError_int(const Token* tok, unsigned int numFormat, const std::string& specifier, const ArgumentInfo* argInfo, bool isUnsigned);
|
||||
void invalidScanfArgTypeError_float(const Token* tok, unsigned int numFormat, const std::string& specifier, const ArgumentInfo* argInfo);
|
||||
void invalidPrintfArgTypeError_s(const Token* tok, unsigned int numFormat, const ArgumentInfo* argInfo);
|
||||
void invalidPrintfArgTypeError_n(const Token* tok, unsigned int numFormat, const ArgumentInfo* argInfo);
|
||||
void invalidPrintfArgTypeError_p(const Token* tok, unsigned int numFormat, const ArgumentInfo* argInfo);
|
||||
void invalidPrintfArgTypeError_uint(const Token* tok, unsigned int numFormat, const std::string& specifier, const ArgumentInfo* argInfo);
|
||||
void invalidPrintfArgTypeError_sint(const Token* tok, unsigned int numFormat, const std::string& specifier, const ArgumentInfo* argInfo);
|
||||
void invalidPrintfArgTypeError_float(const Token* tok, unsigned int numFormat, const std::string& specifier, const ArgumentInfo* argInfo);
|
||||
void invalidLengthModifierError(const Token* tok, unsigned int numFormat, const std::string& modifier);
|
||||
void invalidScanfFormatWidthError(const Token* tok, unsigned int numFormat, int width, const Variable *var, char c);
|
||||
nonneg int index, nonneg int numFunction);
|
||||
void invalidScanfArgTypeError_s(const Token* tok, nonneg int numFormat, const std::string& specifier, const ArgumentInfo* argInfo);
|
||||
void invalidScanfArgTypeError_int(const Token* tok, nonneg int numFormat, const std::string& specifier, const ArgumentInfo* argInfo, bool isUnsigned);
|
||||
void invalidScanfArgTypeError_float(const Token* tok, nonneg int numFormat, const std::string& specifier, const ArgumentInfo* argInfo);
|
||||
void invalidPrintfArgTypeError_s(const Token* tok, nonneg int numFormat, const ArgumentInfo* argInfo);
|
||||
void invalidPrintfArgTypeError_n(const Token* tok, nonneg int numFormat, const ArgumentInfo* argInfo);
|
||||
void invalidPrintfArgTypeError_p(const Token* tok, nonneg int numFormat, const ArgumentInfo* argInfo);
|
||||
void invalidPrintfArgTypeError_uint(const Token* tok, nonneg int numFormat, const std::string& specifier, const ArgumentInfo* argInfo);
|
||||
void invalidPrintfArgTypeError_sint(const Token* tok, nonneg int numFormat, const std::string& specifier, const ArgumentInfo* argInfo);
|
||||
void invalidPrintfArgTypeError_float(const Token* tok, nonneg int numFormat, const std::string& specifier, const ArgumentInfo* argInfo);
|
||||
void invalidLengthModifierError(const Token* tok, nonneg int numFormat, const std::string& modifier);
|
||||
void invalidScanfFormatWidthError(const Token* tok, nonneg int numFormat, int width, const Variable *var, char c);
|
||||
static void argumentType(std::ostream & os, const ArgumentInfo * argInfo);
|
||||
static Severity::SeverityType getSeverity(const ArgumentInfo *argInfo);
|
||||
|
||||
|
|
Loading…
Reference in New Issue