summaryrefslogtreecommitdiffstats
path: root/Tools
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2016-08-24 21:45:03 +0200
committerMattes D <github@xoft.cz>2016-08-24 22:26:53 +0200
commitd2e8643607424cd74616e2e863f5609e7b8458a5 (patch)
treed5afab6035ca6bb0b58fd03ad5cfe3b3f8e1da55 /Tools
parentMerge pull request #3342 from cuberite/FixEmptyHeader (diff)
downloadcuberite-d2e8643607424cd74616e2e863f5609e7b8458a5.tar
cuberite-d2e8643607424cd74616e2e863f5609e7b8458a5.tar.gz
cuberite-d2e8643607424cd74616e2e863f5609e7b8458a5.tar.bz2
cuberite-d2e8643607424cd74616e2e863f5609e7b8458a5.tar.lz
cuberite-d2e8643607424cd74616e2e863f5609e7b8458a5.tar.xz
cuberite-d2e8643607424cd74616e2e863f5609e7b8458a5.tar.zst
cuberite-d2e8643607424cd74616e2e863f5609e7b8458a5.zip
Diffstat (limited to 'Tools')
-rw-r--r--Tools/GrownBiomeGenVisualiser/CMakeLists.txt9
-rw-r--r--Tools/MCADefrag/CMakeLists.txt10
-rw-r--r--Tools/MCADefrag/Globals.h6
-rw-r--r--Tools/MCADefrag/MCADefrag.cpp35
-rw-r--r--Tools/ProtoProxy/CMakeLists.txt12
-rw-r--r--Tools/ProtoProxy/Connection.cpp14
-rw-r--r--Tools/ProtoProxy/Globals.h6
-rw-r--r--Tools/ProtoProxy/ProtoProxy.cpp23
-rw-r--r--Tools/ProtoProxy/Server.cpp8
-rw-r--r--Tools/ProtoProxy/Server.h2
10 files changed, 55 insertions, 70 deletions
diff --git a/Tools/GrownBiomeGenVisualiser/CMakeLists.txt b/Tools/GrownBiomeGenVisualiser/CMakeLists.txt
index e270f6d9a..c84ab9426 100644
--- a/Tools/GrownBiomeGenVisualiser/CMakeLists.txt
+++ b/Tools/GrownBiomeGenVisualiser/CMakeLists.txt
@@ -8,16 +8,9 @@ set_flags()
set_lib_flags()
enable_profile()
-if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
- add_flags_cxx("-Wno-error=sign-conversion -Wno-error=conversion -Wno-error=shorten-64-to-32")
- add_flags_cxx("-Wno-error=old-style-cast")
- if ("${CLANG_VERSION}" VERSION_GREATER 3.5)
- add_flags_cxx("-Wno-error=keyword-macro")
- endif()
-endif()
# Set include paths to the used libraries:
-include_directories("../../lib")
+include_directories(SYSTEM "../../lib")
include_directories("../../src")
diff --git a/Tools/MCADefrag/CMakeLists.txt b/Tools/MCADefrag/CMakeLists.txt
index efa4abddb..f8c8ac65a 100644
--- a/Tools/MCADefrag/CMakeLists.txt
+++ b/Tools/MCADefrag/CMakeLists.txt
@@ -8,16 +8,8 @@ set_flags()
set_lib_flags()
enable_profile()
-if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
- add_flags_cxx("-Wno-error=sign-conversion -Wno-error=conversion -Wno-error=shorten-64-to-32")
- add_flags_cxx("-Wno-error=old-style-cast")
- if ("${CLANG_VERSION}" VERSION_GREATER 3.5)
- add_flags_cxx("-Wno-error=keyword-macro")
- endif()
-endif()
-
# Set include paths to the used libraries:
-include_directories("../../lib")
+include_directories(SYSTEM "../../lib")
include_directories("../../src")
diff --git a/Tools/MCADefrag/Globals.h b/Tools/MCADefrag/Globals.h
index f13a06566..ed9ef82fe 100644
--- a/Tools/MCADefrag/Globals.h
+++ b/Tools/MCADefrag/Globals.h
@@ -36,9 +36,6 @@
// TODO: Can GCC explicitly mark classes as abstract (no instances can be created)?
#define abstract
- // TODO: Can GCC mark virtual methods as overriding (forcing them to have a virtual function of the same signature in the base class)
- #define override
-
#define OBSOLETE __attribute__((deprecated))
#define ALIGN_8 __attribute__((aligned(8)))
@@ -64,9 +61,6 @@
// Explicitly mark classes as abstract (no instances can be created)
#define abstract
- // Mark virtual methods as overriding (forcing them to have a virtual function of the same signature in the base class)
- #define override
-
// Mark functions as obsolete, so that their usage results in a compile-time warning
#define OBSOLETE
diff --git a/Tools/MCADefrag/MCADefrag.cpp b/Tools/MCADefrag/MCADefrag.cpp
index cf1db85d5..c7de1933b 100644
--- a/Tools/MCADefrag/MCADefrag.cpp
+++ b/Tools/MCADefrag/MCADefrag.cpp
@@ -257,7 +257,10 @@ bool cMCADefrag::cThread::ReadChunk(cFile & a_File, const Byte * a_LocationRaw)
int SizeInSectors = a_LocationRaw[3] * (4 KiB);
if (a_File.Seek(SectorNum * (4 KiB)) < 0)
{
- LOGWARNING("Failed to seek to chunk data - file pos %llu (%d KiB, %.02f MiB)!", (Int64)SectorNum * (4 KiB), SectorNum * 4, ((double)SectorNum) / 256);
+ LOGWARNING("Failed to seek to chunk data - file pos %llu (%d KiB, %.02f MiB)!",
+ static_cast<Int64>(SectorNum) * (4 KiB), SectorNum * 4,
+ static_cast<double>(SectorNum) / 256
+ );
return false;
}
@@ -276,7 +279,7 @@ bool cMCADefrag::cThread::ReadChunk(cFile & a_File, const Byte * a_LocationRaw)
}
// Read the data:
- if (a_File.Read(m_CompressedChunkData, m_CompressedChunkDataSize) != m_CompressedChunkDataSize)
+ if (a_File.Read(m_CompressedChunkData, static_cast<size_t>(m_CompressedChunkDataSize)) != m_CompressedChunkDataSize)
{
LOGWARNING("Failed to read chunk data!");
return false;
@@ -311,15 +314,15 @@ bool cMCADefrag::cThread::WriteChunk(cFile & a_File, Byte * a_LocationRaw)
}
// Update the Location:
- a_LocationRaw[0] = m_CurrentSectorOut >> 16;
+ a_LocationRaw[0] = static_cast<Byte>(m_CurrentSectorOut >> 16);
a_LocationRaw[1] = (m_CurrentSectorOut >> 8) & 0xff;
a_LocationRaw[2] = m_CurrentSectorOut & 0xff;
- a_LocationRaw[3] = (m_CompressedChunkDataSize + (4 KiB) + 3) / (4 KiB); // +3 because the m_CompressedChunkDataSize doesn't include the exact-length
+ a_LocationRaw[3] = static_cast<Byte>((m_CompressedChunkDataSize + (4 KiB) + 3) / (4 KiB)); // +3 because the m_CompressedChunkDataSize doesn't include the exact-length
m_CurrentSectorOut += a_LocationRaw[3];
// Write the data length:
Byte Buf[4];
- Buf[0] = m_CompressedChunkDataSize >> 24;
+ Buf[0] = static_cast<Byte>(m_CompressedChunkDataSize >> 24);
Buf[1] = (m_CompressedChunkDataSize >> 16) & 0xff;
Buf[2] = (m_CompressedChunkDataSize >> 8) & 0xff;
Buf[3] = m_CompressedChunkDataSize & 0xff;
@@ -330,7 +333,7 @@ bool cMCADefrag::cThread::WriteChunk(cFile & a_File, Byte * a_LocationRaw)
}
// Write the data:
- if (a_File.Write(m_CompressedChunkData, m_CompressedChunkDataSize) != m_CompressedChunkDataSize)
+ if (a_File.Write(m_CompressedChunkData, static_cast<size_t>(m_CompressedChunkDataSize)) != m_CompressedChunkDataSize)
{
LOGWARNING("Failed to write chunk data!");
return false;
@@ -339,7 +342,7 @@ bool cMCADefrag::cThread::WriteChunk(cFile & a_File, Byte * a_LocationRaw)
// Pad onto the next sector:
int NumPadding = a_LocationRaw[3] * 4096 - (m_CompressedChunkDataSize + 4);
ASSERT(NumPadding >= 0);
- if ((NumPadding > 0) && (a_File.Write(g_Zeroes, NumPadding) != NumPadding))
+ if ((NumPadding > 0) && (a_File.Write(g_Zeroes, static_cast<size_t>(NumPadding)) != NumPadding))
{
LOGWARNING("Failed to write padding");
return false;
@@ -382,14 +385,14 @@ bool cMCADefrag::cThread::UncompressChunkZlib(void)
{
// Uncompress the data:
z_stream strm;
- strm.zalloc = (alloc_func)NULL;
- strm.zfree = (free_func)NULL;
- strm.opaque = NULL;
+ strm.zalloc = nullptr;
+ strm.zfree = nullptr;
+ strm.opaque = nullptr;
inflateInit(&strm);
strm.next_out = m_RawChunkData;
strm.avail_out = sizeof(m_RawChunkData);
strm.next_in = m_CompressedChunkData + 1; // The first byte is the compression method, skip it
- strm.avail_in = m_CompressedChunkDataSize;
+ strm.avail_in = static_cast<uInt>(m_CompressedChunkDataSize);
int res = inflate(&strm, Z_FINISH);
inflateEnd(&strm);
if (res != Z_STREAM_END)
@@ -397,7 +400,8 @@ bool cMCADefrag::cThread::UncompressChunkZlib(void)
LOGWARNING("Failed to uncompress chunk data: %s", strm.msg);
return false;
}
- m_RawChunkDataSize = strm.total_out;
+ ASSERT(strm.total_out < static_cast<uLong>(std::numeric_limits<int>::max()));
+ m_RawChunkDataSize = static_cast<int>(strm.total_out);
return true;
}
@@ -409,7 +413,7 @@ bool cMCADefrag::cThread::UncompressChunkZlib(void)
bool cMCADefrag::cThread::CompressChunk(void)
{
// Check that the compressed data can fit:
- uLongf CompressedSize = compressBound(m_RawChunkDataSize);
+ uLongf CompressedSize = compressBound(static_cast<uLong>(m_RawChunkDataSize));
if (CompressedSize > sizeof(m_CompressedChunkData))
{
LOGINFO("Too much data for the internal compression buffer!");
@@ -417,14 +421,15 @@ bool cMCADefrag::cThread::CompressChunk(void)
}
// Compress the data using the highest compression factor:
- int errorcode = compress2(m_CompressedChunkData + 1, &CompressedSize, m_RawChunkData, m_RawChunkDataSize, Z_BEST_COMPRESSION);
+ int errorcode = compress2(m_CompressedChunkData + 1, &CompressedSize, m_RawChunkData, static_cast<uLong>(m_RawChunkDataSize), Z_BEST_COMPRESSION);
if (errorcode != Z_OK)
{
LOGINFO("Recompression failed: %d", errorcode);
return false;
}
m_CompressedChunkData[0] = COMPRESSION_ZLIB;
- m_CompressedChunkDataSize = CompressedSize + 1;
+ ASSERT(CompressedSize < static_cast<uLong>(std::numeric_limits<int>::max()));
+ m_CompressedChunkDataSize = static_cast<int>(CompressedSize + 1);
return true;
}
diff --git a/Tools/ProtoProxy/CMakeLists.txt b/Tools/ProtoProxy/CMakeLists.txt
index ea9799780..5c83123c3 100644
--- a/Tools/ProtoProxy/CMakeLists.txt
+++ b/Tools/ProtoProxy/CMakeLists.txt
@@ -7,18 +7,10 @@ set_lib_flags()
# Set include paths to the used libraries:
-include_directories("../../lib")
-include_directories("../../lib/polarssl/include")
+include_directories(SYSTEM "../../lib")
+include_directories(SYSTEM "../../lib/polarssl/include")
include_directories("../../src")
-if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
- add_flags_cxx("-Wno-error=sign-conversion -Wno-error=conversion -Wno-error=shorten-64-to-32")
- add_flags_cxx("-Wno-error=old-style-cast")
- if ("${CLANG_VERSION}" VERSION_GREATER 3.5)
- add_flags_cxx("-Wno-error=keyword-macro")
- endif()
-endif()
-
function(flatten_files arg1)
set(res "")
foreach(f ${${arg1}})
diff --git a/Tools/ProtoProxy/Connection.cpp b/Tools/ProtoProxy/Connection.cpp
index 62d64c49e..2804a881c 100644
--- a/Tools/ProtoProxy/Connection.cpp
+++ b/Tools/ProtoProxy/Connection.cpp
@@ -151,7 +151,7 @@ AString PrintableAbsIntTriplet(int a_X, int a_Y, int a_Z, double a_Divisor)
{
return Printf("<%d, %d, %d> ~ {%.02f, %.02f, %.02f}",
a_X, a_Y, a_Z,
- (double)a_X / a_Divisor, (double)a_Y / a_Divisor, (double)a_Z / a_Divisor
+ static_cast<double>(a_X) / a_Divisor, static_cast<double>(a_Y) / a_Divisor, static_cast<double>(a_Z) / a_Divisor
);
}
@@ -212,7 +212,7 @@ cConnection::cConnection(SOCKET a_ClientSocket, cServer & a_Server) :
mkdir("Logs", 0777);
#endif
- Printf(m_LogNameBase, "Logs/Log_%d_%d", (int)time(NULL), a_ClientSocket);
+ Printf(m_LogNameBase, "Logs/Log_%d_%d", static_cast<int>(time(nullptr)), static_cast<int>(a_ClientSocket));
AString fnam(m_LogNameBase);
fnam.append(".log");
#ifdef _WIN32
@@ -352,7 +352,7 @@ bool cConnection::ConnectToServer(void)
localhost.sin_family = AF_INET;
localhost.sin_port = htons(m_Server.GetConnectPort());
localhost.sin_addr.s_addr = htonl(0x7f000001); // localhost
- if (connect(m_ServerSocket, (sockaddr *)&localhost, sizeof(localhost)) != 0)
+ if (connect(m_ServerSocket, reinterpret_cast<const sockaddr *>(&localhost), sizeof(localhost)) != 0)
{
printf("connection to server failed: %d\n", SocketError);
return false;
@@ -485,13 +485,13 @@ bool cConnection::SendData(SOCKET a_Socket, cByteBuffer & a_Data, const char * a
bool cConnection::SendEncryptedData(SOCKET a_Socket, cAesCfb128Encryptor & a_Encryptor, const char * a_Data, size_t a_Size, const char * a_Peer)
{
DataLog(a_Data, a_Size, "Encrypting %d bytes to %s", a_Size, a_Peer);
- const Byte * Data = (const Byte *)a_Data;
+ const Byte * Data = reinterpret_cast<const Byte *>(a_Data);
while (a_Size > 0)
{
Byte Buffer[64 KiB];
size_t NumBytes = (a_Size > sizeof(Buffer)) ? sizeof(Buffer) : a_Size;
a_Encryptor.ProcessData(Buffer, Data, NumBytes);
- bool res = SendData(a_Socket, (const char *)Buffer, NumBytes, a_Peer);
+ bool res = SendData(a_Socket, reinterpret_cast<const char *>(Buffer), NumBytes, a_Peer);
if (!res)
{
return false;
@@ -1313,7 +1313,7 @@ bool cConnection::HandleServerLoginEncryptionKeyRequest(void)
}
Log("Got PACKET_ENCRYPTION_KEY_REQUEST from the SERVER:");
Log(" ServerID = %s", ServerID.c_str());
- DataLog(PublicKey.data(), PublicKey.size(), " Public key (%u bytes)", (unsigned)PublicKey.size());
+ DataLog(PublicKey.data(), PublicKey.size(), " Public key (%u bytes)", static_cast<unsigned>(PublicKey.size()));
// Reply to the server:
SendEncryptionKeyResponse(PublicKey, Nonce);
@@ -2942,7 +2942,7 @@ void cConnection::SendEncryptionKeyResponse(const AString & a_ServerPublicKey, c
// Encrypt the nonce:
Byte EncryptedNonce[128];
- res = PubKey.Encrypt((const Byte *)a_Nonce.data(), a_Nonce.size(), EncryptedNonce, sizeof(EncryptedNonce));
+ res = PubKey.Encrypt(reinterpret_cast<const Byte *>(a_Nonce.data()), a_Nonce.size(), EncryptedNonce, sizeof(EncryptedNonce));
if (res < 0)
{
Log("Nonce encryption failed: %d (0x%x)", res, res);
diff --git a/Tools/ProtoProxy/Globals.h b/Tools/ProtoProxy/Globals.h
index c69931bd5..b15c36cd3 100644
--- a/Tools/ProtoProxy/Globals.h
+++ b/Tools/ProtoProxy/Globals.h
@@ -29,9 +29,6 @@
// TODO: Can GCC explicitly mark classes as abstract (no instances can be created)?
#define abstract
- // TODO: Can GCC mark virtual methods as overriding (forcing them to have a virtual function of the same signature in the base class)
- #define override
-
#define OBSOLETE __attribute__((deprecated))
#define ALIGN_8 __attribute__((aligned(8)))
@@ -52,9 +49,6 @@
// Explicitly mark classes as abstract (no instances can be created)
#define abstract
- // Mark virtual methods as overriding (forcing them to have a virtual function of the same signature in the base class)
- #define override
-
// Mark functions as obsolete, so that their usage results in a compile-time warning
#define OBSOLETE
diff --git a/Tools/ProtoProxy/ProtoProxy.cpp b/Tools/ProtoProxy/ProtoProxy.cpp
index 06a486778..ac5858d02 100644
--- a/Tools/ProtoProxy/ProtoProxy.cpp
+++ b/Tools/ProtoProxy/ProtoProxy.cpp
@@ -27,14 +27,29 @@ int main(int argc, char ** argv)
cLogger::InitiateMultithreading();
- int ListenPort = (argc > 1) ? atoi(argv[1]) : 25564;
- int ConnectPort = (argc > 2) ? atoi(argv[2]) : 25565;
- printf("Initializing ProtoProxy. Listen port %d, connect port %d.\n", ListenPort, ConnectPort);
+ UInt16 ListenPort = 25564;
+ UInt16 ConnectPort = 25565;
+ if (argc > 1)
+ {
+ if (!StringToInteger(argv[1], ListenPort))
+ {
+ LOGERROR("Invalid argument 1, expected port number, got \"%s\". Aborting.", argv[1]);
+ return 1;
+ }
+ if (argc > 2)
+ {
+ if (!StringToInteger(argv[2], ConnectPort))
+ {
+ LOGERROR("Invalid argument 2, expected port number, got \"%s\". Aborting.", argv[2]);
+ return 2;
+ }
+ }
+ }
cServer Server;
int res = Server.Init(ListenPort, ConnectPort);
if (res != 0)
{
- printf("Server initialization failed: %d", res);
+ LOGERROR("Server initialization failed: %d", res);
return res;
}
diff --git a/Tools/ProtoProxy/Server.cpp b/Tools/ProtoProxy/Server.cpp
index 98baec8da..60998798c 100644
--- a/Tools/ProtoProxy/Server.cpp
+++ b/Tools/ProtoProxy/Server.cpp
@@ -20,7 +20,7 @@ cServer::cServer(void)
-int cServer::Init(short a_ListenPort, short a_ConnectPort)
+int cServer::Init(UInt16 a_ListenPort, UInt16 a_ConnectPort)
{
m_ConnectPort = a_ConnectPort;
@@ -50,7 +50,7 @@ int cServer::Init(short a_ListenPort, short a_ConnectPort)
local.sin_family = AF_INET;
local.sin_addr.s_addr = INADDR_ANY; // All interfaces
local.sin_port = htons(a_ListenPort);
- if (bind(m_ListenSocket, (sockaddr *)&local, sizeof(local)) != 0)
+ if (bind(m_ListenSocket, reinterpret_cast<const sockaddr *>(&local), sizeof(local)) != 0)
{
#ifdef _WIN32
int err = WSAGetLastError();
@@ -70,7 +70,7 @@ int cServer::Init(short a_ListenPort, short a_ConnectPort)
printf("Failed to listen on socket: %d\n", err);
return err;
}
- LOGINFO("Listening on port %d, connecting to localhost:%d", a_ListenPort, a_ConnectPort);
+ LOGINFO("Listening for client connections on port %d, connecting to server at localhost:%d", a_ListenPort, a_ConnectPort);
LOGINFO("Generating protocol encryption keypair...");
m_PrivateKey.Generate();
@@ -91,7 +91,7 @@ void cServer::Run(void)
sockaddr_in Addr;
memset(&Addr, 0, sizeof(Addr));
socklen_t AddrSize = sizeof(Addr);
- SOCKET client = accept(m_ListenSocket, (sockaddr *)&Addr, &AddrSize);
+ SOCKET client = accept(m_ListenSocket, reinterpret_cast<sockaddr *>(&Addr), &AddrSize);
if (client == INVALID_SOCKET)
{
printf("accept returned an error: %d; bailing out.\n", SocketError);
diff --git a/Tools/ProtoProxy/Server.h b/Tools/ProtoProxy/Server.h
index 9782503fb..bfa16c36c 100644
--- a/Tools/ProtoProxy/Server.h
+++ b/Tools/ProtoProxy/Server.h
@@ -26,7 +26,7 @@ class cServer
public:
cServer(void);
- int Init(short a_ListenPort, short a_ConnectPort);
+ int Init(UInt16 a_ListenPort, UInt16 a_ConnectPort);
void Run(void);
cRsaPrivateKey & GetPrivateKey(void) { return m_PrivateKey; }