From 54b1e8f836c17fe023d93310f48cbfee800843b5 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 15 Aug 2019 11:00:42 -0400 Subject: [PATCH] General: Use nullptr where applicable Uses nullptr instead of NULL or the 0 integer literal where applicable. --- include/athena/Utility.hpp | 4 ++-- src/LZ77/LZType11.cpp | 2 +- src/athena/Compression.cpp | 4 ++-- src/athena/Dir.cpp | 6 +++--- src/athena/FileInfo.cpp | 16 ++++++++-------- src/athena/Socket.cpp | 4 ++-- src/athena/Utility.cpp | 2 +- 7 files changed, 19 insertions(+), 19 deletions(-) diff --git a/include/athena/Utility.hpp b/include/athena/Utility.hpp index e2c7c08..1602564 100644 --- a/include/athena/Utility.hpp +++ b/include/athena/Utility.hpp @@ -181,9 +181,9 @@ atUint64 rand64(); std::string join(const std::vector& elems, std::string_view delims); void tolower(std::string& str); void toupper(std::string& str); -bool parseBool(std::string_view boolean, bool* valid = NULL); +bool parseBool(std::string_view boolean, bool* valid = nullptr); -int countChar(std::string_view str, const char chr, int* lastOccur = NULL); +int countChar(std::string_view str, char chr, int* lastOccur = nullptr); // trim from start std::string& ltrim(std::string& s); diff --git a/src/LZ77/LZType11.cpp b/src/LZ77/LZType11.cpp index 41cee43..de26bd8 100644 --- a/src/LZ77/LZType11.cpp +++ b/src/LZ77/LZType11.cpp @@ -106,7 +106,7 @@ atUint32 LZType11::compress(const atUint8* src, atUint8** dst, atUint32 srcLengt } delete[] compressedBytes; - compressedBytes = NULL; + compressedBytes = nullptr; // Add zeros until the file is a multiple of 4 while ((outbuff.position() % 4) != 0) diff --git a/src/athena/Compression.cpp b/src/athena/Compression.cpp index 4f72837..ff23040 100644 --- a/src/athena/Compression.cpp +++ b/src/athena/Compression.cpp @@ -10,7 +10,7 @@ namespace athena::io::Compression { atInt32 decompressZlib(const atUint8* src, atUint32 srcLen, atUint8* dst, atUint32 dstLen) { - z_stream strm = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + z_stream strm = {}; strm.total_in = strm.avail_in = srcLen; strm.total_out = strm.avail_out = dstLen; strm.next_in = (Bytef*)src; @@ -45,7 +45,7 @@ atInt32 decompressZlib(const atUint8* src, atUint32 srcLen, atUint8* dst, atUint } atInt32 compressZlib(const atUint8* src, atUint32 srcLen, atUint8* dst, atUint32 dstLen) { - z_stream strm = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + z_stream strm = {}; strm.total_in = strm.avail_in = srcLen; strm.total_out = strm.avail_out = dstLen; strm.next_in = (Bytef*)src; diff --git a/src/athena/Dir.cpp b/src/athena/Dir.cpp index 6f6a02c..bdb3b09 100644 --- a/src/athena/Dir.cpp +++ b/src/athena/Dir.cpp @@ -1,7 +1,8 @@ #include "athena/Dir.hpp" #include +#include #include -#include +#include #define __STDC_FORMAT_MACROS #include #include "athena/Utility.hpp" @@ -10,7 +11,6 @@ #include #include #else -#include #include #endif @@ -45,7 +45,7 @@ bool Dir::cd(std::string_view path) { bool Dir::rm(std::string_view path) { return !(remove((m_path + "/" + path.data()).c_str()) < 0); } bool Dir::touch() { - srand(time(NULL)); + std::srand(std::time(nullptr)); atUint64 tmp = utility::rand64(); std::string tmpFile = fmt::format(fmt("{:016X}.tmp"), tmp); bool ret = FileInfo(m_path + "/" + tmpFile).touch(); diff --git a/src/athena/FileInfo.cpp b/src/athena/FileInfo.cpp index fb47e01..d78913c 100644 --- a/src/athena/FileInfo.cpp +++ b/src/athena/FileInfo.cpp @@ -104,7 +104,7 @@ bool FileInfo::touch() const { (void)athena::io::FileWriter(m_path); return true; } - if (utimes(m_path.c_str(), NULL) < 0) { + if (utimes(m_path.c_str(), nullptr) < 0) { return false; } #elif defined(_WIN32) @@ -114,7 +114,7 @@ bool FileInfo::touch() const { wchar_t date[80], time[80]; #if !WINDOWS_STORE - fh = CreateFileA(m_path.c_str(), GENERIC_READ | FILE_WRITE_ATTRIBUTES, 0, NULL, CREATE_NEW, 0, NULL); + fh = CreateFileA(m_path.c_str(), GENERIC_READ | FILE_WRITE_ATTRIBUTES, 0, nullptr, CREATE_NEW, 0, nullptr); if (fh == INVALID_HANDLE_VALUE) return false; @@ -122,14 +122,14 @@ bool FileInfo::touch() const { /* * Use GetFileTime() to get the file modification time. */ - if (GetFileTime(fh, NULL, NULL, &modtime) == 0) { + if (GetFileTime(fh, nullptr, nullptr, &modtime) == 0) { CloseHandle(fh); return false; } FileTimeToSystemTime(&modtime, &st); - if (GetDateFormatW(LOCALE_USER_DEFAULT, DATE_LONGDATE, &st, NULL, date, sizeof date / sizeof date[0]) == 0 || - GetTimeFormatW(LOCALE_USER_DEFAULT, 0, &st, NULL, time, sizeof time / sizeof time[0]) == 0) { + if (GetDateFormatW(LOCALE_USER_DEFAULT, DATE_LONGDATE, &st, nullptr, date, sizeof date / sizeof date[0]) == 0 || + GetTimeFormatW(LOCALE_USER_DEFAULT, 0, &st, nullptr, time, sizeof time / sizeof time[0]) == 0) { CloseHandle(fh); return false; } @@ -139,13 +139,13 @@ bool FileInfo::touch() const { * to the current time. */ GetSystemTime(&st); - if (GetDateFormatW(LOCALE_USER_DEFAULT, DATE_LONGDATE, &st, NULL, date, sizeof date / sizeof date[0]) == 0 || - GetTimeFormatW(LOCALE_USER_DEFAULT, 0, &st, NULL, time, sizeof time / sizeof time[0]) == 0) { + if (GetDateFormatW(LOCALE_USER_DEFAULT, DATE_LONGDATE, &st, nullptr, date, sizeof date / sizeof date[0]) == 0 || + GetTimeFormatW(LOCALE_USER_DEFAULT, 0, &st, nullptr, time, sizeof time / sizeof time[0]) == 0) { CloseHandle(fh); return false; } SystemTimeToFileTime(&st, &modtime); - if (SetFileTime(fh, NULL, NULL, &modtime) == 0) { + if (SetFileTime(fh, nullptr, nullptr, &modtime) == 0) { CloseHandle(fh); return false; } diff --git a/src/athena/Socket.cpp b/src/athena/Socket.cpp index 8f2f7c4..129972a 100644 --- a/src/athena/Socket.cpp +++ b/src/athena/Socket.cpp @@ -45,8 +45,8 @@ void IPAddress::resolve(const std::string& address) { addrinfo hints; memset(&hints, 0, sizeof(hints)); hints.ai_family = AF_INET; - addrinfo* result = NULL; - if (getaddrinfo(address.c_str(), NULL, &hints, &result) == 0) { + addrinfo* result = nullptr; + if (getaddrinfo(address.c_str(), nullptr, &hints, &result) == 0) { if (result) { addr = reinterpret_cast(result->ai_addr)->sin_addr; freeaddrinfo(result); diff --git a/src/athena/Utility.cpp b/src/athena/Utility.cpp index da36334..c0665fc 100644 --- a/src/athena/Utility.cpp +++ b/src/athena/Utility.cpp @@ -100,7 +100,7 @@ int countChar(std::string_view str, const char chr, int* lastOccur) { for (char c : str) { if (c == chr) { - if (lastOccur != NULL) + if (lastOccur != nullptr) *lastOccur = index; ret++;