diff options
author | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2024-01-26 16:07:54 +0100 |
---|---|---|
committer | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2024-01-26 16:07:54 +0100 |
commit | 5afe88df2538274859a162ffd63ed52118e80c19 (patch) | |
tree | b610dfd58dc748fd63f49565b2a43eea2316714f /src/utils | |
parent | 73ba2a95f5bd4a0dd09af52d5864800be2b0a4c6 (diff) | |
download | mana-5afe88df2538274859a162ffd63ed52118e80c19.tar.gz mana-5afe88df2538274859a162ffd63ed52118e80c19.tar.bz2 mana-5afe88df2538274859a162ffd63ed52118e80c19.tar.xz mana-5afe88df2538274859a162ffd63ed52118e80c19.zip |
Apply C++11 fixits
modernize-use-auto
modernize-use-nullptr
modernize-use-override
modernize-use-using
Diffstat (limited to 'src/utils')
-rw-r--r-- | src/utils/base64.cpp | 12 | ||||
-rw-r--r-- | src/utils/mutex.h | 2 | ||||
-rw-r--r-- | src/utils/sha256.cpp | 4 | ||||
-rw-r--r-- | src/utils/stringutils.cpp | 2 | ||||
-rw-r--r-- | src/utils/xml.cpp | 14 | ||||
-rw-r--r-- | src/utils/zlib.cpp | 12 |
6 files changed, 23 insertions, 23 deletions
diff --git a/src/utils/base64.cpp b/src/utils/base64.cpp index 57a9fc84..cf10c8fd 100644 --- a/src/utils/base64.cpp +++ b/src/utils/base64.cpp @@ -46,7 +46,7 @@ unsigned char *php3_base64_encode(const unsigned char *string, int length, int * { const unsigned char *current = string; int i = 0; - unsigned char *result = (unsigned char *)malloc(((length + 3 - length % 3) * 4 / 3 + 1) * sizeof(char)); + auto *result = (unsigned char *)malloc(((length + 3 - length % 3) * 4 / 3 + 1) * sizeof(char)); while (length > 2) { /* keep going until we have less than 24 bits */ @@ -91,11 +91,11 @@ unsigned char *php3_base64_decode(const unsigned char *string, int length, int * int ch, i = 0, j = 0, k; char *chp; - unsigned char *result = (unsigned char *)malloc(length + 1); + auto *result = (unsigned char *)malloc(length + 1); - if (result == NULL) + if (result == nullptr) { - return NULL; + return nullptr; } /* run through the whole string, converting as we go */ @@ -113,7 +113,7 @@ unsigned char *php3_base64_decode(const unsigned char *string, int length, int * if (ch == ' ') ch = '+'; chp = strchr(base64_table, ch); - if (chp == NULL) continue; + if (chp == nullptr) continue; ch = chp - base64_table; switch(i % 4) @@ -145,7 +145,7 @@ unsigned char *php3_base64_decode(const unsigned char *string, int length, int * case 0: case 1: free(result); - return NULL; + return nullptr; case 2: k++; case 3: diff --git a/src/utils/mutex.h b/src/utils/mutex.h index d0120cfa..ad95b17b 100644 --- a/src/utils/mutex.h +++ b/src/utils/mutex.h @@ -96,7 +96,7 @@ inline MutexLocker::MutexLocker(Mutex *mutex): inline MutexLocker::MutexLocker(MutexLocker&& rhs): mMutex(rhs.mMutex) { - rhs.mMutex = NULL; + rhs.mMutex = nullptr; } inline MutexLocker::~MutexLocker() diff --git a/src/utils/sha256.cpp b/src/utils/sha256.cpp index 761f4edb..a97dce3c 100644 --- a/src/utils/sha256.cpp +++ b/src/utils/sha256.cpp @@ -78,8 +78,8 @@ #ifdef HAVE_STDINT_H #include <stdint.h> #else -typedef unsigned char uint8_t; -typedef unsigned int uint32_t; +using uint8_t = unsigned char; +using uint32_t = unsigned int; #endif #define SHA256_BLOCK_SIZE (512 / 8) diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp index 05f1bf7b..59a3f17d 100644 --- a/src/utils/stringutils.cpp +++ b/src/utils/stringutils.cpp @@ -194,7 +194,7 @@ bool getBoolFromString(const std::string &text, bool def) std::string autocomplete(std::vector<std::string> &candidates, std::string base) { - std::vector<std::string>::iterator i = candidates.begin(); + auto i = candidates.begin(); toLower(base); std::string newName(""); diff --git a/src/utils/xml.cpp b/src/utils/xml.cpp index 839479d7..d0f51230 100644 --- a/src/utils/xml.cpp +++ b/src/utils/xml.cpp @@ -46,7 +46,7 @@ namespace XML }; Document::Document(const std::string &filename, bool useResman): - mDoc(0) + mDoc(nullptr) { XMLContext ctx; ctx.file = filename; @@ -54,7 +54,7 @@ namespace XML xmlSetStructuredErrorFunc(&ctx, xmlLogger); int size; - char *data = NULL; + char *data = nullptr; if (useResman) { ResourceManager *resman = ResourceManager::getInstance(); @@ -78,7 +78,7 @@ namespace XML logger->log("Error loading %s", filename.c_str()); } - xmlSetStructuredErrorFunc(NULL, xmlLogger); + xmlSetStructuredErrorFunc(nullptr, xmlLogger); } Document::~Document() @@ -89,7 +89,7 @@ namespace XML xmlNodePtr Document::rootNode() { - return mDoc ? xmlDocGetRootElement(mDoc) : 0; + return mDoc ? xmlDocGetRootElement(mDoc) : nullptr; } int getProperty(xmlNodePtr node, const char* name, int def) @@ -152,12 +152,12 @@ namespace XML if (xmlStrEqual(child->name, BAD_CAST name)) return child; - return NULL; + return nullptr; } static void xmlLogger(void *ctx, xmlErrorPtr error) { - XMLContext *context = static_cast<XMLContext*>(ctx); + auto *context = static_cast<XMLContext*>(ctx); if (context) logger->log("Error in XML file '%s' on line %d", @@ -180,7 +180,7 @@ namespace XML LIBXML_TEST_VERSION; // Handle libxml2 error messages - xmlSetStructuredErrorFunc(NULL, xmlLogger); + xmlSetStructuredErrorFunc(nullptr, xmlLogger); } } // namespace XML diff --git a/src/utils/zlib.cpp b/src/utils/zlib.cpp index 7a5421fd..8234766e 100644 --- a/src/utils/zlib.cpp +++ b/src/utils/zlib.cpp @@ -57,7 +57,7 @@ int inflateMemory(unsigned char *in, unsigned int inLength, do { - if (strm.next_out == NULL) + if (strm.next_out == nullptr) { inflateEnd(&strm); return Z_MEM_ERROR; @@ -80,7 +80,7 @@ int inflateMemory(unsigned char *in, unsigned int inLength, { out = (unsigned char*) realloc(out, bufferSize * 2); - if (out == NULL) + if (out == nullptr) { inflateEnd(&strm); return Z_MEM_ERROR; @@ -105,7 +105,7 @@ int inflateMemory(unsigned char *in, unsigned int inLength, unsigned int outLength = 0; int ret = inflateMemory(in, inLength, out, outLength); - if (ret != Z_OK || out == NULL) + if (ret != Z_OK || out == nullptr) { if (ret == Z_MEM_ERROR) { @@ -125,7 +125,7 @@ int inflateMemory(unsigned char *in, unsigned int inLength, } free(out); - out = NULL; + out = nullptr; outLength = 0; } @@ -163,7 +163,7 @@ void *loadCompressedFile(const std::string &filename, int &filesize) { logger->log("Could not decompress file: %s", filename.c_str()); - return NULL; + return nullptr; } filesize = inflatedSize; @@ -179,5 +179,5 @@ void *loadCompressedFile(const std::string &filename, int &filesize) logger->log("Error loading file from drive: %s", filename.c_str()); } - return NULL; + return nullptr; } |