Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions cli/cmdlineparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -736,9 +736,9 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
else if (std::strcmp(argv[i], "--doc") == 0) {
std::ostringstream doc;
// Get documentation..
for (std::list<Check *>::iterator it = Check::instances().begin(); it != Check::instances().end(); ++it) {
const std::string& name((*it)->name());
const std::string info((*it)->classInfo());
for (const Check * it : Check::instances()) {
const std::string& name(it->name());
const std::string info(it->classInfo());
if (!name.empty() && !info.empty())
doc << "## " << name << " ##\n"
<< info << "\n";
Expand Down
4 changes: 2 additions & 2 deletions lib/checkbufferoverrun.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,8 @@ void CheckBufferOverrun::arrayIndex()
// Negative index
bool neg = false;
std::vector<const ValueFlow::Value *> negativeIndexes;
for (int i = 0; i < indexTokens.size(); ++i) {
const ValueFlow::Value *negativeValue = indexTokens[i]->getValueLE(-1, mSettings);
for (const Token * indexToken : indexTokens) {
const ValueFlow::Value *negativeValue = indexToken->getValueLE(-1, mSettings);
negativeIndexes.emplace_back(negativeValue);
if (negativeValue)
neg = true;
Expand Down
36 changes: 18 additions & 18 deletions lib/checkclass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -563,23 +563,23 @@ void CheckClass::initVar(nonneg int varid, const Scope *scope, std::vector<Usage

void CheckClass::assignAllVar(std::vector<Usage> &usage)
{
for (int i = 0; i < usage.size(); ++i)
usage[i].assign = true;
for (Usage & i : usage)
i.assign = true;
}

void CheckClass::clearAllVar(std::vector<Usage> &usage)
{
for (int i = 0; i < usage.size(); ++i) {
usage[i].assign = false;
usage[i].init = false;
for (Usage & i : usage) {
i.assign = false;
i.init = false;
}
}

bool CheckClass::isBaseClassFunc(const Token *tok, const Scope *scope)
{
// Iterate through each base class...
for (int i = 0; i < scope->definedType->derivedFrom.size(); ++i) {
const Type *derivedFrom = scope->definedType->derivedFrom[i].type;
for (const Type::BaseInfo & i : scope->definedType->derivedFrom) {
const Type *derivedFrom = i.type;

// Check if base class exists in database
if (derivedFrom && derivedFrom->classScope) {
Expand Down Expand Up @@ -1222,8 +1222,8 @@ void CheckClass::checkMemsetType(const Scope *start, const Token *tok, const Sco
const bool printPortability = mSettings->isEnabled(Settings::PORTABILITY);

// recursively check all parent classes
for (int i = 0; i < type->definedType->derivedFrom.size(); i++) {
const Type* derivedFrom = type->definedType->derivedFrom[i].type;
for (const Type::BaseInfo & i : type->definedType->derivedFrom) {
const Type* derivedFrom = i.type;
if (derivedFrom && derivedFrom->classScope)
checkMemsetType(start, tok, derivedFrom->classScope, allocation, parsedTypes);
}
Expand Down Expand Up @@ -1680,10 +1680,10 @@ void CheckClass::virtualDestructor()
const Token *derivedClass = derived->next();

// Iterate through each base class...
for (int j = 0; j < scope->definedType->derivedFrom.size(); ++j) {
for (const Type::BaseInfo & j : scope->definedType->derivedFrom) {
// Check if base class is public and exists in database
if (scope->definedType->derivedFrom[j].access != AccessControl::Private && scope->definedType->derivedFrom[j].type) {
const Type *derivedFrom = scope->definedType->derivedFrom[j].type;
if (j.access != AccessControl::Private && j.type) {
const Type *derivedFrom = j.type;
const Scope *derivedFromScope = derivedFrom->classScope;
if (!derivedFromScope)
continue;
Expand Down Expand Up @@ -1937,9 +1937,9 @@ bool CheckClass::isMemberVar(const Scope *scope, const Token *tok) const
// not found in this class
if (!scope->definedType->derivedFrom.empty()) {
// check each base class
for (int i = 0; i < scope->definedType->derivedFrom.size(); ++i) {
for (const Type::BaseInfo & i : scope->definedType->derivedFrom) {
// find the base class
const Type *derivedFrom = scope->definedType->derivedFrom[i].type;
const Type *derivedFrom = i.type;

// find the function in the base class
if (derivedFrom && derivedFrom->classScope) {
Expand Down Expand Up @@ -1976,9 +1976,9 @@ bool CheckClass::isMemberFunc(const Scope *scope, const Token *tok) const
// not found in this class
if (!scope->definedType->derivedFrom.empty()) {
// check each base class
for (int i = 0; i < scope->definedType->derivedFrom.size(); ++i) {
for (const Type::BaseInfo & i : scope->definedType->derivedFrom) {
// find the base class
const Type *derivedFrom = scope->definedType->derivedFrom[i].type;
const Type *derivedFrom = i.type;

// find the function in the base class
if (derivedFrom && derivedFrom->classScope) {
Expand All @@ -2001,9 +2001,9 @@ bool CheckClass::isConstMemberFunc(const Scope *scope, const Token *tok) const
// not found in this class
if (!scope->definedType->derivedFrom.empty()) {
// check each base class
for (int i = 0; i < scope->definedType->derivedFrom.size(); ++i) {
for (const Type::BaseInfo & i : scope->definedType->derivedFrom) {
// find the base class
const Type *derivedFrom = scope->definedType->derivedFrom[i].type;
const Type *derivedFrom = i.type;

// find the function in the base class
if (derivedFrom && derivedFrom->classScope) {
Expand Down
4 changes: 2 additions & 2 deletions lib/checkio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1561,8 +1561,8 @@ bool CheckIO::ArgumentInfo::isStdVectorOrString()
return true;
} else if (variableInfo->type() && !variableInfo->type()->derivedFrom.empty()) {
const std::vector<Type::BaseInfo>& derivedFrom = variableInfo->type()->derivedFrom;
for (std::size_t i = 0, size = derivedFrom.size(); i < size; ++i) {
const Token* nameTok = derivedFrom[i].nameTok;
for (const Type::BaseInfo & i : derivedFrom) {
const Token* nameTok = i.nameTok;
if (Token::Match(nameTok, "std :: vector|array <")) {
typeToken = nameTok->tokAt(4);
_template = true;
Expand Down
3 changes: 1 addition & 2 deletions lib/checkstring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,7 @@ void CheckString::checkSuspiciousStringCompare()
// Pointer addition?
if (varTok->str() == "+" && mTokenizer->isC()) {
const Token * const tokens[2] = { varTok->astOperand1(), varTok->astOperand2() };
for (int nr = 0; nr < 2; nr++) {
const Token *t = tokens[nr];
for (const Token * t : tokens) {
while (t && (t->str() == "." || t->str() == "::"))
t = t->astOperand2();
if (t && t->variable() && t->variable()->isPointer())
Expand Down
7 changes: 3 additions & 4 deletions lib/errorlogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -638,8 +638,7 @@ std::string ErrorLogger::ErrorMessage::FileLocation::stringify() const
std::string ErrorLogger::toxml(const std::string &str)
{
std::ostringstream xml;
for (std::size_t i = 0U; i < str.length(); i++) {
const unsigned char c = str[i];
for (unsigned char c : str) {
switch (c) {
case '<':
xml << "&lt;";
Expand Down Expand Up @@ -678,8 +677,8 @@ std::string ErrorLogger::plistHeader(const std::string &version, const std::vect
<< "<string>cppcheck version " << version << "</string>\r\n"
<< " <key>files</key>\r\n"
<< " <array>\r\n";
for (unsigned int i = 0; i < files.size(); ++i)
ostr << " <string>" << ErrorLogger::toxml(files[i]) << "</string>\r\n";
for (const std::string & file : files)
ostr << " <string>" << ErrorLogger::toxml(file) << "</string>\r\n";
ostr << " </array>\r\n"
<< " <key>diagnostics</key>\r\n"
<< " <array>\r\n";
Expand Down
6 changes: 3 additions & 3 deletions lib/importproject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -736,13 +736,13 @@ void ImportProject::importBcb6Prj(const std::string &projectFilename)
{
std::string arg;

for (int i = 0; i < cflag1.size(); ++i) {
if (cflag1.at(i) == ' ' && !arg.empty()) {
for (char i : cflag1) {
if (i == ' ' && !arg.empty()) {
cflags.insert(arg);
arg.clear();
continue;
}
arg += cflag1.at(i);
arg += i;
}

if (!arg.empty()) {
Expand Down
3 changes: 1 addition & 2 deletions lib/library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -869,8 +869,7 @@ std::string Library::getFunctionName(const Token *ftok, bool *error) const
if (!scope->isClassOrStruct())
continue;
const std::vector<Type::BaseInfo> &derivedFrom = scope->definedType->derivedFrom;
for (unsigned int i = 0; i < derivedFrom.size(); ++i) {
const Type::BaseInfo &baseInfo = derivedFrom[i];
for (const Type::BaseInfo & baseInfo : derivedFrom) {
const std::string name(baseInfo.name + "::" + ftok->str());
if (functions.find(name) != functions.end() && matchArguments(ftok, name))
return name;
Expand Down
10 changes: 5 additions & 5 deletions lib/mathlib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,8 @@ MathLib::biguint MathLib::toULongNumber(const std::string & str)
static unsigned int encodeMultiChar(const std::string& str)
{
unsigned int retval = 0;
for (std::string::const_iterator it=str.begin(); it!=str.end(); ++it) {
retval = (retval << 8) | *it;
for (char it : str) {
retval = (retval << 8) | it;
}
return retval;
}
Expand Down Expand Up @@ -1338,10 +1338,10 @@ bool MathLib::isNullValue(const std::string &str)
if (str.empty() || (!std::isdigit(static_cast<unsigned char>(str[0])) && (str[0] != '.' && str[0] != '-' && str[0] != '+')))
return false; // Has to be a number

for (size_t i = 0; i < str.size(); i++) {
if (std::isdigit(static_cast<unsigned char>(str[i])) && str[i] != '0') // May not contain digits other than 0
for (char i : str) {
if (std::isdigit(static_cast<unsigned char>(i)) && i != '0') // May not contain digits other than 0
return false;
if (str[i] == 'E' || str[i] == 'e')
if (i == 'E' || i == 'e')
return true;
}
return true;
Expand Down
4 changes: 2 additions & 2 deletions lib/platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ bool cppcheck::Platform::loadPlatformFile(const char exename[], const std::strin
filenames.push_back(filesdir + ("platforms/" + filename + ".xml"));
#endif
bool success = false;
for (int i = 0; i < filenames.size(); ++i) {
if (doc.LoadFile(filenames[i].c_str()) == tinyxml2::XML_SUCCESS) {
for (const std::string & f : filenames) {
if (doc.LoadFile(f.c_str()) == tinyxml2::XML_SUCCESS) {
success = true;
break;
}
Expand Down
8 changes: 4 additions & 4 deletions lib/preprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ static void inlineSuppressions(const simplecpp::TokenList &tokens, Settings &mSe
// Relative filename
std::string relativeFilename(tok->location.file());
if (mSettings.relativePaths) {
for (std::size_t j = 0U; j < mSettings.basePaths.size(); ++j) {
const std::string bp = mSettings.basePaths[j] + "/";
for (const std::string & basePath : mSettings.basePaths) {
const std::string bp = basePath + "/";
if (relativeFilename.compare(0,bp.size(),bp)==0) {
relativeFilename = relativeFilename.substr(bp.size());
}
Expand Down Expand Up @@ -891,8 +891,8 @@ static const std::uint32_t crc32Table[] = {
static std::uint32_t crc32(const std::string &data)
{
std::uint32_t crc = ~0U;
for (std::string::const_iterator c = data.begin(); c != data.end(); ++c) {
crc = crc32Table[(crc ^ (unsigned char)(*c)) & 0xFF] ^ (crc >> 8);
for (char c : data) {
crc = crc32Table[(crc ^ (unsigned char)c) & 0xFF] ^ (crc >> 8);
}
return crc ^ ~0U;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,8 @@ class CPPCHECKLIB Settings : public cppcheck::Platform {
* @return true for the file to be excluded.
*/
bool configurationExcluded(const std::string &file) const {
for (std::set<std::string>::const_iterator i=configExcludePaths.begin(); i!=configExcludePaths.end(); ++i) {
if (file.length()>=i->length() && file.compare(0,i->length(),*i)==0) {
for (const std::string & configExcludePath : configExcludePaths) {
if (file.length()>=configExcludePath.length() && file.compare(0,configExcludePath.length(),configExcludePath)==0) {
return true;
}
}
Expand Down
42 changes: 20 additions & 22 deletions lib/symboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1223,8 +1223,8 @@ void SymbolDatabase::createSymbolDatabaseEnums()
continue;

// add enumerators to enumerator tokens
for (std::size_t i = 0, end = it->enumeratorList.size(); i < end; ++i)
const_cast<Token *>(it->enumeratorList[i].name)->enumerator(&it->enumeratorList[i]);
for (Enumerator & i : it->enumeratorList)
const_cast<Token *>(i.name)->enumerator(&i);
}

// fill in enumerator values
Expand All @@ -1234,9 +1234,7 @@ void SymbolDatabase::createSymbolDatabaseEnums()

MathLib::bigint value = 0;

for (std::size_t i = 0, end = it->enumeratorList.size(); i < end; ++i) {
Enumerator & enumerator = it->enumeratorList[i];

for (Enumerator & enumerator : it->enumeratorList) {
// look for initialization tokens that can be converted to enumerators and convert them
if (enumerator.start) {
if (!enumerator.end)
Expand Down Expand Up @@ -2572,9 +2570,9 @@ const Function* Type::getFunction(const std::string& funcName) const
return it->second;
}

for (std::size_t i = 0; i < derivedFrom.size(); i++) {
if (derivedFrom[i].type) {
const Function* const func = derivedFrom[i].type->getFunction(funcName);
for (const Type::BaseInfo & i : derivedFrom) {
if (i.type) {
const Function* const func = i.type->getFunction(funcName);
if (func)
return func;
}
Expand Down Expand Up @@ -3039,21 +3037,21 @@ void SymbolDatabase::printOut(const char *title) const

std::cout << " derivedFrom[" << type->derivedFrom.size() << "] = (";
std::size_t count = type->derivedFrom.size();
for (std::size_t i = 0; i < type->derivedFrom.size(); ++i) {
if (type->derivedFrom[i].isVirtual)
for (const Type::BaseInfo & i : type->derivedFrom) {
if (i.isVirtual)
std::cout << "Virtual ";

std::cout << (type->derivedFrom[i].access == AccessControl::Public ? " Public" :
type->derivedFrom[i].access == AccessControl::Protected ? " Protected" :
type->derivedFrom[i].access == AccessControl::Private ? " Private" :
std::cout << (i.access == AccessControl::Public ? " Public" :
i.access == AccessControl::Protected ? " Protected" :
i.access == AccessControl::Private ? " Private" :
" Unknown");

if (type->derivedFrom[i].type)
std::cout << " " << type->derivedFrom[i].type;
if (i.type)
std::cout << " " << i.type;
else
std::cout << " Unknown";

std::cout << " " << type->derivedFrom[i].name;
std::cout << " " << i.name;
if (count-- > 1)
std::cout << ",";
}
Expand Down Expand Up @@ -3940,8 +3938,8 @@ const Enumerator * SymbolDatabase::findEnumerator(const Token * tok) const

if (scope->definedType) {
const std::vector<Type::BaseInfo> & derivedFrom = scope->definedType->derivedFrom;
for (size_t i = 0, end = derivedFrom.size(); i < end; ++i) {
const Type *derivedFromType = derivedFrom[i].type;
for (const Type::BaseInfo & i : derivedFrom) {
const Type *derivedFromType = i.type;
if (derivedFromType && derivedFromType ->classScope) {
enumerator = derivedFromType->classScope->findEnumerator(tokStr);

Expand Down Expand Up @@ -3982,8 +3980,8 @@ const Type* SymbolDatabase::findVariableTypeInBase(const Scope* scope, const Tok
{
if (scope && scope->definedType && !scope->definedType->derivedFrom.empty()) {
const std::vector<Type::BaseInfo> &derivedFrom = scope->definedType->derivedFrom;
for (std::size_t i = 0; i < derivedFrom.size(); ++i) {
const Type *base = derivedFrom[i].type;
for (const Type::BaseInfo & i : derivedFrom) {
const Type *base = i.type;
if (base && base->classScope) {
const Type * type = base->classScope->findType(typeTok->str());
if (type)
Expand Down Expand Up @@ -4131,8 +4129,8 @@ void Scope::findFunctionInBase(const std::string & name, nonneg int args, std::v
{
if (isClassOrStruct() && definedType && !definedType->derivedFrom.empty()) {
const std::vector<Type::BaseInfo> &derivedFrom = definedType->derivedFrom;
for (std::size_t i = 0; i < derivedFrom.size(); ++i) {
const Type *base = derivedFrom[i].type;
for (const Type::BaseInfo & i : derivedFrom) {
const Type *base = i.type;
if (base && base->classScope) {
if (base->classScope == this) // Ticket #5120, #5125: Recursive class; tok should have been found already
continue;
Expand Down
6 changes: 3 additions & 3 deletions lib/symboldatabase.h
Original file line number Diff line number Diff line change
Expand Up @@ -989,9 +989,9 @@ class CPPCHECKLIB Scope {
std::vector<Enumerator> enumeratorList;

const Enumerator * findEnumerator(const std::string & name) const {
for (int i = 0, end = enumeratorList.size(); i < end; ++i) {
if (enumeratorList[i].name->str() == name)
return &enumeratorList[i];
for (const Enumerator & i : enumeratorList) {
if (i.name->str() == name)
return &i;
}
return nullptr;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/templatesimplifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3641,8 +3641,8 @@ void TemplateSimplifier::simplifyTemplates(
}

// remove explicit instantiations
for (size_t j = 0; j < mExplicitInstantiationsToDelete.size(); ++j) {
Token * start = mExplicitInstantiationsToDelete[j].token();
for (TokenAndName & j : mExplicitInstantiationsToDelete) {
Token * start = j.token();
if (start) {
Token * end = start->next();
while (end && end->str() != ";")
Expand Down
Loading