Skip to content

Commit cfcfa3f

Browse files
committed
Use "enabled" list for the style checking.
Settings-class currently enables style checking via dedicated boolean attribute. All other CLI's enable-options are handled through the enable-list. This commit moves style-check enabling to use the enable-list. Main advantage is the consistency how options are handled/stored in the Settings class. Which also unifies using them for the other code. You need to enable certain type of checks? Use the addEnabled()-method. You want to check if certain type of checks are enabled? Use the isEnabled()-method.
1 parent 85b2bd2 commit cfcfa3f

36 files changed

Lines changed: 89 additions & 97 deletions

lib/check64bit.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ static bool isint(const Variable *var)
4646

4747
void Check64BitPortability::pointerassignment()
4848
{
49-
if (!_settings->_checkCodingStyle)
49+
if (!_settings->isEnabled("style"))
5050
return;
5151

5252
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())

lib/checkassignif.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ CheckAssignIf instance;
3434

3535
void CheckAssignIf::assignIf()
3636
{
37-
if (!_settings->_checkCodingStyle)
37+
if (!_settings->isEnabled("style"))
3838
return;
3939

4040
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())
@@ -84,7 +84,7 @@ void CheckAssignIf::assignIfError(const Token *tok, bool result)
8484

8585
void CheckAssignIf::comparison()
8686
{
87-
if (!_settings->_checkCodingStyle)
87+
if (!_settings->isEnabled("style"))
8888
return;
8989

9090
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())
@@ -140,7 +140,7 @@ void CheckAssignIf::comparisonError(const Token *tok, bool result)
140140

141141
void CheckAssignIf::multiCondition()
142142
{
143-
if (!_settings->_checkCodingStyle)
143+
if (!_settings->isEnabled("style"))
144144
return;
145145

146146
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())

