Skip to content

Commit c8a52e9

Browse files
committed
refactor: move and rename code in order to support a CMAKE_UNITY_BUILD
1 parent f97bab8 commit c8a52e9

33 files changed

Lines changed: 221 additions & 209 deletions

lib/check64bit.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,10 @@
3232

3333
//---------------------------------------------------------------------------
3434

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

3836
// Register this check class (by creating a static instance of it)
3937
namespace {
40-
Check64BitPortability instance;
38+
Check64BitPortability instance64BitPortability;
4139
}
4240

4341
void Check64BitPortability::pointerassignment()

lib/checkassert.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,10 @@
3131

3232
//---------------------------------------------------------------------------
3333

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

3735
// Register this check class (by creating a static instance of it)
3836
namespace {
39-
CheckAssert instance;
37+
CheckAssert instanceAssert;
4038
}
4139

4240
void CheckAssert::assertWithSideEffects()

lib/checkautovariables.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,9 @@
4242

4343
// Register this check class into cppcheck by creating a static instance of it..
4444
namespace {
45-
CheckAutoVariables instance;
45+
CheckAutoVariables instanceAutoVariables;
4646
}
4747

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

5249
static bool isPtrArg(const Token *tok)
5350
{

lib/checkbool.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,9 @@
3434

3535
// Register this check class (by creating a static instance of it)
3636
namespace {
37-
CheckBool instance;
37+
CheckBool instanceBool;
3838
}
3939

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

4541
static bool isBool(const Variable* var)
4642
{

lib/checkboost.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,9 @@
2626

2727
// Register this check class (by creating a static instance of it)
2828
namespace {
29-
CheckBoost instance;
29+
CheckBoost instanceBoost;
3030
}
3131

32-
static const CWE CWE664(664);
3332

3433
void CheckBoost::checkBoostForeachModification()
3534
{

lib/checkbufferoverrun.cpp

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,11 @@
4848

4949
// Register this check class (by creating a static instance of it)
5050
namespace {
51-
CheckBufferOverrun instance;
51+
CheckBufferOverrun instanceBufferOverrun;
5252
}
5353

5454
//---------------------------------------------------------------------------
5555

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

6657
//---------------------------------------------------------------------------
6758

@@ -885,7 +876,7 @@ void CheckBufferOverrun::argumentSizeError(const Token *tok, const std::string &
885876
// CTU..
886877
//---------------------------------------------------------------------------
887878

888-
// a Clang-built executable will crash when using the anonymous MyFileInfo later on - so put it in a unique namespace for now
879+
// a Clang-built executable will crash when using the anonymous MyFileInfoBufferOverrun later on - so put it in a unique namespace for now
889880
// see https://trac.cppcheck.net/ticket/12108 for more details
890881
#ifdef __clang__
891882
inline namespace CheckBufferOverrun_internal
@@ -894,7 +885,7 @@ namespace
894885
#endif
895886
{
896887
/** data for multifile checking */
897-
class MyFileInfo : public Check::FileInfo {
888+
class MyFileInfoBufferOverrun : public Check::FileInfo {
898889
public:
899890
/** unsafe array index usage */
900891
std::list<CTU::FileInfo::UnsafeUsage> unsafeArrayIndex;
@@ -954,7 +945,7 @@ Check::FileInfo *CheckBufferOverrun::getFileInfo(const Tokenizer *tokenizer, con
954945
if (unsafeArrayIndex.empty() && unsafePointerArith.empty()) {
955946
return nullptr;
956947
}
957-
auto *fileInfo = new MyFileInfo;
948+
auto *fileInfo = new MyFileInfoBufferOverrun;
958949
fileInfo->unsafeArrayIndex = unsafeArrayIndex;
959950
fileInfo->unsafePointerArith = unsafePointerArith;
960951
return fileInfo;
@@ -966,7 +957,7 @@ Check::FileInfo * CheckBufferOverrun::loadFileInfoFromXml(const tinyxml2::XMLEle
966957
const std::string arrayIndex("array-index");
967958
const std::string pointerArith("pointer-arith");
968959

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

999990
for (const Check::FileInfo* fi1 : fileInfo) {
1000-
const MyFileInfo *fi = dynamic_cast<const MyFileInfo*>(fi1);
991+
const MyFileInfoBufferOverrun *fi = dynamic_cast<const MyFileInfoBufferOverrun*>(fi1);
1001992
if (!fi)
1002993
continue;
1003994
for (const CTU::FileInfo::UnsafeUsage &unsafeUsage : fi->unsafeArrayIndex)

lib/checkclass.cpp

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,9 @@ namespace CTU {
4848

4949
// Register CheckClass..
5050
namespace {
51-
CheckClass instance;
51+
CheckClass instanceClass;
5252
}
5353

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

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

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

26682661
if (tok->str() == ":") {
2669-
std::vector<VarInfo> vars;
2662+
std::vector<internal::VarInfo> vars;
26702663
tok = tok->next();
26712664

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

3439-
// a Clang-built executable will crash when using the anonymous MyFileInfo later on - so put it in a unique namespace for now
3432+
// a Clang-built executable will crash when using the anonymous MyFileInfoClass later on - so put it in a unique namespace for now
34403433
// see https://trac.cppcheck.net/ticket/12108 for more details
34413434
#ifdef __clang__
34423435
inline namespace CheckClass_internal
@@ -3445,7 +3438,7 @@ namespace
34453438
#endif
34463439
{
34473440
/* multifile checking; one definition rule violations */
3448-
class MyFileInfo : public Check::FileInfo {
3441+
class MyFileInfoClass : public Check::FileInfo {
34493442
public:
34503443
struct NameLoc {
34513444
std::string className;
@@ -3485,7 +3478,7 @@ Check::FileInfo *CheckClass::getFileInfo(const Tokenizer *tokenizer, const Setti
34853478
return nullptr;
34863479
(void)settings;
34873480
// One definition rule
3488-
std::vector<MyFileInfo::NameLoc> classDefinitions;
3481+
std::vector<MyFileInfoClass::NameLoc> classDefinitions;
34893482
for (const Scope * classScope : tokenizer->getSymbolDatabase()->classAndStructScopes) {
34903483
if (classScope->isAnonymous())
34913484
continue;
@@ -3519,7 +3512,7 @@ Check::FileInfo *CheckClass::getFileInfo(const Tokenizer *tokenizer, const Setti
35193512
if (scope->type != Scope::ScopeType::eGlobal)
35203513
continue;
35213514

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

3546-
auto *fileInfo = new MyFileInfo;
3539+
auto *fileInfo = new MyFileInfoClass;
35473540
fileInfo->classDefinitions.swap(classDefinitions);
35483541
return fileInfo;
35493542
}
35503543

35513544
Check::FileInfo * CheckClass::loadFileInfoFromXml(const tinyxml2::XMLElement *xmlElement) const
35523545
{
3553-
auto *fileInfo = new MyFileInfo;
3546+
auto *fileInfo = new MyFileInfoClass;
35543547
for (const tinyxml2::XMLElement *e = xmlElement->FirstChildElement(); e; e = e->NextSiblingElement()) {
35553548
if (std::strcmp(e->Name(), "class") != 0)
35563549
continue;
@@ -3560,7 +3553,7 @@ Check::FileInfo * CheckClass::loadFileInfoFromXml(const tinyxml2::XMLElement *xm
35603553
const char *col = e->Attribute("col");
35613554
const char *hash = e->Attribute("hash");
35623555
if (name && file && line && col && hash) {
3563-
MyFileInfo::NameLoc nameLoc;
3556+
MyFileInfoClass::NameLoc nameLoc;
35643557
nameLoc.className = name;
35653558
nameLoc.fileName = file;
35663559
nameLoc.lineNumber = strToInt<int>(line);
@@ -3582,17 +3575,17 @@ bool CheckClass::analyseWholeProgram(const CTU::FileInfo *ctu, const std::list<C
35823575
(void)ctu; // This argument is unused
35833576
(void)settings; // This argument is unused
35843577

3585-
std::unordered_map<std::string, MyFileInfo::NameLoc> all;
3578+
std::unordered_map<std::string, MyFileInfoClass::NameLoc> all;
35863579

35873580
CheckClass dummy(nullptr, &settings, &errorLogger);
35883581
dummy.
35893582
logChecker("CheckClass::analyseWholeProgram");
35903583

35913584
for (const Check::FileInfo* fi1 : fileInfo) {
3592-
const MyFileInfo *fi = dynamic_cast<const MyFileInfo*>(fi1);
3585+
const MyFileInfoClass *fi = dynamic_cast<const MyFileInfoClass*>(fi1);
35933586
if (!fi)
35943587
continue;
3595-
for (const MyFileInfo::NameLoc &nameLoc : fi->classDefinitions) {
3588+
for (const MyFileInfoClass::NameLoc &nameLoc : fi->classDefinitions) {
35963589
auto it = all.find(nameLoc.className);
35973590
if (it == all.end()) {
35983591
all[nameLoc.className] = nameLoc;

lib/checkcondition.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,12 @@
4242
#include <utility>
4343
#include <vector>
4444

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

5146
//---------------------------------------------------------------------------
5247

5348
// Register this check class (by creating a static instance of it)
5449
namespace {
55-
CheckCondition instance;
50+
CheckCondition instanceCondition;
5651
}
5752

5853
bool CheckCondition::diag(const Token* tok, bool insert)

lib/checkexceptionsafety.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,9 @@
3434

3535
// Register CheckExceptionSafety..
3636
namespace {
37-
CheckExceptionSafety instance;
37+
CheckExceptionSafety instanceExceptionSafety;
3838
}
3939

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

4441
//---------------------------------------------------------------------------
4542

lib/checkfunctions.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,9 @@
4343

4444
// Register this check class (by creating a static instance of it)
4545
namespace {
46-
CheckFunctions instance;
46+
CheckFunctions instanceFunctions;
4747
}
4848

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

5750
void CheckFunctions::checkProhibitedFunctions()
5851
{

0 commit comments

Comments
 (0)