Skip to content
Closed
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 gui/filelist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ void FileList::addExcludeList(const QStringList &paths)
mExcludedPaths = paths;
}

static std::vector<std::string> toStdStringList(const QStringList &stringList)
static std::vector<std::string> toStdStringList2(const QStringList &stringList)
{
std::vector<std::string> ret;
std::transform(stringList.cbegin(), stringList.cend(), std::back_inserter(ret), [](const QString& s) {
Expand All @@ -120,9 +120,9 @@ static std::vector<std::string> toStdStringList(const QStringList &stringList)
QStringList FileList::applyExcludeList() const
{
#ifdef _WIN32
const PathMatch pathMatch(toStdStringList(mExcludedPaths), true);
const PathMatch pathMatch(toStdStringList2(mExcludedPaths), true);
#else
const PathMatch pathMatch(toStdStringList(mExcludedPaths), false);
const PathMatch pathMatch(toStdStringList2(mExcludedPaths), false);
#endif

QStringList paths;
Expand Down
2 changes: 2 additions & 0 deletions gui/test/cppchecklibrarydata/testcppchecklibrarydata.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#pragma once

#include "cppchecklibrarydata.h"

#include <QObject>
Expand Down
2 changes: 2 additions & 0 deletions gui/test/filelist/testfilelist.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#pragma once

#include <QObject>
#include <QString>

Expand Down
2 changes: 2 additions & 0 deletions gui/test/projectfile/testprojectfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#pragma once

#include <QObject>
#include <QString>

Expand Down
2 changes: 2 additions & 0 deletions gui/test/translationhandler/testtranslationhandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#pragma once

#include <QObject>
#include <QString>

Expand Down
2 changes: 2 additions & 0 deletions gui/test/xmlreportv2/testxmlreportv2.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#pragma once

#include <QObject>
#include <QString>

Expand Down
10 changes: 5 additions & 5 deletions gui/xmlreport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
#include <QStringRef>
#endif

static constexpr char ResultElementName[] = "results";
static constexpr char VersionAttribute[] = "version";
static constexpr char ResultElementName2[] = "results";
static constexpr char VersionAttribute2[] = "version";

XmlReport::XmlReport(const QString &filename) :
Report(filename)
Expand Down Expand Up @@ -70,10 +70,10 @@ int XmlReport::determineVersion(const QString &filename)
while (!reader.atEnd()) {
switch (reader.readNext()) {
case QXmlStreamReader::StartElement:
if (reader.name() == QString(ResultElementName)) {
if (reader.name() == QString(ResultElementName2)) {
QXmlStreamAttributes attribs = reader.attributes();
if (attribs.hasAttribute(QString(VersionAttribute))) {
const int ver = attribs.value(QString(), VersionAttribute).toString().toInt();
if (attribs.hasAttribute(QString(VersionAttribute2))) {
const int ver = attribs.value(QString(), VersionAttribute2).toString().toInt();
return ver;
}
return 1;
Expand Down
4 changes: 1 addition & 3 deletions lib/check64bit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,10 @@

//---------------------------------------------------------------------------

// CWE ids used
static const CWE CWE758(758U); // Reliance on Undefined, Unspecified, or Implementation-Defined Behavior

// Register this check class (by creating a static instance of it)
namespace {
Check64BitPortability instance;
Check64BitPortability instance64BitPortability;
}

void Check64BitPortability::pointerassignment()
Expand Down
4 changes: 1 addition & 3 deletions lib/checkassert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,10 @@

//---------------------------------------------------------------------------

// CWE ids used
static const CWE CWE398(398U); // Indicator of Poor Code Quality

// Register this check class (by creating a static instance of it)
namespace {
CheckAssert instance;
CheckAssert instanceAssert;
}

void CheckAssert::assertWithSideEffects()
Expand Down
5 changes: 1 addition & 4 deletions lib/checkautovariables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,9 @@

// Register this check class into cppcheck by creating a static instance of it..
namespace {
CheckAutoVariables instance;
CheckAutoVariables instanceAutoVariables;
}

static const CWE CWE398(398U); // Indicator of Poor Code Quality
static const CWE CWE562(562U); // Return of Stack Variable Address
static const CWE CWE590(590U); // Free of Memory not on the Heap

static bool isPtrArg(const Token *tok)
{
Expand Down
6 changes: 1 addition & 5 deletions lib/checkbool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,9 @@

// Register this check class (by creating a static instance of it)
namespace {
CheckBool instance;
CheckBool instanceBool;
}

static const CWE CWE398(398U); // Indicator of Poor Code Quality
static const CWE CWE571(571U); // Expression is Always True
static const CWE CWE587(587U); // Assignment of a Fixed Address to a Pointer
static const CWE CWE704(704U); // Incorrect Type Conversion or Cast

static bool isBool(const Variable* var)
{
Expand Down
3 changes: 1 addition & 2 deletions lib/checkboost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@

// Register this check class (by creating a static instance of it)
namespace {
CheckBoost instance;
CheckBoost instanceBoost;
}

static const CWE CWE664(664);

void CheckBoost::checkBoostForeachModification()
{
Expand Down
21 changes: 6 additions & 15 deletions lib/checkbufferoverrun.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,11 @@

// Register this check class (by creating a static instance of it)
namespace {
CheckBufferOverrun instance;
CheckBufferOverrun instanceBufferOverrun;
}

//---------------------------------------------------------------------------

// CWE ids used:
static const CWE CWE131(131U); // Incorrect Calculation of Buffer Size
static const CWE CWE170(170U); // Improper Null Termination
static const CWE CWE_ARGUMENT_SIZE(398U); // Indicator of Poor Code Quality
static const CWE CWE_ARRAY_INDEX_THEN_CHECK(398U); // Indicator of Poor Code Quality
static const CWE CWE758(758U); // Reliance on Undefined, Unspecified, or Implementation-Defined Behavior
static const CWE CWE_POINTER_ARITHMETIC_OVERFLOW(758U); // Reliance on Undefined, Unspecified, or Implementation-Defined Behavior
static const CWE CWE_BUFFER_UNDERRUN(786U); // Access of Memory Location Before Start of Buffer
static const CWE CWE_BUFFER_OVERRUN(788U); // Access of Memory Location After End of Buffer

//---------------------------------------------------------------------------

Expand Down Expand Up @@ -885,7 +876,7 @@ void CheckBufferOverrun::argumentSizeError(const Token *tok, const std::string &
// CTU..
//---------------------------------------------------------------------------

// a Clang-built executable will crash when using the anonymous MyFileInfo later on - so put it in a unique namespace for now
// a Clang-built executable will crash when using the anonymous MyFileInfoBufferOverrun later on - so put it in a unique namespace for now
// see https://trac.cppcheck.net/ticket/12108 for more details
#ifdef __clang__
inline namespace CheckBufferOverrun_internal
Expand All @@ -894,7 +885,7 @@ namespace
#endif
{
/** data for multifile checking */
class MyFileInfo : public Check::FileInfo {
class MyFileInfoBufferOverrun : public Check::FileInfo {
public:
/** unsafe array index usage */
std::list<CTU::FileInfo::UnsafeUsage> unsafeArrayIndex;
Expand Down Expand Up @@ -954,7 +945,7 @@ Check::FileInfo *CheckBufferOverrun::getFileInfo(const Tokenizer *tokenizer, con
if (unsafeArrayIndex.empty() && unsafePointerArith.empty()) {
return nullptr;
}
auto *fileInfo = new MyFileInfo;
auto *fileInfo = new MyFileInfoBufferOverrun;
fileInfo->unsafeArrayIndex = unsafeArrayIndex;
fileInfo->unsafePointerArith = unsafePointerArith;
return fileInfo;
Expand All @@ -966,7 +957,7 @@ Check::FileInfo * CheckBufferOverrun::loadFileInfoFromXml(const tinyxml2::XMLEle
const std::string arrayIndex("array-index");
const std::string pointerArith("pointer-arith");

auto *fileInfo = new MyFileInfo;
auto *fileInfo = new MyFileInfoBufferOverrun;
for (const tinyxml2::XMLElement *e = xmlElement->FirstChildElement(); e; e = e->NextSiblingElement()) {
if (e->Name() == arrayIndex)
fileInfo->unsafeArrayIndex = CTU::loadUnsafeUsageListFromXml(e);
Expand Down Expand Up @@ -997,7 +988,7 @@ bool CheckBufferOverrun::analyseWholeProgram(const CTU::FileInfo *ctu, const std
const std::map<std::string, std::list<const CTU::FileInfo::CallBase *>> callsMap = ctu->getCallsMap();

for (const Check::FileInfo* fi1 : fileInfo) {
const MyFileInfo *fi = dynamic_cast<const MyFileInfo*>(fi1);
const MyFileInfoBufferOverrun *fi = dynamic_cast<const MyFileInfoBufferOverrun*>(fi1);
if (!fi)
continue;
for (const CTU::FileInfo::UnsafeUsage &unsafeUsage : fi->unsafeArrayIndex)
Expand Down
33 changes: 13 additions & 20 deletions lib/checkclass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,9 @@ namespace CTU {

// Register CheckClass..
namespace {
CheckClass instance;
CheckClass instanceClass;
}

static const CWE CWE398(398U); // Indicator of Poor Code Quality
static const CWE CWE404(404U); // Improper Resource Shutdown or Release
static const CWE CWE665(665U); // Improper Initialization
static const CWE CWE758(758U); // Reliance on Undefined, Unspecified, or Implementation-Defined Behavior
static const CWE CWE762(762U); // Mismatched Memory Management Routines

static const CWE CWE_ONE_DEFINITION_RULE(758U);

static const char * getFunctionTypeName(Function::Type type)
{
Expand Down Expand Up @@ -2632,7 +2625,7 @@ void CheckClass::checkConstError2(const Token *tok1, const Token *tok2, const st
// ClassCheck: Check that initializer list is in declared order.
//---------------------------------------------------------------------------

namespace { // avoid one-definition-rule violation
namespace internal { // avoid one-definition-rule violation
struct VarInfo {
VarInfo(const Variable *_var, const Token *_tok)
: var(_var), tok(_tok) {}
Expand Down Expand Up @@ -2666,7 +2659,7 @@ void CheckClass::initializerListOrder()
const Token *tok = func->arg->link()->next();

if (tok->str() == ":") {
std::vector<VarInfo> vars;
std::vector<internal::VarInfo> vars;
tok = tok->next();

// find all variable initializations in list
Expand Down Expand Up @@ -3436,7 +3429,7 @@ void CheckClass::unsafeClassRefMemberError(const Token *tok, const std::string &
CWE(0), Certainty::normal);
}

// a Clang-built executable will crash when using the anonymous MyFileInfo later on - so put it in a unique namespace for now
// a Clang-built executable will crash when using the anonymous MyFileInfoClass later on - so put it in a unique namespace for now
// see https://trac.cppcheck.net/ticket/12108 for more details
#ifdef __clang__
inline namespace CheckClass_internal
Expand All @@ -3445,7 +3438,7 @@ namespace
#endif
{
/* multifile checking; one definition rule violations */
class MyFileInfo : public Check::FileInfo {
class MyFileInfoClass : public Check::FileInfo {
public:
struct NameLoc {
std::string className;
Expand Down Expand Up @@ -3485,7 +3478,7 @@ Check::FileInfo *CheckClass::getFileInfo(const Tokenizer *tokenizer, const Setti
return nullptr;
(void)settings;
// One definition rule
std::vector<MyFileInfo::NameLoc> classDefinitions;
std::vector<MyFileInfoClass::NameLoc> classDefinitions;
for (const Scope * classScope : tokenizer->getSymbolDatabase()->classAndStructScopes) {
if (classScope->isAnonymous())
continue;
Expand Down Expand Up @@ -3519,7 +3512,7 @@ Check::FileInfo *CheckClass::getFileInfo(const Tokenizer *tokenizer, const Setti
if (scope->type != Scope::ScopeType::eGlobal)
continue;

MyFileInfo::NameLoc nameLoc;
MyFileInfoClass::NameLoc nameLoc;
nameLoc.className = std::move(name);
nameLoc.fileName = tokenizer->list.file(classScope->classDef);
nameLoc.lineNumber = classScope->classDef->linenr();
Expand All @@ -3543,14 +3536,14 @@ Check::FileInfo *CheckClass::getFileInfo(const Tokenizer *tokenizer, const Setti
if (classDefinitions.empty())
return nullptr;

auto *fileInfo = new MyFileInfo;
auto *fileInfo = new MyFileInfoClass;
fileInfo->classDefinitions.swap(classDefinitions);
return fileInfo;
}

Check::FileInfo * CheckClass::loadFileInfoFromXml(const tinyxml2::XMLElement *xmlElement) const
{
auto *fileInfo = new MyFileInfo;
auto *fileInfo = new MyFileInfoClass;
for (const tinyxml2::XMLElement *e = xmlElement->FirstChildElement(); e; e = e->NextSiblingElement()) {
if (std::strcmp(e->Name(), "class") != 0)
continue;
Expand All @@ -3560,7 +3553,7 @@ Check::FileInfo * CheckClass::loadFileInfoFromXml(const tinyxml2::XMLElement *xm
const char *col = e->Attribute("col");
const char *hash = e->Attribute("hash");
if (name && file && line && col && hash) {
MyFileInfo::NameLoc nameLoc;
MyFileInfoClass::NameLoc nameLoc;
nameLoc.className = name;
nameLoc.fileName = file;
nameLoc.lineNumber = strToInt<int>(line);
Expand All @@ -3582,17 +3575,17 @@ bool CheckClass::analyseWholeProgram(const CTU::FileInfo *ctu, const std::list<C
(void)ctu; // This argument is unused
(void)settings; // This argument is unused

std::unordered_map<std::string, MyFileInfo::NameLoc> all;
std::unordered_map<std::string, MyFileInfoClass::NameLoc> all;

CheckClass dummy(nullptr, &settings, &errorLogger);
dummy.
logChecker("CheckClass::analyseWholeProgram");

for (const Check::FileInfo* fi1 : fileInfo) {
const MyFileInfo *fi = dynamic_cast<const MyFileInfo*>(fi1);
const MyFileInfoClass *fi = dynamic_cast<const MyFileInfoClass*>(fi1);
if (!fi)
continue;
for (const MyFileInfo::NameLoc &nameLoc : fi->classDefinitions) {
for (const MyFileInfoClass::NameLoc &nameLoc : fi->classDefinitions) {
auto it = all.find(nameLoc.className);
if (it == all.end()) {
all[nameLoc.className] = nameLoc;
Expand Down
7 changes: 1 addition & 6 deletions lib/checkcondition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,12 @@
#include <utility>
#include <vector>

// CWE ids used
static const CWE uncheckedErrorConditionCWE(391U);
static const CWE CWE398(398U); // Indicator of Poor Code Quality
static const CWE CWE570(570U); // Expression is Always False
static const CWE CWE571(571U); // Expression is Always True

//---------------------------------------------------------------------------

// Register this check class (by creating a static instance of it)
namespace {
CheckCondition instance;
CheckCondition instanceCondition;
}

bool CheckCondition::diag(const Token* tok, bool insert)
Expand Down
5 changes: 1 addition & 4 deletions lib/checkexceptionsafety.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,9 @@

// Register CheckExceptionSafety..
namespace {
CheckExceptionSafety instance;
CheckExceptionSafety instanceExceptionSafety;
}

static const CWE CWE398(398U); // Indicator of Poor Code Quality
static const CWE CWE703(703U); // Improper Check or Handling of Exceptional Conditions
static const CWE CWE480(480U); // Use of Incorrect Operator

//---------------------------------------------------------------------------

Expand Down
9 changes: 1 addition & 8 deletions lib/checkfunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,9 @@

// Register this check class (by creating a static instance of it)
namespace {
CheckFunctions instance;
CheckFunctions instanceFunctions;
}

static const CWE CWE252(252U); // Unchecked Return Value
static const CWE CWE477(477U); // Use of Obsolete Functions
static const CWE CWE758(758U); // Reliance on Undefined, Unspecified, or Implementation-Defined Behavior
static const CWE CWE628(628U); // Function Call with Incorrectly Specified Arguments
static const CWE CWE686(686U); // Function Call With Incorrect Argument Type
static const CWE CWE687(687U); // Function Call With Incorrectly Specified Argument Value
static const CWE CWE688(688U); // Function Call With Incorrect Variable or Reference as Argument

void CheckFunctions::checkProhibitedFunctions()
{
Expand Down
Loading