Skip to content

Commit b8cd7db

Browse files
mathbunnyrudanmar
authored andcommitted
Use nullptr instead of 0 or NULL (cppcheck-opensource#936)
1 parent c1b0a07 commit b8cd7db

38 files changed

Lines changed: 169 additions & 169 deletions

cli/cppcheckexecutor.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
/*static*/ FILE* CppCheckExecutor::exceptionOutput = stdout;
7979

8080
CppCheckExecutor::CppCheckExecutor()
81-
: _settings(0), time1(0), errorOutput(nullptr), errorlist(false)
81+
: _settings(nullptr), time1(0), errorOutput(nullptr), errorlist(false)
8282
{
8383
}
8484

@@ -823,7 +823,7 @@ int CppCheckExecutor::check_internal(CppCheck& cppcheck, int /*argc*/, const cha
823823
}
824824

825825
if (settings.reportProgress)
826-
time1 = std::time(0);
826+
time1 = std::time(nullptr);
827827

828828
if (!settings.outputFile.empty()) {
829829
errorOutput = new std::ofstream(settings.outputFile);
@@ -930,7 +930,7 @@ int CppCheckExecutor::check_internal(CppCheck& cppcheck, int /*argc*/, const cha
930930
reportErr(ErrorLogger::ErrorMessage::getXMLFooter());
931931
}
932932

933-
_settings = 0;
933+
_settings = nullptr;
934934
if (returnValue)
935935
return settings.exitCode;
936936
else

cli/filelister.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ static void addFiles2(std::map<std::string, std::size_t> &files,
188188
std::string new_path;
189189
new_path.reserve(path.length() + 100);// prealloc some memory to avoid constant new/deletes in loop
190190

191-
while ((readdir_r(dir, &entry, &dir_result) == 0) && (dir_result != NULL)) {
191+
while ((readdir_r(dir, &entry, &dir_result) == 0) && (dir_result != nullptr)) {
192192

193193
if ((std::strcmp(dir_result->d_name, ".") == 0) ||
194194
(std::strcmp(dir_result->d_name, "..") == 0))

lib/check.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
//---------------------------------------------------------------------------
2626

2727
Check::Check(const std::string &aname)
28-
: _tokenizer(0), _settings(0), _errorLogger(0), _name(aname)
28+
: _tokenizer(nullptr), _settings(nullptr), _errorLogger(nullptr), _name(aname)
2929
{
3030
for (std::list<Check*>::iterator i = instances().begin(); i != instances().end(); ++i) {
3131
if ((*i)->name() > aname) {

lib/check.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ class CPPCHECKLIB Check {
146146
/** report an error */
147147
template<typename T, typename U>
148148
void reportError(const std::list<const Token *> &callstack, Severity::SeverityType severity, const T id, const U msg, const CWE &cwe, bool inconclusive) {
149-
const ErrorLogger::ErrorMessage errmsg(callstack, _tokenizer?&_tokenizer->list:0, severity, id, msg, cwe, inconclusive);
149+
const ErrorLogger::ErrorMessage errmsg(callstack, _tokenizer ? &_tokenizer->list : nullptr, severity, id, msg, cwe, inconclusive);
150150
if (_errorLogger)
151151
_errorLogger->reportErr(errmsg);
152152
else

lib/check64bit.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ void Check64BitPortability::pointerassignment()
5252
const std::size_t functions = symbolDatabase->functionScopes.size();
5353
for (std::size_t i = 0; i < functions; ++i) {
5454
const Scope * scope = symbolDatabase->functionScopes[i];
55-
if (scope->function == 0 || !scope->function->hasBody()) // We only look for functions with a body
55+
if (scope->function == nullptr || !scope->function->hasBody()) // We only look for functions with a body
5656
continue;
5757

5858
bool retPointer = false;

lib/checkboost.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ class CPPCHECKLIB CheckBoost : public Check {
6565
void boostForeachError(const Token *tok);
6666

6767
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const {
68-
CheckBoost c(0, settings, errorLogger);
69-
c.boostForeachError(0);
68+
CheckBoost c(nullptr, settings, errorLogger);
69+
c.boostForeachError(nullptr);
7070
}
7171

7272
static std::string myName() {

lib/checkbufferoverrun.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1299,7 +1299,7 @@ void CheckBufferOverrun::checkGlobalAndLocalVariable()
12991299
continue;
13001300
}
13011301

1302-
if (var == 0)
1302+
if (var == nullptr)
13031303
continue;
13041304

13051305
const MathLib::bigint totalSize = size * static_cast<int>(sizeOfType(var->typeStartToken()));

lib/checkclass.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ bool CheckClass::isBaseClassFunc(const Token *tok, const Scope *scope)
504504
void CheckClass::initializeVarList(const Function &func, std::list<const Function *> &callstack, const Scope *scope, std::vector<Usage> &usage)
505505
{
506506
if (!func.functionScope)
507-
throw InternalError(0, "Internal Error: Invalid syntax"); // #5702
507+
throw InternalError(nullptr, "Internal Error: Invalid syntax"); // #5702
508508
bool initList = func.isConstructor();
509509
const Token *ftok = func.arg->link()->next();
510510
int level = 0;
@@ -1022,7 +1022,7 @@ static const Scope* findFunctionOf(const Scope* scope)
10221022
return scope->functionOf;
10231023
scope = scope->nestedIn;
10241024
}
1025-
return 0;
1025+
return nullptr;
10261026
}
10271027

10281028
void CheckClass::checkMemset()
@@ -1364,7 +1364,7 @@ void CheckClass::checkReturnPtrThis(const Scope *scope, const Function *func, co
13641364
}
13651365
return;
13661366
}
1367-
if (_settings->library.isScopeNoReturn(last, 0)) {
1367+
if (_settings->library.isScopeNoReturn(last, nullptr)) {
13681368
// Typical wrong way to prohibit default assignment operator
13691369
// by always throwing an exception or calling a noreturn function
13701370
operatorEqShouldBeLeftUnimplementedError(func->token);
@@ -2049,7 +2049,7 @@ bool CheckClass::checkConstFunc(const Scope *scope, const Function *func, bool&
20492049

20502050
void CheckClass::checkConstError(const Token *tok, const std::string &classname, const std::string &funcname, bool suggestStatic)
20512051
{
2052-
checkConstError2(tok, 0, classname, funcname, suggestStatic);
2052+
checkConstError2(tok, nullptr, classname, funcname, suggestStatic);
20532053
}
20542054

20552055
void CheckClass::checkConstError2(const Token *tok1, const Token *tok2, const std::string &classname, const std::string &funcname, bool suggestStatic)

lib/checkclass.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,8 @@ class CPPCHECKLIB CheckClass : public Check {
197197
c.memsetError(nullptr, "memfunc", "classname", "class");
198198
c.memsetErrorReference(nullptr, "memfunc", "class");
199199
c.memsetErrorFloat(nullptr, "class");
200-
c.mallocOnClassWarning(nullptr, "malloc", 0);
201-
c.mallocOnClassError(nullptr, "malloc", 0, "std::string");
200+
c.mallocOnClassWarning(nullptr, "malloc", nullptr);
201+
c.mallocOnClassError(nullptr, "malloc", nullptr, "std::string");
202202
c.operatorEqReturnError(nullptr, "class");
203203
c.virtualDestructorError(nullptr, "Base", "Derived", false);
204204
c.thisSubtractionError(nullptr);
@@ -208,10 +208,10 @@ class CPPCHECKLIB CheckClass : public Check {
208208
c.operatorEqToSelfError(nullptr);
209209
c.checkConstError(nullptr, "class", "function", false);
210210
c.checkConstError(nullptr, "class", "function", true);
211-
c.initializerListError(nullptr, 0, "class", "variable");
211+
c.initializerListError(nullptr, nullptr, "class", "variable");
212212
c.suggestInitializationList(nullptr, "variable");
213213
c.selfInitializationError(nullptr, "var");
214-
c.duplInheritedMembersError(nullptr, 0, "class", "class", "variable", false, false);
214+
c.duplInheritedMembersError(nullptr, nullptr, "class", "class", "variable", false, false);
215215
c.copyCtorAndEqOperatorError(nullptr, "class", false, false);
216216
}
217217

lib/checkcondition.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ void CheckCondition::assignIf()
6363

6464
if (Token::Match(tok->tokAt(-2), "[;{}] %var% =")) {
6565
const Variable *var = tok->previous()->variable();
66-
if (var == 0)
66+
if (var == nullptr)
6767
continue;
6868

6969
char bitop = '\0';
@@ -241,7 +241,7 @@ static void getnumchildren(const Token *tok, std::list<MathLib::bigint> &numchil
241241
/* Return whether tok is in the body for a function returning a boolean. */
242242
static bool inBooleanFunction(const Token *tok)
243243
{
244-
const Scope *scope = tok ? tok->scope() : 0;
244+
const Scope *scope = tok ? tok->scope() : nullptr;
245245
while (scope && scope->isLocal())
246246
scope = scope->nestedIn;
247247
if (scope && scope->type == Scope::eFunction) {

0 commit comments

Comments
 (0)