Skip to content

Commit

Permalink
c++11 modernization: Replace NULL with nullptr.
Browse files Browse the repository at this point in the history
nullptr has the advantage that it is always a pointer type, giving
less ambiguity with overloading and template programming.
  • Loading branch information
perim committed May 6, 2017
1 parent 1ea6ecc commit 9d0f604
Show file tree
Hide file tree
Showing 161 changed files with 3,673 additions and 3,676 deletions.
20 changes: 10 additions & 10 deletions lib/exceptionhandler/dumpinfo.cpp
Expand Up @@ -51,7 +51,7 @@ using std::string;

static const std::size_t max_debug_messages = 20;

static char *dbgHeader = NULL;
static char *dbgHeader = nullptr;
static WZ_MUTEX *dbgMessagesMutex = wzMutexCreate(); // Protects dbgMessages.
static std::deque<std::vector<char> > dbgMessages;

Expand All @@ -62,7 +62,7 @@ static void dumpstr(const DumpFileHandle file, const char *const str, std::size_
{
#if defined(WZ_OS_WIN)
DWORD lNumberOfBytesWritten;
WriteFile(file, str, size, &lNumberOfBytesWritten, NULL);
WriteFile(file, str, size, &lNumberOfBytesWritten, nullptr);
#else
std::size_t written = 0;
while (written < size)
Expand Down Expand Up @@ -104,10 +104,10 @@ static void debug_exceptionhandler_data(void **, const char *const str)
/* Can't use ASSERT here as that will cause us to be invoked again.
* Possibly resulting in infinite recursion.
*/
assert(str != NULL && "Empty string sent to debug callback");
assert(str != nullptr && "Empty string sent to debug callback");

// For non-debug builds
if (str == NULL)
if (str == nullptr)
{
return;
}
Expand Down Expand Up @@ -174,7 +174,7 @@ static std::string getProgramPath(const char *programCommand)
std::vector<char> buf(PATH_MAX);

#if defined(WZ_OS_WIN)
while (GetModuleFileNameA(NULL, &buf[0], buf.size()) == buf.size())
while (GetModuleFileNameA(nullptr, &buf[0], buf.size()) == buf.size())
{
buf.resize(buf.size() * 2);
}
Expand All @@ -185,7 +185,7 @@ static std::string getProgramPath(const char *programCommand)

sasprintf(&whichProgramCommand, "which %s", programCommand);
whichProgramStream = popen(whichProgramCommand, "r");
if (whichProgramStream == NULL)
if (whichProgramStream == nullptr)
{
debug(LOG_WARNING, "Failed to run \"%s\", will not create extended backtrace", whichProgramCommand);
return std::string();
Expand Down Expand Up @@ -258,7 +258,7 @@ static std::string getCurTime()
using std::string;

// Get the current time
const time_t currentTime = time(NULL);
const time_t currentTime = time(nullptr);

// Convert it to a string
string time(ctime(&currentTime));
Expand Down Expand Up @@ -343,7 +343,7 @@ static void createHeader(int const argc, const char **argv, const char *packageV
<< endl;

dbgHeader = strdup(os.str().c_str());
if (dbgHeader == NULL)
if (dbgHeader == nullptr)
{
debug(LOG_FATAL, "createHeader: Out of memory!");
abort();
Expand All @@ -355,7 +355,7 @@ void addDumpInfo(const char *inbuffer)
{
char ourtime[sizeof("HH:MM:SS")];

const time_t curtime = time(NULL);
const time_t curtime = time(nullptr);
struct tm *const timeinfo = localtime(&curtime);

strftime(ourtime, sizeof(ourtime), "%H:%M:%S", timeinfo);
Expand All @@ -371,6 +371,6 @@ void addDumpInfo(const char *inbuffer)

void dbgDumpInit(int argc, const char **argv, const char *packageVersion)
{
debug_register_callback(&debug_exceptionhandler_data, NULL, NULL, NULL);
debug_register_callback(&debug_exceptionhandler_data, nullptr, nullptr, nullptr);
createHeader(argc, argv, packageVersion);
}
50 changes: 25 additions & 25 deletions lib/exceptionhandler/exceptionhandler.cpp
Expand Up @@ -320,59 +320,59 @@ static void setFatalSignalHandler(SigActionHandler signalHandler)
new_handler.sa_handler = signalHandler;
#endif

sigaction(SIGABRT, NULL, &oldAction[SIGABRT]);
sigaction(SIGABRT, nullptr, &oldAction[SIGABRT]);
if (oldAction[SIGABRT].sa_handler != SIG_IGN)
{
sigaction(SIGABRT, &new_handler, NULL);
sigaction(SIGABRT, &new_handler, nullptr);
}

sigaction(SIGBUS, NULL, &oldAction[SIGBUS]);
sigaction(SIGBUS, nullptr, &oldAction[SIGBUS]);
if (oldAction[SIGBUS].sa_handler != SIG_IGN)
{
sigaction(SIGBUS, &new_handler, NULL);
sigaction(SIGBUS, &new_handler, nullptr);
}

sigaction(SIGFPE, NULL, &oldAction[SIGFPE]);
sigaction(SIGFPE, nullptr, &oldAction[SIGFPE]);
if (oldAction[SIGFPE].sa_handler != SIG_IGN)
{
sigaction(SIGFPE, &new_handler, NULL);
sigaction(SIGFPE, &new_handler, nullptr);
}

sigaction(SIGILL, NULL, &oldAction[SIGILL]);
sigaction(SIGILL, nullptr, &oldAction[SIGILL]);
if (oldAction[SIGILL].sa_handler != SIG_IGN)
{
sigaction(SIGILL, &new_handler, NULL);
sigaction(SIGILL, &new_handler, nullptr);
}

sigaction(SIGQUIT, NULL, &oldAction[SIGQUIT]);
sigaction(SIGQUIT, nullptr, &oldAction[SIGQUIT]);
if (oldAction[SIGQUIT].sa_handler != SIG_IGN)
{
sigaction(SIGQUIT, &new_handler, NULL);
sigaction(SIGQUIT, &new_handler, nullptr);
}

sigaction(SIGSEGV, NULL, &oldAction[SIGSEGV]);
sigaction(SIGSEGV, nullptr, &oldAction[SIGSEGV]);
if (oldAction[SIGSEGV].sa_handler != SIG_IGN)
{
sigaction(SIGSEGV, &new_handler, NULL);
sigaction(SIGSEGV, &new_handler, nullptr);
}

#if _XOPEN_UNIX
sigaction(SIGSYS, NULL, &oldAction[SIGSYS]);
sigaction(SIGSYS, nullptr, &oldAction[SIGSYS]);
if (oldAction[SIGSYS].sa_handler != SIG_IGN)
{
sigaction(SIGSYS, &new_handler, NULL);
sigaction(SIGSYS, &new_handler, nullptr);
}

sigaction(SIGXCPU, NULL, &oldAction[SIGXCPU]);
sigaction(SIGXCPU, nullptr, &oldAction[SIGXCPU]);
if (oldAction[SIGXCPU].sa_handler != SIG_IGN)
{
sigaction(SIGXCPU, &new_handler, NULL);
sigaction(SIGXCPU, &new_handler, nullptr);
}

sigaction(SIGXFSZ, NULL, &oldAction[SIGXFSZ]);
sigaction(SIGXFSZ, nullptr, &oldAction[SIGXFSZ]);
if (oldAction[SIGXFSZ].sa_handler != SIG_IGN)
{
sigaction(SIGXFSZ, &new_handler, NULL);
sigaction(SIGXFSZ, &new_handler, nullptr);
}

// ignore SIGTRAP
Expand Down Expand Up @@ -433,8 +433,8 @@ static pid_t execGdb(int const dumpFile, int *gdbWritePipe)
{
int gdbPipe[2];
pid_t pid;
char *gdbArgv[] = { gdbPath, programPath, programPID, NULL };
char *gdbEnv[] = { NULL };
char *gdbArgv[] = { gdbPath, programPath, programPID, nullptr };
char *gdbEnv[] = { nullptr };
/* Check if the "bare minimum" is available: GDB and an absolute path
* to our program's binary.
*/
Expand Down Expand Up @@ -539,7 +539,7 @@ static bool gdbExtendedBacktrace(int const dumpFile)
*/
void const *const frame =
#if defined(SA_SIGINFO) && defined(REG_RBP)
sigcontext ? (void *)(sigcontext->uc_mcontext.gregs[REG_RBP] + sizeof(greg_t) + sizeof(void (*)(void))) : NULL;
sigcontext ? (void *)(sigcontext->uc_mcontext.gregs[REG_RBP] + sizeof(greg_t) + sizeof(void (*)(void))) : nullptr;
#elif defined(SA_SIGINFO) && defined(REG_EBP)
sigcontext ? (void *)(sigcontext->uc_mcontext.gregs[REG_EBP] + sizeof(greg_t) + sizeof(void (*)(void))) : NULL;
#else
Expand All @@ -551,7 +551,7 @@ static bool gdbExtendedBacktrace(int const dumpFile)
*/
void (*instruction)(void) =
#if defined(SA_SIGINFO) && defined(REG_RIP)
sigcontext ? (void (*)(void))sigcontext->uc_mcontext.gregs[REG_RIP] : NULL;
sigcontext ? (void (*)(void))sigcontext->uc_mcontext.gregs[REG_RIP] : nullptr;
#elif defined(SA_SIGINFO) && defined(REG_EIP)
sigcontext ? (void (*)(void))sigcontext->uc_mcontext.gregs[REG_EIP] : NULL;
#else
Expand Down Expand Up @@ -662,7 +662,7 @@ static void posixExceptionHandler(int signum)
int dumpFile;
const char *signal;
# if defined(__GLIBC__)
void *btBuffer[MAX_BACKTRACE] = {NULL};
void *btBuffer[MAX_BACKTRACE] = {nullptr};
uint32_t btSize = backtrace(btBuffer, MAX_BACKTRACE);
# endif

Expand Down Expand Up @@ -722,7 +722,7 @@ static void posixExceptionHandler(int signum)
close(dumpFile);


sigaction(signum, &oldAction[signum], NULL);
sigaction(signum, &oldAction[signum], nullptr);
raise(signum);
}

Expand Down Expand Up @@ -810,7 +810,7 @@ void setupExceptionHandler(int argc, const char **argv, const char *packageVersi

sysInfoValid = (uname(&sysInfo) == 0);

currentTime = time(NULL);
currentTime = time(nullptr);
sstrcpy(executionDate, ctime(&currentTime));

snprintf(programPID, sizeof(programPID), "%i", getpid());
Expand Down
18 changes: 9 additions & 9 deletions lib/framework/debug.cpp
Expand Up @@ -43,7 +43,7 @@
char last_called_script_event[MAX_EVENT_NAME_LEN];
UDWORD traceID = -1;

static debug_callback *callbackRegistry = NULL;
static debug_callback *callbackRegistry = nullptr;
bool enabled_debug[LOG_LAST]; // global
#ifdef DEBUG
bool assertEnabled = true;
Expand Down Expand Up @@ -208,7 +208,7 @@ bool debug_callback_file_init(void **data)
return false;
}
snprintf(WZ_DBGFile, sizeof(WZ_DBGFile), "%s", WZDebugfilename);
setbuf(logfile, NULL);
setbuf(logfile, nullptr);
fprintf(logfile, "\n--- Starting log [%s]---\n", WZDebugfilename);
*data = logfile;

Expand All @@ -227,7 +227,7 @@ void debug_callback_file_exit(void **data)
{
FILE *logfile = (FILE *)*data;
fclose(logfile);
*data = NULL;
*data = nullptr;
}

void debugFlushStderr()
Expand Down Expand Up @@ -291,7 +291,7 @@ void debug_init()

void debug_exit()
{
debug_callback *curCallback = callbackRegistry, * tmpCallback = NULL;
debug_callback *curCallback = callbackRegistry, * tmpCallback = nullptr;

while (curCallback)
{
Expand All @@ -304,17 +304,17 @@ void debug_exit()
curCallback = tmpCallback;
}
warning_list.clear();
callbackRegistry = NULL;
callbackRegistry = nullptr;
}


void debug_register_callback(debug_callback_fn callback, debug_callback_init init, debug_callback_exit exit, void *data)
{
debug_callback *curCallback = callbackRegistry, * tmpCallback = NULL;
debug_callback *curCallback = callbackRegistry, * tmpCallback = nullptr;

tmpCallback = (debug_callback *)malloc(sizeof(*tmpCallback));

tmpCallback->next = NULL;
tmpCallback->next = nullptr;
tmpCallback->callback = callback;
tmpCallback->init = init;
tmpCallback->exit = exit;
Expand Down Expand Up @@ -367,7 +367,7 @@ static void printToDebugCallbacks(const char *const str)
debug_callback *curCallback;

// Loop over all callbacks, invoking them with the given data string
for (curCallback = callbackRegistry; curCallback != NULL; curCallback = curCallback->next)
for (curCallback = callbackRegistry; curCallback != nullptr; curCallback = curCallback->next)
{
curCallback->callback(&curCallback->data, str);
}
Expand Down Expand Up @@ -401,7 +401,7 @@ const char *debugLastError()
}
else
{
return NULL;
return nullptr;
}
}

Expand Down
10 changes: 5 additions & 5 deletions lib/framework/frame.cpp
Expand Up @@ -196,7 +196,7 @@ static bool loadFile2(const char *pFileName, char **ppFileData, UDWORD *pFileSiz
assert(false);
return false;
}
assert(*ppFileData != NULL);
assert(*ppFileData != nullptr);
}

/* Load the file data */
Expand All @@ -206,7 +206,7 @@ static bool loadFile2(const char *pFileName, char **ppFileData, UDWORD *pFileSiz
if (AllocateMem)
{
free(*ppFileData);
*ppFileData = NULL;
*ppFileData = nullptr;
}

debug(LOG_ERROR, "Reading %s short: %s", pFileName, PHYSFS_getLastError());
Expand All @@ -219,7 +219,7 @@ static bool loadFile2(const char *pFileName, char **ppFileData, UDWORD *pFileSiz
if (AllocateMem)
{
free(*ppFileData);
*ppFileData = NULL;
*ppFileData = nullptr;
}

debug(LOG_ERROR, "Error closing %s: %s", pFileName, PHYSFS_getLastError());
Expand Down Expand Up @@ -250,7 +250,7 @@ PHYSFS_file *openSaveFile(const char *fileName)
}

assert(!"openSaveFile: couldn't open file for writing");
return NULL;
return nullptr;
}

return fileHandle;
Expand Down Expand Up @@ -285,7 +285,7 @@ bool saveFile(const char *pFileName, const char *pFileData, UDWORD fileSize)
return false;
}

if (PHYSFS_getRealDir(pFileName) == NULL)
if (PHYSFS_getRealDir(pFileName) == nullptr)
{
// weird
debug(LOG_ERROR, "PHYSFS_getRealDir(%s) returns NULL (%s)?!", pFileName, PHYSFS_getLastError());
Expand Down

0 comments on commit 9d0f604

Please sign in to comment.