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

@@ -24,7 +24,9 @@
#include <framework/core/application.h>
#include <framework/core/eventdispatcher.h>
#include <boost/asio.hpp>
#include <memory>
asio::io_service g_ioService;
std::list<std::shared_ptr<asio::streambuf>> Connection::m_outputStreams;
@@ -123,7 +125,7 @@ void Connection::write(uint8* buffer, size_t size)
m_outputStream = m_outputStreams.front();
m_outputStreams.pop_front();
} else
m_outputStream = std::shared_ptr<asio::streambuf>(new asio::streambuf);
m_outputStream = std::make_shared<asio::streambuf>();
m_delayedWriteTimer.cancel();
m_delayedWriteTimer.expires_from_now(boost::posix_time::milliseconds(0));
@@ -177,7 +179,7 @@ void Connection::read_until(const std::string& what, const RecvCallback& callbac
asio::async_read_until(m_socket,
m_inputStream,
what.c_str(),
what,
std::bind(&Connection::onRecv, asConnection(), std::placeholders::_1, std::placeholders::_2));
m_readTimer.cancel();

View File

@@ -144,7 +144,7 @@ void Protocol::internalRecvData(uint8* buffer, uint16 size)
void Protocol::generateXteaKey()
{
std::mt19937 eng(std::time(NULL));
std::mt19937 eng(std::time(nullptr));
std::uniform_int_distribution<uint32> unif(0, 0xFFFFFFFF);
m_xteaKey[0] = unif(eng);
m_xteaKey[1] = unif(eng);