diff options
author | Mattes D <github@xoft.cz> | 2016-08-24 21:45:03 +0200 |
---|---|---|
committer | Mattes D <github@xoft.cz> | 2016-08-24 22:26:53 +0200 |
commit | d2e8643607424cd74616e2e863f5609e7b8458a5 (patch) | |
tree | d5afab6035ca6bb0b58fd03ad5cfe3b3f8e1da55 | |
parent | Merge pull request #3342 from cuberite/FixEmptyHeader (diff) | |
download | cuberite-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 |
42 files changed, 145 insertions, 211 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; } diff --git a/src/BlockArea.cpp b/src/BlockArea.cpp index 438d958b9..b54f6b2e7 100644 --- a/src/BlockArea.cpp +++ b/src/BlockArea.cpp @@ -632,9 +632,9 @@ void cBlockArea::DumpToRawFile(const AString & a_FileName) LOGWARNING("cBlockArea: Cannot open file \"%s\" for raw dump", a_FileName.c_str()); return; } - UInt32 SizeX = ntohl(m_Size.x); - UInt32 SizeY = ntohl(m_Size.y); - UInt32 SizeZ = ntohl(m_Size.z); + UInt32 SizeX = ntohl(static_cast<UInt32>(m_Size.x)); + UInt32 SizeY = ntohl(static_cast<UInt32>(m_Size.y)); + UInt32 SizeZ = ntohl(static_cast<UInt32>(m_Size.z)); f.Write(&SizeX, 4); f.Write(&SizeY, 4); f.Write(&SizeZ, 4); diff --git a/src/BlockEntities/CMakeLists.txt b/src/BlockEntities/CMakeLists.txt index 8e57c172f..96dfa8d85 100644 --- a/src/BlockEntities/CMakeLists.txt +++ b/src/BlockEntities/CMakeLists.txt @@ -44,8 +44,7 @@ SET (HDRS ) if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") - set_source_files_properties(BeaconEntity.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=conversion -Wno-error=switch-enum") - set_source_files_properties(NoteEntity.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=conversion -Wno-error=sign-conversion") + set_source_files_properties(BeaconEntity.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=switch-enum") endif() if(NOT MSVC) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 11e2f8376..ac1c8138b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -163,29 +163,13 @@ configure_file("BuildInfo.h.cmake" "${CMAKE_CURRENT_SOURCE_DIR}/BuildInfo.h") if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") set_source_files_properties(BiomeDef.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=switch-enum") - set_source_files_properties(BlockArea.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=sign-conversion") set_source_files_properties(BlockID.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=global-constructors") - set_source_files_properties(BoundingBox.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=global-constructors -Wno-error=float-equal") - set_source_files_properties(ByteBuffer.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=sign-conversion -Wno-error=global-constructors") - set_source_files_properties(ChunkData.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=sign-conversion ") - set_source_files_properties(ChunkMap.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=shadow -Wno-error=sign-conversion ") - set_source_files_properties(ClientHandle.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=conversion -Wno-error=sign-conversion -Wno-error=global-constructors ") - set_source_files_properties(CompositeChat.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=global-constructors -Wno-error=missing-variable-declarations") - set_source_files_properties(IniFile.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=sign-conversion ") - set_source_files_properties(Inventory.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=conversion") - set_source_files_properties(Item.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=conversion ") - set_source_files_properties(ItemGrid.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=conversion") - set_source_files_properties(LightingThread.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=conversion -Wno-error=sign-conversion") - set_source_files_properties(Map.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=conversion -Wno-error=old-style-cast") - set_source_files_properties(MobProximityCounter.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=float-equal") + set_source_files_properties(BoundingBox.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=global-constructors") + set_source_files_properties(ByteBuffer.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=global-constructors") + set_source_files_properties(ClientHandle.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=global-constructors ") + set_source_files_properties(CompositeChat.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=global-constructors") set_source_files_properties(MobSpawner.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=switch-enum") - set_source_files_properties(RCONServer.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=sign-conversion") - set_source_files_properties(Root.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=sign-conversion -Wno-error=shadow -Wno-error=old-style-cast") set_source_files_properties(Statistics.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=global-constructors") - set_source_files_properties(StringUtils.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=conversion ") - set_source_files_properties(Tracer.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=sign-conversion") - set_source_files_properties(World.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=sign-conversion ") - set_source_files_properties(main.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=missing-variable-declarations -Wno-error=missing-prototypes") endif() if (NOT MSVC) diff --git a/src/Generating/CMakeLists.txt b/src/Generating/CMakeLists.txt index 8b0577129..2cd923a99 100644 --- a/src/Generating/CMakeLists.txt +++ b/src/Generating/CMakeLists.txt @@ -71,17 +71,11 @@ SET (HDRS if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") set_source_files_properties(BioGen.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=switch-enum") set_source_files_properties(CompoGenBiomal.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=global-constructors ") - set_source_files_properties(ComposableGenerator.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=switch-enum -Wno-error=old-style-cast") - set_source_files_properties(DistortedHeightmap.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=old-style-cast") - set_source_files_properties(EndGen.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=old-style-cast") + set_source_files_properties(ComposableGenerator.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=switch-enum") set_source_files_properties(FinishGen.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=switch-enum -Wno-error=switch") - set_source_files_properties(HeiGen.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=old-style-cast") - set_source_files_properties(Noise3DGenerator.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=old-style-cast") set_source_files_properties(PieceGenerator.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=global-constructors") set_source_files_properties(Prefab.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=global-constructors") - set_source_files_properties(Ravines.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=old-style-cast") - set_source_files_properties(RoughRavines.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=float-equal -Wno-error=old-style-cast") - set_source_files_properties(StructGen.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=switch-enum -Wno-error=switch -Wno-error=old-style-cast") + set_source_files_properties(StructGen.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=switch-enum -Wno-error=switch") set_source_files_properties(VillageGen.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=global-constructors -Wno-error=switch-enum") endif() diff --git a/src/Generating/RoughRavines.cpp b/src/Generating/RoughRavines.cpp index c8e4fc9dd..f6f984ab4 100644 --- a/src/Generating/RoughRavines.cpp +++ b/src/Generating/RoughRavines.cpp @@ -181,7 +181,7 @@ protected: { #ifdef _DEBUG // DEBUG: Make the roughravine shapepoints visible on a single layer (so that we can see with Minutor what's going on) - if ((DifX + x == 0) && (DifZ + z == 0)) + if ((FloorC(DifX + x) == 0) && (FloorC(DifZ + z) == 0)) { a_ChunkDesc.SetBlockType(x, 4, z, E_BLOCK_LAPIS_ORE); } @@ -194,8 +194,8 @@ protected: continue; } - int Top = std::min(static_cast<int>(ceilf(itr->m_Top)), +cChunkDef::Height); - for (int y = std::max(static_cast<int>(floorf(itr->m_Bottom)), 1); y <= Top; y++) + int Top = std::min(CeilC(itr->m_Top), +cChunkDef::Height); + for (int y = std::max(FloorC(itr->m_Bottom), 1); y <= Top; y++) { if ((itr->m_Radius + m_PerHeightRadius[y]) * (itr->m_Radius + m_PerHeightRadius[y]) < DistSq) { diff --git a/src/HTTP/CMakeLists.txt b/src/HTTP/CMakeLists.txt index 3a2001e67..1e7b0672b 100644 --- a/src/HTTP/CMakeLists.txt +++ b/src/HTTP/CMakeLists.txt @@ -35,7 +35,6 @@ SET (HDRS if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") set_source_files_properties(HTTPServer.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=global-constructors ") set_source_files_properties(HTTPServerConnection.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=switch-enum") - set_source_files_properties(HTTPMessage.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=tautological-compare") endif() if(NOT MSVC) diff --git a/src/Items/CMakeLists.txt b/src/Items/CMakeLists.txt index f7341bb53..eacc1e53f 100644 --- a/src/Items/CMakeLists.txt +++ b/src/Items/CMakeLists.txt @@ -58,7 +58,7 @@ SET (HDRS ) if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") - set_source_files_properties(ItemHandler.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=sign-conversion -Wno-error=conversion -Wno-error=switch-enum") + set_source_files_properties(ItemHandler.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=switch-enum") endif() if(NOT MSVC) diff --git a/src/Mobs/CMakeLists.txt b/src/Mobs/CMakeLists.txt index 85fdb4b1b..44c664b6e 100644 --- a/src/Mobs/CMakeLists.txt +++ b/src/Mobs/CMakeLists.txt @@ -81,7 +81,7 @@ SET (HDRS ZombiePigman.h) if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") - set_source_files_properties(Monster.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=sign-conversion -Wno-error=conversion -Wno-error=switch -Wno-error=switch-enum -Wno-error=float-equal ") + set_source_files_properties(Monster.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=switch -Wno-error=switch-enum") endif() if(NOT MSVC) diff --git a/src/Mobs/Rabbit.h b/src/Mobs/Rabbit.h index aafd979d1..289ff0282 100644 --- a/src/Mobs/Rabbit.h +++ b/src/Mobs/Rabbit.h @@ -42,7 +42,6 @@ public: } eRabbitType GetRabbitType() const { return m_Type; } - UInt8 GetRabbitTypeAsNumber() const { return static_cast<UInt8>(GetRabbitType()); } int GetMoreCarrotTicks() const { return m_MoreCarrotTicks; } private: diff --git a/src/PolarSSL++/CMakeLists.txt b/src/PolarSSL++/CMakeLists.txt index 375e6f51e..3d77e15d1 100644 --- a/src/PolarSSL++/CMakeLists.txt +++ b/src/PolarSSL++/CMakeLists.txt @@ -32,10 +32,6 @@ set(HDRS X509Cert.h ) -if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") - set_source_files_properties(RsaPrivateKey.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=old-style-cast") -endif() - if(NOT MSVC) add_library(PolarSSL++ ${SRCS} ${HDRS}) diff --git a/src/PolarSSL++/RsaPrivateKey.cpp b/src/PolarSSL++/RsaPrivateKey.cpp index 17cede05f..50620ecd4 100644 --- a/src/PolarSSL++/RsaPrivateKey.cpp +++ b/src/PolarSSL++/RsaPrivateKey.cpp @@ -3,8 +3,8 @@ #include "Globals.h" #include "RsaPrivateKey.h" +#include <polarssl/pk.h> #include "CtrDrbgContext.h" -#include "polarssl/pk.h" @@ -112,7 +112,7 @@ int cRsaPrivateKey::Decrypt(const Byte * a_EncryptedData, size_t a_EncryptedLeng if (a_EncryptedLength < m_Rsa.len) { LOGD("%s: Invalid a_EncryptedLength: got %u, exp at least %u", - __FUNCTION__, (unsigned)a_EncryptedLength, (unsigned)(m_Rsa.len) + __FUNCTION__, static_cast<unsigned>(a_EncryptedLength), static_cast<unsigned>(m_Rsa.len) ); ASSERT(!"Invalid a_DecryptedMaxLength!"); return -1; @@ -120,7 +120,7 @@ int cRsaPrivateKey::Decrypt(const Byte * a_EncryptedData, size_t a_EncryptedLeng if (a_DecryptedMaxLength < m_Rsa.len) { LOGD("%s: Invalid a_DecryptedMaxLength: got %u, exp at least %u", - __FUNCTION__, (unsigned)a_EncryptedLength, (unsigned)(m_Rsa.len) + __FUNCTION__, static_cast<unsigned>(a_EncryptedLength), static_cast<unsigned>(m_Rsa.len) ); ASSERT(!"Invalid a_DecryptedMaxLength!"); return -1; @@ -146,7 +146,7 @@ int cRsaPrivateKey::Encrypt(const Byte * a_PlainData, size_t a_PlainLength, Byte if (a_EncryptedMaxLength < m_Rsa.len) { LOGD("%s: Invalid a_EncryptedMaxLength: got %u, exp at least %u", - __FUNCTION__, (unsigned)a_EncryptedMaxLength, (unsigned)(m_Rsa.len) + __FUNCTION__, static_cast<unsigned>(a_EncryptedMaxLength), static_cast<unsigned>(m_Rsa.len) ); ASSERT(!"Invalid a_DecryptedMaxLength!"); return -1; @@ -154,7 +154,7 @@ int cRsaPrivateKey::Encrypt(const Byte * a_PlainData, size_t a_PlainLength, Byte if (a_PlainLength < m_Rsa.len) { LOGD("%s: Invalid a_PlainLength: got %u, exp at least %u", - __FUNCTION__, (unsigned)a_PlainLength, (unsigned)(m_Rsa.len) + __FUNCTION__, static_cast<unsigned>(a_PlainLength), static_cast<unsigned>(m_Rsa.len) ); ASSERT(!"Invalid a_PlainLength!"); return -1; diff --git a/src/Protocol/CMakeLists.txt b/src/Protocol/CMakeLists.txt index 220449fa3..f3282c93f 100644 --- a/src/Protocol/CMakeLists.txt +++ b/src/Protocol/CMakeLists.txt @@ -24,8 +24,8 @@ SET (HDRS ) if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") - set_source_files_properties(Protocol19x.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=old-style-cast -Wno-error=sign-conversion -Wno-error=conversion -Wno-error=switch-enum -Wno-error=switch") - set_source_files_properties(Protocol18x.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=old-style-cast -Wno-error=sign-conversion -Wno-error=conversion -Wno-error=switch-enum -Wno-error=switch") + set_source_files_properties(Protocol19x.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=switch-enum -Wno-error=switch") + set_source_files_properties(Protocol18x.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=switch-enum -Wno-error=switch") endif() if (NOT MSVC) diff --git a/src/Protocol/Protocol18x.cpp b/src/Protocol/Protocol18x.cpp index b158dee4d..88a0757f2 100644 --- a/src/Protocol/Protocol18x.cpp +++ b/src/Protocol/Protocol18x.cpp @@ -3471,7 +3471,7 @@ void cProtocol180::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_Mob) { auto & Rabbit = reinterpret_cast<const cRabbit &>(a_Mob); a_Pkt.WriteBEUInt8(0x12); - a_Pkt.WriteBEUInt8(Rabbit.GetRabbitTypeAsNumber()); + a_Pkt.WriteBEUInt8(static_cast<UInt8>(Rabbit.GetRabbitType())); a_Pkt.WriteBEUInt8(0x0c); a_Pkt.WriteBEInt8(Rabbit.IsBaby() ? -1 : (Rabbit.IsInLoveCooldown() ? 1 : 0)); break; diff --git a/src/Protocol/Protocol19x.cpp b/src/Protocol/Protocol19x.cpp index b0e458691..d8c86cf6b 100644 --- a/src/Protocol/Protocol19x.cpp +++ b/src/Protocol/Protocol19x.cpp @@ -402,7 +402,7 @@ void cProtocol190::SendEntityEquipment(const cEntity & a_Entity, short a_SlotNum { a_SlotNum++; } - Pkt.WriteVarInt32(a_SlotNum); + Pkt.WriteVarInt32(static_cast<UInt32>(a_SlotNum)); WriteItem(Pkt, a_Item); } @@ -3137,7 +3137,7 @@ void cProtocol190::StartEncryption(const Byte * a_Key) -eBlockFace cProtocol190::FaceIntToBlockFace(UInt32 a_BlockFace) +eBlockFace cProtocol190::FaceIntToBlockFace(Int32 a_BlockFace) { // Normalize the blockface values returned from the protocol // Anything known gets mapped 1:1, everything else returns BLOCK_FACE_NONE @@ -3543,14 +3543,10 @@ void cProtocol190::WriteEntityMetadata(cPacketizer & a_Pkt, const cEntity & a_En a_Pkt.WriteBEUInt8(METADATA_TYPE_VARINT); // The following expression makes Minecarts shake more with less health or higher damage taken - // It gets half the maximum health, and takes it away from the current health minus the half health: - /* - Health: 5 | 3 - (5 - 3) = 1 (shake power) - Health: 3 | 3 - (3 - 3) = 3 - Health: 1 | 3 - (1 - 3) = 5 - */ auto & Minecart = reinterpret_cast<const cMinecart &>(a_Entity); - a_Pkt.WriteVarInt32((((a_Entity.GetMaxHealth() / 2) - (a_Entity.GetHealth() - (a_Entity.GetMaxHealth() / 2))) * Minecart.LastDamage()) * 4); + auto maxHealth = a_Entity.GetMaxHealth(); + auto curHealth = a_Entity.GetHealth(); + a_Pkt.WriteVarInt32(static_cast<UInt32>((maxHealth - curHealth) * Minecart.LastDamage() * 4)); a_Pkt.WriteBEUInt8(6); // Index 6: Shaking direction (doesn't seem to effect anything) a_Pkt.WriteBEUInt8(METADATA_TYPE_VARINT); @@ -3570,11 +3566,11 @@ void cProtocol190::WriteEntityMetadata(cPacketizer & a_Pkt, const cEntity & a_En a_Pkt.WriteBEUInt8(METADATA_TYPE_VARINT); int Content = MinecartContent.m_ItemType; Content |= MinecartContent.m_ItemDamage << 8; - a_Pkt.WriteVarInt32(Content); + a_Pkt.WriteVarInt32(static_cast<UInt32>(Content)); a_Pkt.WriteBEUInt8(9); // Index 9: Block ID and damage a_Pkt.WriteBEUInt8(METADATA_TYPE_VARINT); - a_Pkt.WriteVarInt32(RideableMinecart.GetBlockHeight()); + a_Pkt.WriteVarInt32(static_cast<UInt32>(RideableMinecart.GetBlockHeight())); a_Pkt.WriteBEUInt8(10); // Index 10: Show block a_Pkt.WriteBEUInt8(METADATA_TYPE_BOOL); @@ -3718,7 +3714,7 @@ void cProtocol190::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_Mob) auto & Creeper = reinterpret_cast<const cCreeper &>(a_Mob); a_Pkt.WriteBEUInt8(11); // Index 11: State (idle or "blowing") a_Pkt.WriteBEUInt8(METADATA_TYPE_VARINT); - a_Pkt.WriteVarInt32(Creeper.IsBlowing() ? 1 : -1); + a_Pkt.WriteVarInt32(Creeper.IsBlowing() ? 1 : 0xffffffff); a_Pkt.WriteBEUInt8(12); // Index 12: Is charged a_Pkt.WriteBEUInt8(METADATA_TYPE_BOOL); @@ -3736,7 +3732,7 @@ void cProtocol190::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_Mob) a_Pkt.WriteBEUInt8(11); // Index 11: Carried block a_Pkt.WriteBEUInt8(METADATA_TYPE_BLOCKID); UInt32 Carried = 0; - Carried |= Enderman.GetCarriedBlock() << 4; + Carried |= static_cast<UInt32>(Enderman.GetCarriedBlock() << 4); Carried |= Enderman.GetCarriedMeta(); a_Pkt.WriteVarInt32(Carried); @@ -3789,18 +3785,18 @@ void cProtocol190::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_Mob) a_Pkt.WriteBEUInt8(13); // Index 13: Variant / type a_Pkt.WriteBEUInt8(METADATA_TYPE_VARINT); - a_Pkt.WriteVarInt32(Horse.GetHorseType()); + a_Pkt.WriteVarInt32(static_cast<UInt32>(Horse.GetHorseType())); a_Pkt.WriteBEUInt8(14); // Index 14: Color / style a_Pkt.WriteBEUInt8(METADATA_TYPE_VARINT); int Appearance = 0; Appearance = Horse.GetHorseColor(); Appearance |= Horse.GetHorseStyle() << 8; - a_Pkt.WriteVarInt32(Appearance); + a_Pkt.WriteVarInt32(static_cast<UInt32>(Appearance)); a_Pkt.WriteBEUInt8(16); // Index 16: Armor a_Pkt.WriteBEUInt8(METADATA_TYPE_VARINT); - a_Pkt.WriteVarInt32(Horse.GetHorseArmour()); + a_Pkt.WriteVarInt32(static_cast<UInt32>(Horse.GetHorseArmour())); a_Pkt.WriteBEUInt8(11); // Index 11: Is baby a_Pkt.WriteBEUInt8(METADATA_TYPE_BOOL); @@ -3813,7 +3809,7 @@ void cProtocol190::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_Mob) auto & MagmaCube = reinterpret_cast<const cMagmaCube &>(a_Mob); a_Pkt.WriteBEUInt8(11); // Index 11: Size a_Pkt.WriteBEUInt8(METADATA_TYPE_VARINT); - a_Pkt.WriteVarInt32(MagmaCube.GetSize()); + a_Pkt.WriteVarInt32(static_cast<UInt32>(MagmaCube.GetSize())); break; } // case mtMagmaCube @@ -3873,7 +3869,7 @@ void cProtocol190::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_Mob) a_Pkt.WriteBEUInt8(12); // Index 12: sheared, color a_Pkt.WriteBEUInt8(METADATA_TYPE_BYTE); Int8 SheepMetadata = 0; - SheepMetadata = static_cast<Byte>(Sheep.GetFurColor()); + SheepMetadata = static_cast<Int8>(Sheep.GetFurColor()); if (Sheep.IsSheared()) { SheepMetadata |= 0x10; @@ -3891,7 +3887,7 @@ void cProtocol190::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_Mob) a_Pkt.WriteBEUInt8(12); // Index 12: Type a_Pkt.WriteBEUInt8(METADATA_TYPE_VARINT); - a_Pkt.WriteVarInt32(Rabbit.GetRabbitTypeAsNumber()); + a_Pkt.WriteVarInt32(static_cast<UInt32>(Rabbit.GetRabbitType())); break; } // case mtRabbit @@ -3909,7 +3905,7 @@ void cProtocol190::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_Mob) auto & Slime = reinterpret_cast<const cSlime &>(a_Mob); a_Pkt.WriteBEUInt8(11); // Index 11: Size a_Pkt.WriteBEUInt8(METADATA_TYPE_VARINT); - a_Pkt.WriteVarInt32(Slime.GetSize()); + a_Pkt.WriteVarInt32(static_cast<UInt32>(Slime.GetSize())); break; } // case mtSlime @@ -3922,7 +3918,7 @@ void cProtocol190::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_Mob) a_Pkt.WriteBEUInt8(12); // Index 12: Type a_Pkt.WriteBEUInt8(METADATA_TYPE_VARINT); - a_Pkt.WriteVarInt32(Villager.GetVilType()); + a_Pkt.WriteVarInt32(static_cast<UInt32>(Villager.GetVilType())); break; } // case mtVillager @@ -3980,7 +3976,7 @@ void cProtocol190::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_Mob) a_Pkt.WriteBEUInt8(16); // Index 16: Collar color a_Pkt.WriteBEUInt8(METADATA_TYPE_VARINT); - a_Pkt.WriteVarInt32(Wolf.GetCollarColor()); + a_Pkt.WriteVarInt32(static_cast<UInt32>(Wolf.GetCollarColor())); break; } // case mtWolf diff --git a/src/Protocol/Protocol19x.h b/src/Protocol/Protocol19x.h index d23653702..2bf8df4f5 100644 --- a/src/Protocol/Protocol19x.h +++ b/src/Protocol/Protocol19x.h @@ -258,7 +258,7 @@ protected: /** Converts the BlockFace received by the protocol into eBlockFace constants. If the received value doesn't match any of our eBlockFace constants, BLOCK_FACE_NONE is returned. */ - eBlockFace FaceIntToBlockFace(UInt32 a_FaceInt); + eBlockFace FaceIntToBlockFace(Int32 a_FaceInt); /** Writes the item data into a packet. */ void WriteItem(cPacketizer & a_Pkt, const cItem & a_Item); diff --git a/src/Simulator/CMakeLists.txt b/src/Simulator/CMakeLists.txt index dcd099890..45972a6ef 100644 --- a/src/Simulator/CMakeLists.txt +++ b/src/Simulator/CMakeLists.txt @@ -11,7 +11,8 @@ SET (SRCS Simulator.cpp SimulatorManager.cpp VanillaFluidSimulator.cpp - VaporizeFluidSimulator.cpp) + VaporizeFluidSimulator.cpp +) SET (HDRS DelayedFluidSimulator.h @@ -25,14 +26,10 @@ SET (HDRS Simulator.h SimulatorManager.h VanillaFluidSimulator.h - VaporizeFluidSimulator.h) + VaporizeFluidSimulator.h +) -if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") - set_source_files_properties(FireSimulator.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=sign-conversion") - set_source_files_properties(FluidSimulator.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=sign-conversion -Wno-error=shadow") -endif() - if(NOT MSVC) add_library(Simulator ${SRCS} ${HDRS}) endif() diff --git a/src/Simulator/FluidSimulator.cpp b/src/Simulator/FluidSimulator.cpp index 10e4fee21..fce5e64b9 100644 --- a/src/Simulator/FluidSimulator.cpp +++ b/src/Simulator/FluidSimulator.cpp @@ -120,7 +120,7 @@ bool cFluidSimulator::IsHigherMeta(NIBBLETYPE a_Meta1, NIBBLETYPE a_Meta2) // TODO Not working very well yet :s Direction cFluidSimulator::GetFlowingDirection(int a_X, int a_Y, int a_Z, bool a_Over) { - if ((a_Y < 0) || (a_Y >= cChunkDef::Height)) + if (!cChunkDef::IsValidHeight(a_Y)) { return NONE; } @@ -157,11 +157,11 @@ Direction cFluidSimulator::GetFlowingDirection(int a_X, int a_Y, int a_Z, bool a Points.push_back(new Vector3i(a_X, a_Y, a_Z + 1)); Points.push_back(new Vector3i(a_X, a_Y, a_Z - 1)); - for (std::vector<Vector3i *>::iterator it = Points.begin(); it < Points.end(); ++it) + for (auto itr = Points.cbegin(), end = Points.cend(); itr != end; ++itr) { - Vector3i *Pos = (*it); - BLOCKTYPE BlockID = m_World.GetBlock(Pos->x, Pos->y, Pos->z); - if (IsAllowedBlock(BlockID)) + Vector3i * Pos = (*itr); + auto PosBlockID = m_World.GetBlock(Pos->x, Pos->y, Pos->z); + if (IsAllowedBlock(PosBlockID)) { NIBBLETYPE Meta = m_World.GetBlockMeta(Pos->x, Pos->y, Pos->z); @@ -172,7 +172,7 @@ Direction cFluidSimulator::GetFlowingDirection(int a_X, int a_Y, int a_Z, bool a Z = Pos->z; } } - else if (BlockID == E_BLOCK_AIR) + else if (PosBlockID == E_BLOCK_AIR) { LowestPoint = 9; // This always dominates X = Pos->x; diff --git a/src/StringCompression.cpp b/src/StringCompression.cpp index 8be6d0026..ff434bbb1 100644 --- a/src/StringCompression.cpp +++ b/src/StringCompression.cpp @@ -16,7 +16,7 @@ int CompressString(const char * a_Data, size_t a_Length, AString & a_Compressed, // HACK: We're assuming that AString returns its internal buffer in its data() call and we're overwriting that buffer! // It saves us one allocation and one memcpy of the entire compressed data - // It may not work on some STL implementations! (Confirmed working on MSVC 2008 & 2010) + // It may not work on some STL implementations! (Confirmed working on all currently used MSVC, GCC and Clang versions) a_Compressed.resize(CompressedSize); int errorcode = compress2(reinterpret_cast<Bytef *>(const_cast<char *>(a_Compressed.data())), &CompressedSize, reinterpret_cast<const Bytef *>(a_Data), static_cast<uLong>(a_Length), a_Factor); if (errorcode != Z_OK) @@ -35,7 +35,7 @@ int UncompressString(const char * a_Data, size_t a_Length, AString & a_Uncompres { // HACK: We're assuming that AString returns its internal buffer in its data() call and we're overwriting that buffer! // It saves us one allocation and one memcpy of the entire compressed data - // It may not work on some STL implementations! (Confirmed working on MSVC 2008 & 2010) + // It may not work on some STL implementations! (Confirmed working on all currently used MSVC, GCC and Clang versions) a_Uncompressed.resize(a_UncompressedSize); uLongf UncompressedSize = static_cast<uLongf>(a_UncompressedSize); // On some architectures the uLongf is different in size to int, that may be the cause of the -5 error int errorcode = uncompress(reinterpret_cast<Bytef *>(const_cast<char *>(a_Uncompressed.data())), &UncompressedSize, reinterpret_cast<const Bytef *>(a_Data), static_cast<uLong>(a_Length)); diff --git a/src/StringUtils.cpp b/src/StringUtils.cpp index 8ea94ecd7..521aa79f4 100644 --- a/src/StringUtils.cpp +++ b/src/StringUtils.cpp @@ -558,8 +558,8 @@ std::u16string UTF8ToRawBEUTF16(const AString & a_UTF8) { // target is a character in range 0xFFFF - 0x10FFFF. ch -= halfBase; - unsigned short v1 = htons((ch >> halfShift) + UNI_SUR_HIGH_START); - unsigned short v2 = htons((ch & halfMask) + UNI_SUR_LOW_START); + auto v1 = htons(static_cast<uint16_t>((ch >> halfShift) + UNI_SUR_HIGH_START)); + auto v2 = htons(static_cast<uint16_t>((ch & halfMask) + UNI_SUR_LOW_START)); UTF16.push_back(static_cast<char16_t>(v1)); UTF16.push_back(static_cast<char16_t>(v2)); } diff --git a/src/UI/CMakeLists.txt b/src/UI/CMakeLists.txt index e1e82c88d..d71e08ade 100644 --- a/src/UI/CMakeLists.txt +++ b/src/UI/CMakeLists.txt @@ -35,8 +35,8 @@ SET (HDRS WindowOwner.h) if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") - set_source_files_properties(SlotArea.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=conversion -Wno-error=switch-enum -Wno-error=sign-conversion ") - set_source_files_properties(Window.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=conversion -Wno-error=switch-enum -Wno-error=sign-conversion ") + set_source_files_properties(SlotArea.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=switch-enum ") + set_source_files_properties(Window.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=switch-enum ") endif() if(NOT MSVC) diff --git a/src/WorldStorage/CMakeLists.txt b/src/WorldStorage/CMakeLists.txt index b16e03160..c351420f4 100644 --- a/src/WorldStorage/CMakeLists.txt +++ b/src/WorldStorage/CMakeLists.txt @@ -29,11 +29,10 @@ SET (HDRS ) if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") - set_source_files_properties(FastNBT.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=sign-conversion ") set_source_files_properties(FireworksSerializer.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=switch-enum ") - set_source_files_properties(NBTChunkSerializer.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=switch-enum -Wno-error=sign-conversion -Wno-error=conversion ") - set_source_files_properties(SchematicFileSerializer.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=shadow -Wno-error=conversion -Wno-error=global-constructors") - set_source_files_properties(WSSAnvil.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=sign-conversion -Wno-error=shorten-64-to-32 -Wno-error=switch -Wno-error=switch-enum -Wno-error=conversion ") + set_source_files_properties(NBTChunkSerializer.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=switch-enum ") + set_source_files_properties(SchematicFileSerializer.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=global-constructors") + set_source_files_properties(WSSAnvil.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=switch -Wno-error=switch-enum ") endif() if(NOT MSVC) diff --git a/src/WorldStorage/FastNBT.cpp b/src/WorldStorage/FastNBT.cpp index 608269aad..7d99b927a 100644 --- a/src/WorldStorage/FastNBT.cpp +++ b/src/WorldStorage/FastNBT.cpp @@ -439,7 +439,7 @@ void cFastNBTWriter::AddByte(const AString & a_Name, unsigned char a_Value) void cFastNBTWriter::AddShort(const AString & a_Name, Int16 a_Value) { TagCommon(a_Name, TAG_Short); - UInt16 Value = htons(a_Value); + UInt16 Value = htons(static_cast<UInt16>(a_Value)); m_Result.append(reinterpret_cast<const char *>(&Value), 2); } @@ -450,7 +450,7 @@ void cFastNBTWriter::AddShort(const AString & a_Name, Int16 a_Value) void cFastNBTWriter::AddInt(const AString & a_Name, Int32 a_Value) { TagCommon(a_Name, TAG_Int); - UInt32 Value = htonl(a_Value); + UInt32 Value = htonl(static_cast<UInt32>(a_Value)); m_Result.append(reinterpret_cast<const char *>(&Value), 4); } @@ -494,7 +494,7 @@ void cFastNBTWriter::AddDouble(const AString & a_Name, double a_Value) void cFastNBTWriter::AddString(const AString & a_Name, const AString & a_Value) { TagCommon(a_Name, TAG_String); - UInt16 len = htons(static_cast<short>(a_Value.size())); + UInt16 len = htons(static_cast<UInt16>(a_Value.size())); m_Result.append(reinterpret_cast<const char *>(&len), 2); m_Result.append(a_Value.c_str(), a_Value.size()); } @@ -506,7 +506,7 @@ void cFastNBTWriter::AddString(const AString & a_Name, const AString & a_Value) void cFastNBTWriter::AddByteArray(const AString & a_Name, const char * a_Value, size_t a_NumElements) { TagCommon(a_Name, TAG_ByteArray); - u_int len = htonl(static_cast<u_int>(a_NumElements)); + UInt32 len = htonl(static_cast<UInt32>(a_NumElements)); m_Result.append(reinterpret_cast<const char *>(&len), 4); m_Result.append(a_Value, a_NumElements); } @@ -518,7 +518,7 @@ void cFastNBTWriter::AddByteArray(const AString & a_Name, const char * a_Value, void cFastNBTWriter::AddIntArray(const AString & a_Name, const int * a_Value, size_t a_NumElements) { TagCommon(a_Name, TAG_IntArray); - u_int len = htonl(static_cast<u_int>(a_NumElements)); + UInt32 len = htonl(static_cast<UInt32>(a_NumElements)); size_t cap = m_Result.capacity(); size_t size = m_Result.length(); if ((cap - size) < (4 + a_NumElements * 4)) @@ -528,7 +528,7 @@ void cFastNBTWriter::AddIntArray(const AString & a_Name, const int * a_Value, si m_Result.append(reinterpret_cast<const char *>(&len), 4); for (size_t i = 0; i < a_NumElements; i++) { - UInt32 Element = htonl(a_Value[i]); + UInt32 Element = htonl(static_cast<UInt32>(a_Value[i])); m_Result.append(reinterpret_cast<const char *>(&Element), 4); } } diff --git a/src/WorldStorage/NBTChunkSerializer.cpp b/src/WorldStorage/NBTChunkSerializer.cpp index 86ad10af2..a825e4785 100644 --- a/src/WorldStorage/NBTChunkSerializer.cpp +++ b/src/WorldStorage/NBTChunkSerializer.cpp @@ -665,8 +665,8 @@ void cNBTChunkSerializer::AddMonsterEntity(cMonster * a_Monster) } case mtRabbit: { - const cRabbit *Rabbit = reinterpret_cast<const cRabbit *>(a_Monster); - m_Writer.AddInt("RabbitType", Rabbit->GetRabbitTypeAsNumber()); + const cRabbit * Rabbit = reinterpret_cast<const cRabbit *>(a_Monster); + m_Writer.AddInt("RabbitType", static_cast<Int32>(Rabbit->GetRabbitType())); m_Writer.AddInt("MoreCarrotTicks", Rabbit->GetMoreCarrotTicks()); m_Writer.AddInt("Age", Rabbit->GetAge()); break; diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp index 4fc855589..3fd104004 100755 --- a/src/WorldStorage/WSSAnvil.cpp +++ b/src/WorldStorage/WSSAnvil.cpp @@ -2882,8 +2882,7 @@ void cWSSAnvil::LoadWolfFromNBT(cEntityList & a_Entities, const cParsedNBT & a_N case TAG_Byte: { // Vanilla uses this - unsigned char CollarColor = a_NBT.GetByte(CollarColorIdx); - Monster->SetCollarColor(CollarColor); + Monster->SetCollarColor(a_NBT.GetByte(CollarColorIdx)); break; } case TAG_Int: @@ -2892,6 +2891,11 @@ void cWSSAnvil::LoadWolfFromNBT(cEntityList & a_Entities, const cParsedNBT & a_N Monster->SetCollarColor(a_NBT.GetInt(CollarColorIdx)); break; } + default: + { + // No other values are interpreted + break; + } } } @@ -3381,7 +3385,7 @@ bool cWSSAnvil::cMCAFile::SetChunkData(const cChunkCoords & a_Chunk, const AStri // Store the chunk data: m_File.Seek(static_cast<int>(ChunkSector * 4096)); - u_long ChunkSize = htonl(static_cast<u_long>(a_Data.size()) + 1); + UInt32 ChunkSize = htonl(static_cast<UInt32>(a_Data.size() + 1)); if (m_File.Write(&ChunkSize, 4) != 4) { LOGWARNING("Cannot save chunk [%d, %d], writing(1) data to file \"%s\" failed", a_Chunk.m_ChunkX, a_Chunk.m_ChunkZ, GetFileName().c_str()); @@ -3408,7 +3412,7 @@ bool cWSSAnvil::cMCAFile::SetChunkData(const cChunkCoords & a_Chunk, const AStri } // Store the header: - ChunkSize = (static_cast<u_long>(a_Data.size()) + MCA_CHUNK_HEADER_LENGTH + 4095) / 4096; // Round data size up to nearest 4KB sector, make it a sector number + ChunkSize = (static_cast<UInt32>(a_Data.size()) + MCA_CHUNK_HEADER_LENGTH + 4095) / 4096; // Round data size up to nearest 4KB sector, make it a sector number if (ChunkSize > 255) { LOGWARNING("Cannot save chunk [%d, %d], the data is too large (%u KiB, maximum is 1024 KiB). Remove some entities and retry.", @@ -3418,10 +3422,10 @@ bool cWSSAnvil::cMCAFile::SetChunkData(const cChunkCoords & a_Chunk, const AStri } // Store the header info in the table - m_Header[LocalX + 32 * LocalZ] = htonl((ChunkSector << 8) | ChunkSize); + m_Header[LocalX + 32 * LocalZ] = htonl(static_cast<UInt32>((ChunkSector << 8) | ChunkSize)); // Set the modification time - m_TimeStamps[LocalX + 32 * LocalZ] = htonl(static_cast<u_long>(time(nullptr))); + m_TimeStamps[LocalX + 32 * LocalZ] = htonl(static_cast<UInt32>(time(nullptr))); if (m_File.Seek(0) < 0) { diff --git a/tests/BoundingBox/BoundingBoxTest.cpp b/tests/BoundingBox/BoundingBoxTest.cpp index 988a2181e..b27641df2 100644 --- a/tests/BoundingBox/BoundingBoxTest.cpp +++ b/tests/BoundingBox/BoundingBoxTest.cpp @@ -46,7 +46,7 @@ static int Test(void) } if (res) { - if (LineCoeff != LineCoeffs[i]) + if (std::abs(LineCoeff - LineCoeffs[i]) > 0.0000001) { LOGERROR("LineIntersection({%.02f, %.02f, %.02f}, {%.02f, %.02f, %.02f}) -> %d, %.05f, %d", Line1.x, Line1.y, Line1.z, diff --git a/tests/BoundingBox/CMakeLists.txt b/tests/BoundingBox/CMakeLists.txt index 10a4164dc..f2dd42ee9 100644 --- a/tests/BoundingBox/CMakeLists.txt +++ b/tests/BoundingBox/CMakeLists.txt @@ -25,10 +25,6 @@ if (MSVC) list (APPEND SHARED_HDRS ${CMAKE_SOURCE_DIR}/src/LeakFinder.h ${CMAKE_SOURCE_DIR}/src/StackWalker.h) endif() -if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") - add_flags_cxx("-Wno-error=float-equal") -endif() - source_group("Shared" FILES ${SHARED_SRCS} ${SHARED_HDRS}) source_group("Sources" FILES ${SRCS}) add_executable(BoundingBox-exe ${SRCS} ${SHARED_SRCS} ${SHARED_HDRS}) diff --git a/tests/ChunkData/CMakeLists.txt b/tests/ChunkData/CMakeLists.txt index 9fdcd4650..61cb8e7c6 100644 --- a/tests/ChunkData/CMakeLists.txt +++ b/tests/ChunkData/CMakeLists.txt @@ -1,11 +1,6 @@ enable_testing() include_directories(${CMAKE_SOURCE_DIR}/src/) -if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") - add_flags_cxx("-Wno-error=old-style-cast") - set_source_files_properties(${CMAKE_SOURCE_DIR}/src/ChunkData.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=sign-conversion") - set_source_files_properties(${CMAKE_SOURCE_DIR}/src/StringUtils.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=conversion") -endif() add_definitions(-DTEST_GLOBALS=1) diff --git a/tests/ChunkData/CopyBlocks.cpp b/tests/ChunkData/CopyBlocks.cpp index b76b2d420..8253ac2ec 100644 --- a/tests/ChunkData/CopyBlocks.cpp +++ b/tests/ChunkData/CopyBlocks.cpp @@ -51,7 +51,7 @@ int main(int argc, char ** argv) { if (idx / 500 != LastReportedStep) { - printf("Testing index %u...\n", (unsigned)idx); + printf("Testing index %u...\n", static_cast<unsigned>(idx)); LastReportedStep = idx / 500; } diff --git a/tests/HTTP/CMakeLists.txt b/tests/HTTP/CMakeLists.txt index 04e82caf9..5529ed082 100644 --- a/tests/HTTP/CMakeLists.txt +++ b/tests/HTTP/CMakeLists.txt @@ -1,8 +1,8 @@ enable_testing() include_directories(${CMAKE_SOURCE_DIR}/src/) -include_directories(${CMAKE_SOURCE_DIR}/lib/libevent/include) -include_directories(${CMAKE_SOURCE_DIR}/lib/polarssl/include) +include_directories(SYSTEM ${CMAKE_SOURCE_DIR}/lib/libevent/include) +include_directories(SYSTEM ${CMAKE_SOURCE_DIR}/lib/polarssl/include) add_definitions(-DTEST_GLOBALS=1) @@ -37,9 +37,6 @@ add_library(HTTP ) target_link_libraries(HTTP Network OSSupport) -if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") - add_flags_cxx("-Wno-error=conversion -Wno-error=old-style-cast") -endif() diff --git a/tests/LoadablePieces/CMakeLists.txt b/tests/LoadablePieces/CMakeLists.txt index cebcaba02..6e385846f 100644 --- a/tests/LoadablePieces/CMakeLists.txt +++ b/tests/LoadablePieces/CMakeLists.txt @@ -1,7 +1,7 @@ enable_testing() include_directories(${CMAKE_SOURCE_DIR}/src/) -include_directories(${CMAKE_SOURCE_DIR}/lib/) +include_directories(SYSTEM ${CMAKE_SOURCE_DIR}/lib/) include_directories(${CMAKE_CURRENT_SOURCE_DIR}) add_definitions(-DTEST_GLOBALS=1) @@ -75,7 +75,6 @@ set (SRCS if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") - add_flags_cxx("-Wno-error=conversion -Wno-error=old-style-cast") add_flags_cxx("-Wno-error=global-constructors") add_flags_cxx("-Wno-error=switch-enum") endif() diff --git a/tests/Network/CMakeLists.txt b/tests/Network/CMakeLists.txt index c6c76385e..f3496d276 100644 --- a/tests/Network/CMakeLists.txt +++ b/tests/Network/CMakeLists.txt @@ -1,8 +1,8 @@ enable_testing() include_directories(${CMAKE_SOURCE_DIR}/src/) -include_directories(${CMAKE_SOURCE_DIR}/lib/libevent/include) -include_directories(${CMAKE_SOURCE_DIR}/lib/polarssl/include) +include_directories(SYSTEM ${CMAKE_SOURCE_DIR}/lib/libevent/include) +include_directories(SYSTEM ${CMAKE_SOURCE_DIR}/lib/polarssl/include) add_definitions(-DTEST_GLOBALS=1) @@ -51,12 +51,9 @@ if (MSVC) target_link_libraries(Network ws2_32.lib) endif() -if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") - add_flags_cxx("-Wno-error=conversion -Wno-error=old-style-cast") - if ("${CLANG_VERSION}" VERSION_GREATER 3.5) - add_flags_cxx("-Wno-error=inconsistent-missing-override") - endif() -endif() + + + # Define individual tests: diff --git a/tests/SchematicFileSerializer/CMakeLists.txt b/tests/SchematicFileSerializer/CMakeLists.txt index 4694421fc..792349a9d 100644 --- a/tests/SchematicFileSerializer/CMakeLists.txt +++ b/tests/SchematicFileSerializer/CMakeLists.txt @@ -1,7 +1,7 @@ enable_testing() include_directories(${CMAKE_SOURCE_DIR}/src/) -include_directories(${CMAKE_SOURCE_DIR}/lib/) +include_directories(SYSTEM ${CMAKE_SOURCE_DIR}/lib/) include_directories(${CMAKE_CURRENT_SOURCE_DIR}) add_definitions(-DTEST_GLOBALS=1) @@ -63,9 +63,7 @@ set (SRCS if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") - add_flags_cxx("-Wno-error=conversion -Wno-error=old-style-cast") add_flags_cxx("-Wno-error=global-constructors") - add_flags_cxx("-Wno-error=switch-enum") endif() |