lib/checkbufferoverrun.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ void CheckBufferOverrun::bufferOverrun(const Token *tok, const std::string &varn
115115

116116
void CheckBufferOverrun::strncatUsage(const Token *tok)
117117
{
118-
if (_settings && !_settings->_checkCodingStyle)
118+
if (_settings && !_settings->isEnabled("style"))
119119
return;
120120

121121
reportError(tok, Severity::warning, "strncatUsage",
@@ -137,7 +137,7 @@ void CheckBufferOverrun::pointerOutOfBounds(const Token *tok, const std::string
137137

138138
void CheckBufferOverrun::sizeArgumentAsChar(const Token *tok)
139139
{
140-
if (_settings && !_settings->_checkCodingStyle)
140+
if (_settings && !_settings->isEnabled("style"))
141141
return;
142142
reportError(tok, Severity::warning, "sizeArgumentAsChar", "The size argument is given as a char constant");
143143
}
@@ -1017,7 +1017,7 @@ void CheckBufferOverrun::checkScope(const Token *tok, const std::vector<std::str
10171017
if (varid && Token::Match(tok, "= %varid% + %num% ;", varid))
10181018
{
10191019
const MathLib::bigint index = MathLib::toLongNumber(tok->strAt(3));
1020-
if (index > size && _settings->_checkCodingStyle)
1020+
if (index > size && _settings->isEnabled("style"))
10211021
pointerOutOfBounds(tok->next(), "buffer");
10221022
if (index >= size && Token::Match(tok->tokAt(-2), "[;{}] %varid% =", varid))
10231023
pointerIsOutOfBounds = true;
@@ -1127,7 +1127,7 @@ void CheckBufferOverrun::checkScope(const Token *tok, const ArrayInfo &arrayInfo
11271127
checkFunctionCall(tok, arrayInfo);
11281128
}
11291129

1130-
if (_settings->_checkCodingStyle)
1130+
if (_settings->isEnabled("style"))
11311131
{
11321132
// check for strncpy which is not terminated
11331133
if ((Token::Match(tok, "strncpy ( %varid% , %var% , %num% )", arrayInfo.varid())))
@@ -1217,7 +1217,7 @@ void CheckBufferOverrun::checkScope(const Token *tok, const ArrayInfo &arrayInfo
12171217
}
12181218

12191219
// undefined behaviour: result of pointer arithmetic is out of bounds
1220-
if (_settings->_checkCodingStyle && Token::Match(tok, "= %varid% + %num% ;", arrayInfo.varid()))
1220+
if (_settings->isEnabled("style") && Token::Match(tok, "= %varid% + %num% ;", arrayInfo.varid()))
12211221
{
12221222
const MathLib::bigint index = MathLib::toLongNumber(tok->strAt(3));
12231223
if (index < 0 || index > arrayInfo.num(0))
@@ -2186,7 +2186,7 @@ void CheckBufferOverrun::executionPaths()
21862186

21872187
void CheckBufferOverrun::arrayIndexThenCheck()
21882188
{
2189-
if (!_settings->_checkCodingStyle)
2189+
if (!_settings->isEnabled("style"))
21902190
return;
21912191
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())
21922192
{

lib/checkclass.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ void CheckClass::createSymbolDatabase()
6363

6464
void CheckClass::constructors()
6565
{
66-
if (!_settings->_checkCodingStyle)
66+
if (!_settings->isEnabled("style"))
6767
return;
6868

6969
createSymbolDatabase();
@@ -570,7 +570,7 @@ void CheckClass::operatorEqVarError(const Token *tok, const std::string &classna
570570

571571
void CheckClass::privateFunctions()
572572
{
573-
if (!_settings->_checkCodingStyle)
573+
if (!_settings->isEnabled("style"))
574574
return;
575575

576576
// don't check code that contains templates. Templates that are
@@ -802,7 +802,7 @@ void CheckClass::memsetError(const Token *tok, const std::string &memfunc, const
802802

803803
void CheckClass::operatorEq()
804804
{
805-
if (!_settings->_checkCodingStyle)
805+
if (!_settings->isEnabled("style"))
806806
return;
807807

808808
createSymbolDatabase();
@@ -841,7 +841,7 @@ void CheckClass::operatorEqReturnError(const Token *tok, const std::string &clas
841841

842842
void CheckClass::operatorEqRetRefThis()
843843
{
844-
if (!_settings->_checkCodingStyle)
844+
if (!_settings->isEnabled("style"))
845845
return;
846846

847847
createSymbolDatabase();
@@ -957,7 +957,7 @@ void CheckClass::operatorEqRetRefThisError(const Token *tok)
957957

958958
void CheckClass::operatorEqToSelf()
959959
{
960-
if (!_settings->_checkCodingStyle)
960+
if (!_settings->isEnabled("style"))
961961
return;
962962

963963
createSymbolDatabase();
@@ -1251,7 +1251,7 @@ void CheckClass::virtualDestructorError(const Token *tok, const std::string &Bas
12511251

12521252
void CheckClass::thisSubtraction()
12531253
{
1254-
if (!_settings->_checkCodingStyle)
1254+
if (!_settings->isEnabled("style"))
12551255
return;
12561256

12571257
const Token *tok = _tokenizer->tokens();

lib/checkexceptionsafety.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ CheckExceptionSafety instance;
3535
void CheckExceptionSafety::destructors()
3636
{
3737
// This is a style error..
38-
if (!_settings->_checkCodingStyle)
38+
if (!_settings->isEnabled("style"))
3939
return;
4040

4141
// Perform check..
@@ -175,7 +175,7 @@ void CheckExceptionSafety::deallocThrow()
175175
//---------------------------------------------------------------------------
176176
void CheckExceptionSafety::checkRethrowCopy()
177177
{
178-
if (!_settings->_checkCodingStyle)
178+
if (!_settings->isEnabled("style"))
179179
return;
180180
const char catchPattern[] = "catch ( const| %type% &|*| %var% ) { %any%";
181181

lib/checkmemoryleak.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2910,7 +2910,7 @@ void CheckMemoryLeakInClass::checkPublicFunctions(const Scope *scope, const Toke
29102910
// Check that public functions deallocate the pointers that they allocate.
29112911
// There is no checking how these functions are used and therefore it
29122912
// isn't established if there is real leaks or not.
2913-
if (!_settings->_checkCodingStyle)
2913+
if (!_settings->isEnabled("style"))
29142914
return;
29152915

29162916
const unsigned int varid = classtok->varId();

lib/checknonreentrantfunctions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ CheckNonReentrantFunctions instance;
3333

3434
void CheckNonReentrantFunctions::nonReentrantFunctions()
3535
{
36-
if (!_settings->isEnabled("posix") || !_settings->_checkCodingStyle)
36+
if (!_settings->isEnabled("posix") || !_settings->isEnabled("style"))
3737
return;
3838

3939
// Don't check C# and Java code

lib/checkobsoletefunctions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ CheckObsoleteFunctions instance;
3333

3434
void CheckObsoleteFunctions::obsoleteFunctions()
3535
{
36-
if (!_settings->_checkCodingStyle)
36+
if (!_settings->isEnabled("style"))
3737
return;
3838

3939
// Don't check C# and Java code

0 commit comments

Comments
 (0)