Tidy up the source code

* Replaced push_back calls with emplace_back where applicable.
* Replaced size() == 0 and size() != 0 with empty() and !empty().
* Replaced C style loops for range for loops where applicable.
* Fixed mismatching arg names between function declarations and definitions.
* Replaced NULL and 0 (in the context of pointers) with nullptr.
* Remove unnecessary calls to string::c_str() where applicable.
* Replaced deprecated C headers with proper C++ headers.
* Removed unnecessary null pointer checks when deleting pointers
(deleting a null pointer has no effect).
* Fixed a potential memory leak in apngloader.cpp file.
* Replaced unsafe strcpy with strncpy in the demangle_name function.
This commit is contained in:
Kamil Chojnowski
2019-10-10 00:21:26 +02:00
parent caae18dbce
commit 869de6886f
59 changed files with 202 additions and 199 deletions

View File

@@ -52,7 +52,7 @@ public:
any() : content(nullptr) { }
any(const any& other) : content(other.content ? other.content->clone() : nullptr) { }
template<typename T> any(const T& value) : content(new holder<T>(value)) { }
~any() { if(content) delete content; }
~any() { delete content; }
any& swap(any& rhs) { std::swap(content, rhs.content); return *this; }

View File

@@ -44,20 +44,21 @@ namespace stdext {
const char* demangle_name(const char* name)
{
static const unsigned BufferSize = 1024;
static char Buffer[1024] = {};
#ifdef _MSC_VER
static char buffer[1024];
UnDecorateSymbolName(name, buffer, sizeof(buffer), UNDNAME_COMPLETE);
return buffer;
UnDecorateSymbolName(name, Buffer, BufferSize, UNDNAME_COMPLETE);
return Buffer;
#else
size_t len;
int status;
static char buffer[1024];
char* demangled = abi::__cxa_demangle(name, 0, &len, &status);
char* demangled = abi::__cxa_demangle(name, nullptr, &len, &status);
if(demangled) {
strcpy(buffer, demangled);
strncpy(Buffer, demangled, BufferSize);
free(demangled);
}
return buffer;
return Buffer;
#endif
}

View File

@@ -66,4 +66,4 @@ double round(double r)
return (r > 0.0) ? floor(r + 0.5) : ceil(r - 0.5);
}
}
}

View File

@@ -41,7 +41,7 @@ class packed_storage {
public:
packed_storage() : m_values(nullptr), m_size(0) { }
~packed_storage() { if(m_values) delete[] m_values; }
~packed_storage() { delete[] m_values; }
template<typename T>
void set(Key id, const T& value) {

View File

@@ -46,7 +46,7 @@ public:
template <class InputIterator>
packed_vector(InputIterator first, InputIterator last) : m_size(last - first), m_data(new T[m_size]) { std::copy(first, last, m_data); }
packed_vector(const packed_vector<T>& other) : m_size(other.m_size), m_data(new T[other.m_size]) { std::copy(other.begin(), other.end(), m_data); }
~packed_vector() { if(m_data) delete[] m_data; }
~packed_vector() { delete[] m_data; }
packed_vector<T,U>& operator=(packed_vector<T,U> other) { other.swap(*this); return *this; }

View File

@@ -23,22 +23,22 @@
#ifndef STDEXT_H
#define STDEXT_H
#include "compiler.h"
#include "dumper.h"
#include "types.h"
#include "exception.h"
#include "demangle.h"
#include "any.h"
#include "boolean.h"
#include "cast.h"
#include "compiler.h"
#include "demangle.h"
#include "dumper.h"
#include "dynamic_storage.h"
#include "exception.h"
#include "format.h"
#include "math.h"
#include "packed_any.h"
#include "packed_storage.h"
#include "packed_vector.h"
#include "shared_object.h"
#include "string.h"
#include "time.h"
#include "boolean.h"
#include "shared_object.h"
#include "any.h"
#include "packed_any.h"
#include "dynamic_storage.h"
#include "packed_storage.h"
#include "format.h"
#include "packed_vector.h"
#include "types.h"
#endif

View File

@@ -23,7 +23,7 @@
#include "string.h"
#include "format.h"
#include <boost/algorithm/string.hpp>
#include <ctype.h>
#include <cctype>
#include <physfs.h>
#ifdef _MSC_VER

View File

@@ -21,6 +21,7 @@
*/
#include "time.h"
#include <chrono>
#include <ctime>
#include <thread>
@@ -30,7 +31,7 @@ namespace stdext {
const static auto startup_time = std::chrono::high_resolution_clock::now();
ticks_t time() {
return std::time(NULL);
return std::time(nullptr);
}
ticks_t millis()