Skip to content

Commit edea4ef

Browse files
committed
Refactoring: Renamed CheckNullPointer::isPointer to Token::isUpperCaseName
1 parent ee0d18a commit edea4ef

8 files changed

Lines changed: 18 additions & 23 deletions

File tree

‎lib/checkleakautovar.cpp‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@
2626
#include "errorlogger.h"
2727
#include "symboldatabase.h"
2828

29-
#include "checknullpointer.h" // <- isUpper
30-
3129
#include <fstream>
3230

3331
//---------------------------------------------------------------------------
@@ -269,7 +267,7 @@ void CheckLeakAutoVar::checkScope(const Token * const startToken,
269267
// track the execution for a later if condition.
270268
if (Token::Match(tok->tokAt(2), "%num% ;") && MathLib::toLongNumber(tok->strAt(2)) != 0)
271269
notzero.insert(tok->varId());
272-
else if (Token::Match(tok->tokAt(2), "- %type% ;") && CheckNullPointer::isUpper(tok->strAt(3)))
270+
else if (Token::Match(tok->tokAt(2), "- %type% ;") && tok->tokAt(3)->isUpperCaseName())
273271
notzero.insert(tok->varId());
274272
else
275273
notzero.erase(tok->varId());

‎lib/checknullpointer.cpp‎

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,6 @@ namespace {
3232

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

35-
36-
/** Is string uppercase? */
37-
bool CheckNullPointer::isUpper(const std::string &str)
38-
{
39-
for (unsigned int i = 0; i < str.length(); ++i) {
40-
if (std::islower(str[i]))
41-
return false;
42-
}
43-
return true;
44-
}
45-
4635
/**
4736
* @brief parse a function call and extract information about variable usage
4837
* @param tok first token
@@ -932,7 +921,7 @@ void CheckNullPointer::nullPointerByCheckAndDeRef()
932921
// - if (x) { } else { ... }
933922

934923
// If the if-body ends with a unknown macro then bailout
935-
if (Token::Match(i->classEnd->tokAt(-3), "[;{}] %var% ;") && isUpper(i->classEnd->strAt(-2)))
924+
if (Token::Match(i->classEnd->tokAt(-3), "[;{}] %var% ;") && i->classEnd->tokAt(-2)->isUpperCaseName())
936925
continue;
937926

938927
// vartok : token for the variable

‎lib/checknullpointer.h‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,6 @@ class CPPCHECKLIB CheckNullPointer : public Check {
5959
checkNullPointer.executionPaths();
6060
}
6161

62-
/** Is string uppercase? */
63-
static bool isUpper(const std::string &str);
64-
6562
/**
6663
* @brief parse a function call and extract information about variable usage
6764
* @param tok first token

‎lib/checkuninitvar.cpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ class UninitVar : public ExecutionPath {
670670
}
671671

672672
// ticket #2367 : unexpanded macro that uses sizeof|typeof?
673-
else if (Token::Match(tok2, "%type% (") && CheckNullPointer::isUpper(tok2->str())) {
673+
else if (Token::Match(tok2, "%type% (") && tok2->isUpperCaseName()) {
674674
tok2 = tok2->next()->link();
675675
if (!tok2)
676676
break;
@@ -689,7 +689,7 @@ class UninitVar : public ExecutionPath {
689689

690690
functionCall = functionCall ? functionCall->previous() : 0;
691691
if (functionCall) {
692-
if (functionCall->isName() && !CheckNullPointer::isUpper(functionCall->str()) && use_dead_pointer(checks, tok2))
692+
if (functionCall->isName() && !functionCall->isUpperCaseName() && use_dead_pointer(checks, tok2))
693693
ExecutionPath::bailOutVar(checks, tok2->varId());
694694
}
695695
}

‎lib/symboldatabase.cpp‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#include "settings.h"
2525
#include "errorlogger.h"
2626
#include "check.h"
27-
#include "checknullpointer.h" // isUpper
2827

2928
#include <string>
3029
#include <sstream>
@@ -99,7 +98,7 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
9998
// Namespace and unknown macro (#3854)
10099
else if (Token::Match(tok, "namespace %var% %type% (") &&
101100
_tokenizer->isCPP() &&
102-
CheckNullPointer::isUpper(tok->strAt(2)) &&
101+
tok->tokAt(2)->isUpperCaseName() &&
103102
Token::simpleMatch(tok->linkAt(3), ") {")) {
104103
scopeList.push_back(Scope(this, tok, scope));
105104

‎lib/token.cpp‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,17 @@ void Token::update_property_isStandardType()
130130
}
131131

132132

133+
bool Token::isUpperCaseName() const
134+
{
135+
if (!isName())
136+
return false;
137+
for (unsigned int i = 0; i < _str.length(); ++i) {
138+
if (std::islower(_str[i]))
139+
return false;
140+
}
141+
return true;
142+
}
143+
133144
void Token::str(const std::string &s)
134145
{
135146
_str = s;

‎lib/token.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ class CPPCHECKLIB Token {
170170
return _type == eName || _type == eType || _type == eVariable || _type == eFunction ||
171171
_type == eBoolean; // TODO: "true"/"false" aren't really a name...
172172
}
173+
bool isUpperCaseName() const;
173174
bool isNumber() const {
174175
return _type == eNumber;
175176
}

‎lib/tokenize.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3454,7 +3454,7 @@ void Tokenizer::removeMacrosInGlobalScope()
34543454
tok->deleteNext();
34553455
}
34563456

3457-
if (Token::Match(tok, "[;{}] %type%") && CheckNullPointer::isUpper(tok->next()->str())) {
3457+
if (Token::Match(tok, "[;{}] %type%") && tok->next()->isUpperCaseName()) {
34583458
const Token *tok2 = tok->tokAt(2);
34593459
if (tok2 && tok2->str() == "(") {
34603460
unsigned int par = 0;

0 commit comments

Comments
 (0)