From d51cab2d3bb579b663c1211dfc1e69039165c06f Mon Sep 17 00:00:00 2001 From: Tycho Date: Fri, 7 Mar 2014 11:16:16 -0800 Subject: Turned on Werror --- SetFlags.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SetFlags.cmake b/SetFlags.cmake index 35831e7e9..e6ba782fc 100644 --- a/SetFlags.cmake +++ b/SetFlags.cmake @@ -182,7 +182,7 @@ macro(set_exe_flags) string(REPLACE "-w" "" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}") string(REPLACE "-w" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}") string(REPLACE "-w" "" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}") - add_flags_cxx("-Wall -Wextra -Werror -Wno-error=unused-parameter") + add_flags_cxx("-Wall -Wextra -Werror -Wno-error=unused-parameter -Wno-error=switch") # we support non-IEEE 754 fpus so can make no guarentees about error add_flags_cxx("-ffast-math") -- cgit v1.2.3 From b4e3d0aa4e573200d1fffc3073e791c54d9eb20c Mon Sep 17 00:00:00 2001 From: Tycho Date: Sun, 9 Mar 2014 04:37:36 -0700 Subject: Turned off Wunused-parameter --- SetFlags.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SetFlags.cmake b/SetFlags.cmake index e6ba782fc..4e20c84ab 100644 --- a/SetFlags.cmake +++ b/SetFlags.cmake @@ -182,7 +182,7 @@ macro(set_exe_flags) string(REPLACE "-w" "" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}") string(REPLACE "-w" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}") string(REPLACE "-w" "" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}") - add_flags_cxx("-Wall -Wextra -Werror -Wno-error=unused-parameter -Wno-error=switch") + add_flags_cxx("-Wall -Wextra -Werror -Wno-unused-parameter -Wno-error=switch") # we support non-IEEE 754 fpus so can make no guarentees about error add_flags_cxx("-ffast-math") -- cgit v1.2.3 From 59d42ec5b2c666f1f50c9763dad13e97e2c6040f Mon Sep 17 00:00:00 2001 From: Tycho Date: Sun, 9 Mar 2014 04:58:08 -0700 Subject: Enabled loads of clang warnings --- SetFlags.cmake | 2 ++ 1 file changed, 2 insertions(+) diff --git a/SetFlags.cmake b/SetFlags.cmake index 4e20c84ab..56d32b8fe 100644 --- a/SetFlags.cmake +++ b/SetFlags.cmake @@ -190,6 +190,8 @@ macro(set_exe_flags) # clang does not provide the __extern_always_inline macro and a part of libm depends on this when using fast-math if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") add_flags_cxx("-D__extern_always_inline=inline") + add_flags_cxx("-Weverything -Wno-c++98-compat-pedantic -Wno-string-conversion") + add_flags_cxx("-Wno-extra-semi -Wno-error=switch-enum -Wno-documentation") endif() endif() -- cgit v1.2.3 From c5436e1ae75928f08a411d29a0b28241c3f2b062 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sun, 9 Mar 2014 09:16:15 -0700 Subject: Lots more warnings --- SetFlags.cmake | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/SetFlags.cmake b/SetFlags.cmake index 56d32b8fe..ec2f6c556 100644 --- a/SetFlags.cmake +++ b/SetFlags.cmake @@ -192,6 +192,15 @@ macro(set_exe_flags) add_flags_cxx("-D__extern_always_inline=inline") add_flags_cxx("-Weverything -Wno-c++98-compat-pedantic -Wno-string-conversion") add_flags_cxx("-Wno-extra-semi -Wno-error=switch-enum -Wno-documentation") + add_flags_cxx("-Wno-error=sign-conversion -Wno-error=conversion -Wno-error=padded") + add_flags_cxx("-Wno-error=deprecated -Wno-error=weak-vtables -Wno-error=float-equal") + add_flags_cxx("-Wno-error=missing-prototypes -Wno-error=non-virtual-dtor") + add_flags_cxx("-Wno-error=covered-switch-default -Wno-error=shadow") + add_flags_cxx("-Wno-error=exit-time-destructors -Wno-error=missing-variable-declarations") + add_flags_cxx("-Wno-error=cast-align -Wno-error=unused-macros") + add_flags_cxx("-Wno-error=global-constructors -Wno-implicit-fallthrough") + add_flags_cxx("-Wno-missing-noreturn -Wno-error=unreachable-code -Wno-error=undef") + add_flags_cxx("-Wno-error=format-nonliteral") endif() endif() -- cgit v1.2.3 From f4201e0b825479c6ae8ff3165fc0b7fa949c0006 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sun, 9 Mar 2014 09:25:16 -0700 Subject: Fixed gcc error --- src/WorldStorage/WSSCompact.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/WorldStorage/WSSCompact.cpp b/src/WorldStorage/WSSCompact.cpp index 5e49e4909..4301e1733 100644 --- a/src/WorldStorage/WSSCompact.cpp +++ b/src/WorldStorage/WSSCompact.cpp @@ -39,7 +39,7 @@ struct cWSSCompact::sChunkHeader /// The maximum number of PAK files that are cached -const int MAX_PAK_FILES = 16; +const int MAX_PAK_FILES = 16U; /// The maximum number of unsaved chunks before the cPAKFile saves them to disk const int MAX_DIRTY_CHUNKS = 16; -- cgit v1.2.3 From e73caf30f09248a7e428a937226e0383e69ff6ce Mon Sep 17 00:00:00 2001 From: Tycho Date: Sun, 9 Mar 2014 09:33:40 -0700 Subject: Fix gcc error attempt 2 --- src/WorldStorage/WSSCompact.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/WorldStorage/WSSCompact.cpp b/src/WorldStorage/WSSCompact.cpp index 4301e1733..885099713 100644 --- a/src/WorldStorage/WSSCompact.cpp +++ b/src/WorldStorage/WSSCompact.cpp @@ -39,7 +39,7 @@ struct cWSSCompact::sChunkHeader /// The maximum number of PAK files that are cached -const int MAX_PAK_FILES = 16U; +const int MAX_PAK_FILES = static_cast(16); /// The maximum number of unsaved chunks before the cPAKFile saves them to disk const int MAX_DIRTY_CHUNKS = 16; -- cgit v1.2.3 From ebf163b77a030553c616d19179a9cd0f6de787a6 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sun, 9 Mar 2014 09:45:59 -0700 Subject: Unsigned types take 3 --- src/WorldStorage/WSSCompact.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/WorldStorage/WSSCompact.cpp b/src/WorldStorage/WSSCompact.cpp index 885099713..663260aaa 100644 --- a/src/WorldStorage/WSSCompact.cpp +++ b/src/WorldStorage/WSSCompact.cpp @@ -39,7 +39,7 @@ struct cWSSCompact::sChunkHeader /// The maximum number of PAK files that are cached -const int MAX_PAK_FILES = static_cast(16); +const int MAX_PAK_FILES = static_cast(16); /// The maximum number of unsaved chunks before the cPAKFile saves them to disk const int MAX_DIRTY_CHUNKS = 16; -- cgit v1.2.3 From 167ef3b7a1a1ec23330552decfc7d005ccfc8caa Mon Sep 17 00:00:00 2001 From: Tycho Date: Sun, 9 Mar 2014 09:52:49 -0700 Subject: Take 4 --- src/WorldStorage/WSSCompact.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/WorldStorage/WSSCompact.cpp b/src/WorldStorage/WSSCompact.cpp index 663260aaa..6e39b44cc 100644 --- a/src/WorldStorage/WSSCompact.cpp +++ b/src/WorldStorage/WSSCompact.cpp @@ -39,7 +39,7 @@ struct cWSSCompact::sChunkHeader /// The maximum number of PAK files that are cached -const int MAX_PAK_FILES = static_cast(16); +const int MAX_PAK_FILES = static_cast(16); /// The maximum number of unsaved chunks before the cPAKFile saves them to disk const int MAX_DIRTY_CHUNKS = 16; -- cgit v1.2.3 From 02afa78b681838db5d83378836c88895b6fba237 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sun, 9 Mar 2014 10:04:07 -0700 Subject: Take 5 --- src/WorldStorage/WSSCompact.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/WorldStorage/WSSCompact.cpp b/src/WorldStorage/WSSCompact.cpp index 6e39b44cc..18d4452d9 100644 --- a/src/WorldStorage/WSSCompact.cpp +++ b/src/WorldStorage/WSSCompact.cpp @@ -39,7 +39,7 @@ struct cWSSCompact::sChunkHeader /// The maximum number of PAK files that are cached -const int MAX_PAK_FILES = static_cast(16); +const int MAX_PAK_FILES = static_cast(16); /// The maximum number of unsaved chunks before the cPAKFile saves them to disk const int MAX_DIRTY_CHUNKS = 16; -- cgit v1.2.3 From 430aba9f1dc5db8c3d1ec9f9552bb41f8a0b21b0 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sun, 9 Mar 2014 10:10:36 -0700 Subject: Its a const not a macro --- src/WorldStorage/WSSCompact.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/WorldStorage/WSSCompact.cpp b/src/WorldStorage/WSSCompact.cpp index 18d4452d9..95477838e 100644 --- a/src/WorldStorage/WSSCompact.cpp +++ b/src/WorldStorage/WSSCompact.cpp @@ -39,7 +39,7 @@ struct cWSSCompact::sChunkHeader /// The maximum number of PAK files that are cached -const int MAX_PAK_FILES = static_cast(16); +const size_t MAX_PAK_FILES = 16; /// The maximum number of unsaved chunks before the cPAKFile saves them to disk const int MAX_DIRTY_CHUNKS = 16; -- cgit v1.2.3 From 676dcfd1c74a36882b5b9bb75749e3bd86b75d9e Mon Sep 17 00:00:00 2001 From: Tycho Date: Sun, 9 Mar 2014 10:32:56 -0700 Subject: Globals.h is now warnings free again. Also turned off Wpadded as it is indicates potental performance issues rather than potential bugs --- SetFlags.cmake | 2 +- src/ChunkDef.h | 32 ++++++++++++++++++++++++-------- src/Globals.h | 2 -- 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/SetFlags.cmake b/SetFlags.cmake index ec2f6c556..82472f333 100644 --- a/SetFlags.cmake +++ b/SetFlags.cmake @@ -192,7 +192,7 @@ macro(set_exe_flags) add_flags_cxx("-D__extern_always_inline=inline") add_flags_cxx("-Weverything -Wno-c++98-compat-pedantic -Wno-string-conversion") add_flags_cxx("-Wno-extra-semi -Wno-error=switch-enum -Wno-documentation") - add_flags_cxx("-Wno-error=sign-conversion -Wno-error=conversion -Wno-error=padded") + add_flags_cxx("-Wno-error=sign-conversion -Wno-error=conversion -Wno-padded") add_flags_cxx("-Wno-error=deprecated -Wno-error=weak-vtables -Wno-error=float-equal") add_flags_cxx("-Wno-error=missing-prototypes -Wno-error=non-virtual-dtor") add_flags_cxx("-Wno-error=covered-switch-default -Wno-error=shadow") diff --git a/src/ChunkDef.h b/src/ChunkDef.h index 63431f211..a5059348c 100644 --- a/src/ChunkDef.h +++ b/src/ChunkDef.h @@ -124,7 +124,9 @@ public: (z < Width) && (z > -1) ) { - return MakeIndexNoCheck(x, y, z); + return MakeIndexNoCheck(static_cast(x), + static_cast(y), + static_cast(z)); } LOGERROR("cChunkDef::MakeIndex(): coords out of range: {%d, %d, %d}; returning fake index 0", x, y, z); ASSERT(!"cChunkDef::MakeIndex(): coords out of chunk range!"); @@ -166,7 +168,9 @@ public: ASSERT((a_X >= 0) && (a_X < Width)); ASSERT((a_Y >= 0) && (a_Y < Height)); ASSERT((a_Z >= 0) && (a_Z < Width)); - a_BlockTypes[MakeIndexNoCheck(a_X, a_Y, a_Z)] = a_Type; + a_BlockTypes[MakeIndexNoCheck(static_cast(a_X), + static_cast(a_Y), + static_cast(a_Z))] = a_Type; } @@ -182,7 +186,9 @@ public: ASSERT((a_X >= 0) && (a_X < Width)); ASSERT((a_Y >= 0) && (a_Y < Height)); ASSERT((a_Z >= 0) && (a_Z < Width)); - return a_BlockTypes[MakeIndexNoCheck(a_X, a_Y, a_Z)]; + return a_BlockTypes[MakeIndexNoCheck(static_cast(a_X), + static_cast(a_Y), + static_cast(a_Z))]; } @@ -240,7 +246,9 @@ public: { if ((x < Width) && (x > -1) && (y < Height) && (y > -1) && (z < Width) && (z > -1)) { - unsigned int Index = MakeIndexNoCheck(x, y, z); + unsigned int Index = MakeIndexNoCheck(static_cast(x), + static_cast(y), + static_cast(z)); return (a_Buffer[Index / 2] >> ((Index & 1) * 4)) & 0x0f; } ASSERT(!"cChunkDef::GetNibble(): coords out of chunk range!"); @@ -255,8 +263,8 @@ public: ASSERT(!"cChunkDef::SetNibble(): index out of range!"); return; } - a_Buffer[a_BlockIdx / 2] = ( - (a_Buffer[a_BlockIdx / 2] & (0xf0 >> (static_cast(a_BlockIdx & 1) * 4))) | // The untouched nibble + a_Buffer[a_BlockIdx / 2] = static_cast( + (a_Buffer[a_BlockIdx / 2] & (0xf0 >> ((a_BlockIdx & 1) * 4))) | // The untouched nibble ((a_Nibble & 0x0f) << ((a_BlockIdx & 1) * 4)) // The nibble being set ); } @@ -274,8 +282,10 @@ public: return; } - int Index = MakeIndexNoCheck(x, y, z); - a_Buffer[Index / 2] = ( + unsigned int Index = MakeIndexNoCheck(static_cast(x), + static_cast(y), + static_cast(z)); + a_Buffer[Index / 2] = static_cast( (a_Buffer[Index / 2] & (0xf0 >> ((Index & 1) * 4))) | // The untouched nibble ((a_Nibble & 0x0f) << ((Index & 1) * 4)) // The nibble being set ); @@ -435,6 +445,9 @@ Used primarily for entity moving while both chunks are locked. class cClientDiffCallback { public: + + virtual ~cClientDiffCallback() {} + /// Called for clients that are in Chunk1 and not in Chunk2, virtual void Removed(cClientHandle * a_Client) = 0; @@ -495,6 +508,9 @@ typedef std::vector cChunkCoordsVector; class cChunkCoordCallback { public: + + virtual ~cChunkCoordCallback() {} + virtual void Call(int a_ChunkX, int a_ChunkZ) = 0; } ; diff --git a/src/Globals.h b/src/Globals.h index 28805a83f..98611fc55 100644 --- a/src/Globals.h +++ b/src/Globals.h @@ -254,5 +254,3 @@ T Clamp(T a_Value, T a_Min, T a_Max) #include "Entities/Effects.h" - - -- cgit v1.2.3 From 713c59b60b6a096554eda7fabc7696b33a6fcb59 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sun, 9 Mar 2014 10:41:53 -0700 Subject: Treat enum missmatches as warnings for now as there is such a large number of them. --- SetFlags.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SetFlags.cmake b/SetFlags.cmake index 82472f333..e71bf315d 100644 --- a/SetFlags.cmake +++ b/SetFlags.cmake @@ -182,7 +182,7 @@ macro(set_exe_flags) string(REPLACE "-w" "" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}") string(REPLACE "-w" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}") string(REPLACE "-w" "" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}") - add_flags_cxx("-Wall -Wextra -Werror -Wno-unused-parameter -Wno-error=switch") + add_flags_cxx("-Wall -Wextra -Werror -Wno-unused-parameter -Wno-error=switch -Wno-error=enum-compare") # we support non-IEEE 754 fpus so can make no guarentees about error add_flags_cxx("-ffast-math") -- cgit v1.2.3 From 617ad0b5f8e8d469ec017a0e83754f7401f64d00 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sun, 9 Mar 2014 10:46:39 -0700 Subject: Only enable -Werror in gcc because gcc doesn't let you suppress enum missmatch warnings --- SetFlags.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SetFlags.cmake b/SetFlags.cmake index e71bf315d..a9657fff1 100644 --- a/SetFlags.cmake +++ b/SetFlags.cmake @@ -182,7 +182,7 @@ macro(set_exe_flags) string(REPLACE "-w" "" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}") string(REPLACE "-w" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}") string(REPLACE "-w" "" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}") - add_flags_cxx("-Wall -Wextra -Werror -Wno-unused-parameter -Wno-error=switch -Wno-error=enum-compare") + add_flags_cxx("-Wall -Wextra -Wno-unused-parameter -Wno-error=switch") # we support non-IEEE 754 fpus so can make no guarentees about error add_flags_cxx("-ffast-math") @@ -190,7 +190,7 @@ macro(set_exe_flags) # clang does not provide the __extern_always_inline macro and a part of libm depends on this when using fast-math if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") add_flags_cxx("-D__extern_always_inline=inline") - add_flags_cxx("-Weverything -Wno-c++98-compat-pedantic -Wno-string-conversion") + add_flags_cxx("-Werror -Weverything -Wno-c++98-compat-pedantic -Wno-string-conversion") add_flags_cxx("-Wno-extra-semi -Wno-error=switch-enum -Wno-documentation") add_flags_cxx("-Wno-error=sign-conversion -Wno-error=conversion -Wno-padded") add_flags_cxx("-Wno-error=deprecated -Wno-error=weak-vtables -Wno-error=float-equal") -- cgit v1.2.3 From e5fc3c63f2ab4bcc8d225f746afd07d01ad9d08c Mon Sep 17 00:00:00 2001 From: Tycho Date: Sun, 9 Mar 2014 10:52:12 -0700 Subject: Fix IsThread destructor --- src/OSSupport/IsThread.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OSSupport/IsThread.h b/src/OSSupport/IsThread.h index b8784ea33..42b8bfdda 100644 --- a/src/OSSupport/IsThread.h +++ b/src/OSSupport/IsThread.h @@ -34,7 +34,7 @@ protected: public: cIsThread(const AString & iThreadName); - ~cIsThread(); + virtual ~cIsThread(); /// Starts the thread; returns without waiting for the actual start bool Start(void); -- cgit v1.2.3 From 9825dbfd34c65580d795065d1a82e7697b9c5cbd Mon Sep 17 00:00:00 2001 From: Tycho Date: Sun, 9 Mar 2014 11:21:42 -0700 Subject: Fixed Mesannine twister to use UInt32 --- MCServer/Plugins/Core | 2 +- src/ByteBuffer.h | 2 +- src/Defines.h | 2 +- src/Map.h | 2 +- src/MersenneTwister.h | 4 +++- 5 files changed, 7 insertions(+), 5 deletions(-) diff --git a/MCServer/Plugins/Core b/MCServer/Plugins/Core index 013a32a7f..3b416b07a 160000 --- a/MCServer/Plugins/Core +++ b/MCServer/Plugins/Core @@ -1 +1 @@ -Subproject commit 013a32a7fb3c8a6cfe0aef892d4c7394d4e1be59 +Subproject commit 3b416b07a339b3abcbc127070d56eea05b05373d diff --git a/src/ByteBuffer.h b/src/ByteBuffer.h index ed2e10a55..1915467f3 100644 --- a/src/ByteBuffer.h +++ b/src/ByteBuffer.h @@ -43,7 +43,7 @@ public: size_t GetReadableSpace(void) const; /// Returns the current data start index. For debugging purposes. - int GetDataStart(void) const { return m_DataStart; } + size_t GetDataStart(void) const { return m_DataStart; } /// Returns true if the specified amount of bytes are available for reading bool CanReadBytes(size_t a_Count) const; diff --git a/src/Defines.h b/src/Defines.h index 6ab2274a4..fd240c91a 100644 --- a/src/Defines.h +++ b/src/Defines.h @@ -469,7 +469,7 @@ inline void EulerToVector(double a_Pan, double a_Pitch, double & a_X, double & a inline void VectorToEuler(double a_X, double a_Y, double a_Z, double & a_Pan, double & a_Pitch) { - if (a_X != 0) + if (fabs(a_X) < std::numeric_limits::epsilon() ) { a_Pan = atan2(a_Z, a_X) * 180 / PI - 90; } diff --git a/src/Map.h b/src/Map.h index a313d5431..ee7c537b1 100644 --- a/src/Map.h +++ b/src/Map.h @@ -64,7 +64,7 @@ public: unsigned int GetPixelX(void) const { return m_PixelX; } unsigned int GetPixelZ(void) const { return m_PixelZ; } - int GetRot(void) const { return m_Rot; } + unsigned int GetRot(void) const { return m_Rot; } eType GetType(void) const { return m_Type; } diff --git a/src/MersenneTwister.h b/src/MersenneTwister.h index f4c7b0699..07b6b1e5c 100644 --- a/src/MersenneTwister.h +++ b/src/MersenneTwister.h @@ -59,10 +59,12 @@ #include #include +#include "Globals.h" + class MTRand { // Data public: - typedef long uint32; // unsigned integer type, at least 32 bits + typedef UInt32 uint32; // unsigned integer type, at least 32 bits enum { N = 624 }; // length of state vector enum { SAVE = N + 1 }; // length of array for save() -- cgit v1.2.3 From 1bf99b5fd26d142106d7a097900ebfe8a6279ad4 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sun, 9 Mar 2014 11:47:22 -0700 Subject: Be more parinoid about int sizes --- src/Defines.h | 3 ++- src/Globals.h | 18 ++++++++++++++++-- src/MersenneTwister.h | 2 -- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/Defines.h b/src/Defines.h index fd240c91a..592b9434a 100644 --- a/src/Defines.h +++ b/src/Defines.h @@ -2,6 +2,7 @@ #pragma once #include "ChatColor.h" +#include @@ -469,7 +470,7 @@ inline void EulerToVector(double a_Pan, double a_Pitch, double & a_X, double & a inline void VectorToEuler(double a_X, double a_Y, double a_Z, double & a_Pan, double & a_Pitch) { - if (fabs(a_X) < std::numeric_limits::epsilon() ) + if (fabs(a_X) < std::numeric_limits::epsilon()) { a_Pan = atan2(a_Z, a_X) * 180 / PI - 90; } diff --git a/src/Globals.h b/src/Globals.h index 98611fc55..b046e6db0 100644 --- a/src/Globals.h +++ b/src/Globals.h @@ -81,7 +81,7 @@ #endif - +#include // Integral types with predefined sizes: @@ -96,8 +96,22 @@ typedef unsigned short UInt16; typedef unsigned char Byte; +// If you get an error about specialization check the size of integral types +template +class SizeChecker; + +template +class SizeChecker { + T v; +}; +template class SizeChecker; +template class SizeChecker; +template class SizeChecker; +template class SizeChecker; +template class SizeChecker; +template class SizeChecker; // A macro to disallow the copy constructor and operator= functions // This should be used in the private: declarations for any class that shouldn't allow copying itself @@ -179,7 +193,7 @@ typedef unsigned char Byte; #include #include #include - +#include diff --git a/src/MersenneTwister.h b/src/MersenneTwister.h index 07b6b1e5c..2c5440f17 100644 --- a/src/MersenneTwister.h +++ b/src/MersenneTwister.h @@ -59,8 +59,6 @@ #include #include -#include "Globals.h" - class MTRand { // Data public: -- cgit v1.2.3 From 30353cd2285d8d2e9ec38c1015c7d45dbdb82b39 Mon Sep 17 00:00:00 2001 From: Tycho Date: Mon, 10 Mar 2014 10:24:44 -0700 Subject: Fixed MTRand warnings --- src/MersenneTwister.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/MersenneTwister.h b/src/MersenneTwister.h index 2c5440f17..759b8a1ae 100644 --- a/src/MersenneTwister.h +++ b/src/MersenneTwister.h @@ -72,7 +72,7 @@ protected: uint32 state[N]; // internal state uint32 *pNext; // next value to get from state - int left; // number of values left before reload needed + uint32 left; // number of values left before reload needed // Methods public: @@ -164,7 +164,7 @@ inline void MTRand::initialize( const uint32 seed ) // only MSBs of the state array. Modified 9 Jan 2002 by Makoto Matsumoto. uint32 *s = state; uint32 *r = state; - int i = 1; + uint32 i = 1; *s++ = seed & 0xffffffffUL; for( ; i < N; ++i ) { @@ -205,9 +205,9 @@ inline void MTRand::seed( uint32 *const bigSeed, const uint32 seedLength ) // in each element are discarded. // Just call seed() if you want to get array from /dev/urandom initialize(19650218UL); - int i = 1; + uint32 i = 1; uint32 j = 0; - int k = ( (uint32)N > seedLength ? (uint32)N : seedLength ); + uint32 k = ( (uint32)N > seedLength ? (uint32)N : seedLength ); for( ; k; --k ) { state[i] = -- cgit v1.2.3 From 8665233522da3454a77c4c40ace03d3a61150023 Mon Sep 17 00:00:00 2001 From: Tycho Date: Mon, 10 Mar 2014 10:32:51 -0700 Subject: Fixed cast between types of different alignment in cSocket --- src/OSSupport/Socket.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/OSSupport/Socket.cpp b/src/OSSupport/Socket.cpp index 6afaceedf..c29e495c3 100644 --- a/src/OSSupport/Socket.cpp +++ b/src/OSSupport/Socket.cpp @@ -307,7 +307,8 @@ bool cSocket::ConnectIPv4(const AString & a_HostNameOrAddr, unsigned short a_Por CloseSocket(); return false; } - addr = *((unsigned long*)hp->h_addr); + // Should be optimised to a single word copy + memcpy(&addr, hp->h_addr, hp->h_length); } sockaddr_in server; -- cgit v1.2.3 From e2e7f2184f09562753be1a474c2d7e8273b1e83b Mon Sep 17 00:00:00 2001 From: Tycho Date: Mon, 10 Mar 2014 10:38:21 -0700 Subject: Fixed cast to type with different alignment in BlockingTCPLink --- src/OSSupport/BlockingTCPLink.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OSSupport/BlockingTCPLink.cpp b/src/OSSupport/BlockingTCPLink.cpp index e9c00d6d4..07f48b955 100644 --- a/src/OSSupport/BlockingTCPLink.cpp +++ b/src/OSSupport/BlockingTCPLink.cpp @@ -70,7 +70,7 @@ bool cBlockingTCPLink::Connect(const char * iAddress, unsigned int iPort) } } - server.sin_addr.s_addr = *((unsigned long *)hp->h_addr); + memcpy(&server.sin_addr.s_addr,hp->h_addr, hp->h_length); server.sin_family = AF_INET; server.sin_port = htons( (unsigned short)iPort); if (connect(m_Socket, (struct sockaddr *)&server, sizeof(server))) -- cgit v1.2.3 From 7c974b27b1c334da3cd83769398fa9104a2e3253 Mon Sep 17 00:00:00 2001 From: Tycho Date: Mon, 10 Mar 2014 10:42:52 -0700 Subject: Removed unused macro --- src/Protocol/Protocol125.cpp | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/src/Protocol/Protocol125.cpp b/src/Protocol/Protocol125.cpp index 50ebb6d43..69f4934d8 100644 --- a/src/Protocol/Protocol125.cpp +++ b/src/Protocol/Protocol125.cpp @@ -1269,19 +1269,6 @@ int cProtocol125::ParsePacket(unsigned char a_PacketType) -#define HANDLE_PACKET_PARSE(Packet) \ - { \ - int res = Packet.Parse(m_ReceivedData); \ - if (res < 0) \ - { \ - return res; \ - } \ - } - - - - - int cProtocol125::ParseArmAnim(void) { HANDLE_PACKET_READ(ReadBEInt, int, EntityID); -- cgit v1.2.3 From 8864e7d8ca63c972793234d3c65aa534fdec06ad Mon Sep 17 00:00:00 2001 From: Tycho Date: Mon, 10 Mar 2014 11:13:07 -0700 Subject: Fixed alignment issues in Fireworks Serializer --- src/WorldStorage/FireworksSerializer.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/WorldStorage/FireworksSerializer.cpp b/src/WorldStorage/FireworksSerializer.cpp index 1f05b470d..bdd5952ad 100644 --- a/src/WorldStorage/FireworksSerializer.cpp +++ b/src/WorldStorage/FireworksSerializer.cpp @@ -90,16 +90,16 @@ void cFireworkItem::ParseFromNBT(cFireworkItem & a_FireworkItem, const cParsedNB if (ExplosionName == "Colors") { // Divide by four as data length returned in bytes - int DataLength = a_NBT.GetDataLength(explosiontag) / 4; + int DataLength = a_NBT.GetDataLength(explosiontag); if (DataLength == 0) { continue; } - const int * ColourData = (const int *)(a_NBT.GetData(explosiontag)); - for (int i = 0; i < DataLength; i++) + const char * ColourData = (a_NBT.GetData(explosiontag)); + for (int i = 0; i < DataLength; i += 4 /* Size of network int*/) { - a_FireworkItem.m_Colours.push_back(ntohl(ColourData[i])); + a_FireworkItem.m_Colours.push_back(GetBEInt(ColourData + i)); } } else if (ExplosionName == "FadeColors") @@ -110,10 +110,10 @@ void cFireworkItem::ParseFromNBT(cFireworkItem & a_FireworkItem, const cParsedNB continue; } - const int * FadeColourData = (const int *)(a_NBT.GetData(explosiontag)); - for (int i = 0; i < DataLength; i++) + const char * FadeColourData = (a_NBT.GetData(explosiontag)); + for (int i = 0; i < DataLength; i += 4 /* Size of network int*/) { - a_FireworkItem.m_FadeColours.push_back(ntohl(FadeColourData[i])); + a_FireworkItem.m_FadeColours.push_back(GetBEInt(FadeColourData + i)); } } } -- cgit v1.2.3 From cff66315137e90db1292fa01640aae2e2d23b862 Mon Sep 17 00:00:00 2001 From: Tycho Date: Mon, 10 Mar 2014 11:14:34 -0700 Subject: Removed unused macro from WSSCompact --- src/WorldStorage/WSSCompact.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/WorldStorage/WSSCompact.cpp b/src/WorldStorage/WSSCompact.cpp index 95477838e..1e84fb4ad 100644 --- a/src/WorldStorage/WSSCompact.cpp +++ b/src/WorldStorage/WSSCompact.cpp @@ -764,7 +764,6 @@ void cWSSCompact::cPAKFile::UpdateChunk2To3() // Cannot use cChunk::MakeIndex because it might change again????????? // For compatibility, use what we know is current - #define MAKE_2_INDEX( x, y, z ) ( y + (z * 256) + (x * 256 * 16) ) #define MAKE_3_INDEX( x, y, z ) ( x + (z * 16) + (y * 16 * 16) ) unsigned int InChunkOffset = 0; -- cgit v1.2.3 From 8947f802940213d371863710e1c3ac873b2dc4b9 Mon Sep 17 00:00:00 2001 From: Tycho Date: Mon, 10 Mar 2014 11:24:12 -0700 Subject: Use string.reserve to avoid the need to do inplace byteswap --- src/WorldStorage/FastNBT.cpp | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/WorldStorage/FastNBT.cpp b/src/WorldStorage/FastNBT.cpp index 8f80c3f75..f1f092e0b 100644 --- a/src/WorldStorage/FastNBT.cpp +++ b/src/WorldStorage/FastNBT.cpp @@ -506,22 +506,18 @@ void cFastNBTWriter::AddIntArray(const AString & a_Name, const int * a_Value, si { TagCommon(a_Name, TAG_IntArray); Int32 len = htonl(a_NumElements); + size_t cap = m_Result.capacity(); + size_t size = m_Result.length(); + if ((cap - size) < (4 + a_NumElements * 4)) + { + m_Result.reserve(size +4 + a_NumElements * 4); + } m_Result.append((const char *)&len, 4); -#if defined(ANDROID_NDK) - // Android has alignment issues - cannot byteswap (htonl) an int that is not 32-bit-aligned, which happens in the regular version for (size_t i = 0; i < a_NumElements; i++) { int Element = htonl(a_Value[i]); m_Result.append((const char *)&Element, 4); } -#else - int * Elements = (int *)(m_Result.data() + m_Result.size()); - m_Result.append(a_NumElements * 4, (char)0); - for (size_t i = 0; i < a_NumElements; i++) - { - Elements[i] = htonl(a_Value[i]); - } -#endif } -- cgit v1.2.3 From 2eca30aebc9a4f7307c31a75ca23e19fa3f1a4a7 Mon Sep 17 00:00:00 2001 From: Tycho Date: Mon, 10 Mar 2014 11:34:20 -0700 Subject: Removed Some unnessicary macros --- src/ClientHandle.cpp | 13 ------------- src/LightingThread.cpp | 6 ------ src/WorldStorage/WSSAnvil.cpp | 4 ++-- 3 files changed, 2 insertions(+), 21 deletions(-) diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 94c9f5f71..df728e83b 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -36,19 +36,6 @@ - - -#define AddPistonDir(x, y, z, dir, amount) switch (dir) { case 0: (y)-=(amount); break; case 1: (y)+=(amount); break;\ - case 2: (z)-=(amount); break; case 3: (z)+=(amount); break;\ - case 4: (x)-=(amount); break; case 5: (x)+=(amount); break; } - - - - - -/** If the number of queued outgoing packets reaches this, the client will be kicked */ -#define MAX_OUTGOING_PACKETS 2000 - /** Maximum number of explosions to send this tick, server will start dropping if exceeded */ #define MAX_EXPLOSIONS_PER_TICK 20 diff --git a/src/LightingThread.cpp b/src/LightingThread.cpp index 44dadb8a9..302473d71 100644 --- a/src/LightingThread.cpp +++ b/src/LightingThread.cpp @@ -13,12 +13,6 @@ -/// If more than this many chunks are in the queue, a warning is printed to the log -#define WARN_ON_QUEUE_SIZE 800 - - - - /// Chunk data callback that takes the chunk data and puts them into cLightingThread's m_BlockTypes[] / m_HeightMap[]: class cReader : diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp index eb159f28d..070738164 100644 --- a/src/WorldStorage/WSSAnvil.cpp +++ b/src/WorldStorage/WSSAnvil.cpp @@ -507,10 +507,10 @@ cChunkDef::BiomeMap * cWSSAnvil::LoadBiomeMapFromNBT(cChunkDef::BiomeMap * a_Bio // The biomes stored don't match in size return NULL; } - const int * BiomeData = (const int *)(a_NBT.GetData(a_TagIdx)); + const char * BiomeData = (a_NBT.GetData(a_TagIdx)); for (size_t i = 0; i < ARRAYCOUNT(*a_BiomeMap); i++) { - (*a_BiomeMap)[i] = (EMCSBiome)(ntohl(BiomeData[i])); + (*a_BiomeMap)[i] = (EMCSBiome)(GetBEInt(&BiomeData[i * 4])); if ((*a_BiomeMap)[i] == 0xff) { // Unassigned biomes -- cgit v1.2.3 From b78c729880705c1bf28f266b087046c4eaed8317 Mon Sep 17 00:00:00 2001 From: Tycho Date: Mon, 10 Mar 2014 11:56:23 -0700 Subject: Fixed Alignment issue in ByteBuffer --- src/ByteBuffer.cpp | 2 +- src/StringUtils.cpp | 7 ++----- src/StringUtils.h | 2 +- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/ByteBuffer.cpp b/src/ByteBuffer.cpp index 96a135562..a7553786e 100644 --- a/src/ByteBuffer.cpp +++ b/src/ByteBuffer.cpp @@ -767,7 +767,7 @@ bool cByteBuffer::ReadUTF16String(AString & a_String, int a_NumChars) { return false; } - RawBEToUTF8((short *)(RawData.data()), a_NumChars, a_String); + RawBEToUTF8((RawData.data()), a_NumChars, a_String); return true; } diff --git a/src/StringUtils.cpp b/src/StringUtils.cpp index 3fe75d611..3e047fb5c 100644 --- a/src/StringUtils.cpp +++ b/src/StringUtils.cpp @@ -288,13 +288,13 @@ void ReplaceString(AString & iHayStack, const AString & iNeedle, const AString & // Converts a stream of BE shorts into UTF-8 string; returns a ref to a_UTF8 -AString & RawBEToUTF8(short * a_RawData, int a_NumShorts, AString & a_UTF8) +AString & RawBEToUTF8(const char * a_RawData, int a_NumShorts, AString & a_UTF8) { a_UTF8.clear(); a_UTF8.reserve(3 * a_NumShorts / 2); // a quick guess of the resulting size for (int i = 0; i < a_NumShorts; i++) { - int c = ntohs(*(a_RawData + i)); + int c = GetBEShort(a_RawData + i*2); if (c < 0x80) { a_UTF8.push_back((char)c); @@ -364,10 +364,7 @@ Notice from the original file: #define UNI_MAX_BMP 0x0000FFFF #define UNI_MAX_UTF16 0x0010FFFF -#define UNI_MAX_UTF32 0x7FFFFFFF -#define UNI_MAX_LEGAL_UTF32 0x0010FFFF #define UNI_SUR_HIGH_START 0xD800 -#define UNI_SUR_HIGH_END 0xDBFF #define UNI_SUR_LOW_START 0xDC00 #define UNI_SUR_LOW_END 0xDFFF diff --git a/src/StringUtils.h b/src/StringUtils.h index dfbfc2a75..b64108409 100644 --- a/src/StringUtils.h +++ b/src/StringUtils.h @@ -58,7 +58,7 @@ extern unsigned int RateCompareString(const AString & s1, const AString & s2 ); extern void ReplaceString(AString & iHayStack, const AString & iNeedle, const AString & iReplaceWith); // tolua_export /// Converts a stream of BE shorts into UTF-8 string; returns a ref to a_UTF8 -extern AString & RawBEToUTF8(short * a_RawData, int a_NumShorts, AString & a_UTF8); +extern AString & RawBEToUTF8(const char * a_RawData, int a_NumShorts, AString & a_UTF8); /// Converts a UTF-8 string into a UTF-16 BE string, packing that back into AString; return a ref to a_UTF16 extern AString & UTF8ToRawBEUTF16(const char * a_UTF8, size_t a_UTF8Length, AString & a_UTF16); -- cgit v1.2.3 From 693734bd8307f3089368cb3aca662641f92f2e71 Mon Sep 17 00:00:00 2001 From: Tycho Date: Mon, 10 Mar 2014 11:57:04 -0700 Subject: Enable error on cast-align and unused macros --- SetFlags.cmake | 1 - 1 file changed, 1 deletion(-) diff --git a/SetFlags.cmake b/SetFlags.cmake index a9657fff1..d9308f603 100644 --- a/SetFlags.cmake +++ b/SetFlags.cmake @@ -197,7 +197,6 @@ macro(set_exe_flags) add_flags_cxx("-Wno-error=missing-prototypes -Wno-error=non-virtual-dtor") add_flags_cxx("-Wno-error=covered-switch-default -Wno-error=shadow") add_flags_cxx("-Wno-error=exit-time-destructors -Wno-error=missing-variable-declarations") - add_flags_cxx("-Wno-error=cast-align -Wno-error=unused-macros") add_flags_cxx("-Wno-error=global-constructors -Wno-implicit-fallthrough") add_flags_cxx("-Wno-missing-noreturn -Wno-error=unreachable-code -Wno-error=undef") add_flags_cxx("-Wno-error=format-nonliteral") -- cgit v1.2.3 From bc556e7f00ee28198b5ba3e46c1c06caab8fc37b Mon Sep 17 00:00:00 2001 From: Tycho Date: Mon, 10 Mar 2014 12:21:18 -0700 Subject: Fixed Issues in ProtoProxy --- Tools/ProtoProxy/Connection.cpp | 16 ++++++++-------- Tools/ProtoProxy/Connection.h | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Tools/ProtoProxy/Connection.cpp b/Tools/ProtoProxy/Connection.cpp index 91d2fc42f..be908f303 100644 --- a/Tools/ProtoProxy/Connection.cpp +++ b/Tools/ProtoProxy/Connection.cpp @@ -131,8 +131,6 @@ } \ } - -#define MAX_ENC_LEN 1024 @@ -473,14 +471,14 @@ bool cConnection::SendData(SOCKET a_Socket, cByteBuffer & a_Data, const char * a -bool cConnection::SendEncryptedData(SOCKET a_Socket, cAESCFBEncryptor & a_Encryptor, const char * a_Data, int a_Size, const char * a_Peer) +bool cConnection::SendEncryptedData(SOCKET a_Socket, cAESCFBEncryptor & 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; while (a_Size > 0) { Byte Buffer[64 KiB]; - int NumBytes = (a_Size > sizeof(Buffer)) ? sizeof(Buffer) : a_Size; + 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); if (!res) @@ -2263,7 +2261,9 @@ bool cConnection::HandleServerSpawnObjectVehicle(void) HANDLE_SERVER_PACKET_READ(ReadByte, Byte, Yaw); HANDLE_SERVER_PACKET_READ(ReadBEInt, int, DataIndicator); AString ExtraData; - short VelocityX, VelocityY, VelocityZ; + short VelocityX = 0; + short VelocityY = 0; + short VelocityZ = 0; if (DataIndicator != 0) { HANDLE_SERVER_PACKET_READ(ReadBEShort, short, SpeedX); @@ -2697,7 +2697,7 @@ bool cConnection::ParseMetadata(cByteBuffer & a_Buffer, AString & a_Metadata) a_Metadata.push_back(x); while (x != 0x7f) { - int Index = ((unsigned)((unsigned char)x)) & 0x1f; // Lower 5 bits = index + //int Index = ((unsigned)((unsigned char)x)) & 0x1f; // Lower 5 bits = index int Type = ((unsigned)((unsigned char)x)) >> 5; // Upper 3 bits = type int Length = 0; switch (Type) @@ -2772,7 +2772,7 @@ void cConnection::LogMetadata(const AString & a_Metadata, size_t a_IndentCount) { int Index = ((unsigned)((unsigned char)a_Metadata[pos])) & 0x1f; // Lower 5 bits = index int Type = ((unsigned)((unsigned char)a_Metadata[pos])) >> 5; // Upper 3 bits = type - int Length = 0; + //int Length = 0; switch (Type) { case 0: @@ -2827,7 +2827,7 @@ void cConnection::LogMetadata(const AString & a_Metadata, size_t a_IndentCount) ASSERT(!"Cannot parse item description from metadata"); return; } - int After = bb.GetReadableSpace(); + //int After = bb.GetReadableSpace(); int BytesConsumed = BytesLeft - bb.GetReadableSpace(); Log("%sslot[%d] = %s (%d bytes)", Indent.c_str(), Index, ItemDesc.c_str(), BytesConsumed); diff --git a/Tools/ProtoProxy/Connection.h b/Tools/ProtoProxy/Connection.h index 5e4f8cd7b..70b759d0f 100644 --- a/Tools/ProtoProxy/Connection.h +++ b/Tools/ProtoProxy/Connection.h @@ -109,7 +109,7 @@ protected: bool SendData(SOCKET a_Socket, cByteBuffer & a_Data, const char * a_Peer); /// Sends data to the specfied socket, after encrypting it using a_Encryptor. If sending fails, prints a fail message using a_Peer and returns false - bool SendEncryptedData(SOCKET a_Socket, cAESCFBEncryptor & a_Encryptor, const char * a_Data, int a_Size, const char * a_Peer); + bool SendEncryptedData(SOCKET a_Socket, cAESCFBEncryptor & a_Encryptor, const char * a_Data, size_t a_Size, const char * a_Peer); /// Sends data to the specfied socket, after encrypting it using a_Encryptor. If sending fails, prints a fail message using a_Peer and returns false bool SendEncryptedData(SOCKET a_Socket, cAESCFBEncryptor & a_Encryptor, cByteBuffer & a_Data, const char * a_Peer); -- cgit v1.2.3 From bb28f0d1e3fa685791433220d0bf96bda6d4937e Mon Sep 17 00:00:00 2001 From: Tycho Date: Mon, 10 Mar 2014 12:36:01 -0700 Subject: Fixed assert --- src/ByteBuffer.cpp | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/src/ByteBuffer.cpp b/src/ByteBuffer.cpp index a7553786e..ae4e72737 100644 --- a/src/ByteBuffer.cpp +++ b/src/ByteBuffer.cpp @@ -46,6 +46,9 @@ #ifdef SELF_TEST +#define assert_test(x) ( !!(x) || \ + LOGERROR("Assertion failed: %s, file %s, line %i", #x, __FILE__, __LINE__ ), abort(1)) + /// Self-test of the VarInt-reading and writing code static class cByteBufferSelfTest { @@ -62,11 +65,11 @@ public: cByteBuffer buf(50); buf.Write("\x05\xac\x02\x00", 4); UInt32 v1; - assert(buf.ReadVarInt(v1) && (v1 == 5)); + assert_test(buf.ReadVarInt(v1) && (v1 == 5)); UInt32 v2; - assert(buf.ReadVarInt(v2) && (v2 == 300)); + assert_test(buf.ReadVarInt(v2) && (v2 == 300)); UInt32 v3; - assert(buf.ReadVarInt(v3) && (v3 == 0)); + assert_test(buf.ReadVarInt(v3) && (v3 == 0)); } void TestWrite(void) @@ -77,8 +80,8 @@ public: buf.WriteVarInt(0); AString All; buf.ReadAll(All); - assert(All.size() == 4); - assert(memcmp(All.data(), "\x05\xac\x02\x00", All.size()) == 0); + assert_test(All.size() == 4); + assert_test(memcmp(All.data(), "\x05\xac\x02\x00", All.size()) == 0); } void TestWrap(void) @@ -87,17 +90,17 @@ public: for (int i = 0; i < 1000; i++) { size_t FreeSpace = buf.GetFreeSpace(); - assert(buf.GetReadableSpace() == 0); - assert(FreeSpace > 0); - assert(buf.Write("a", 1)); - assert(buf.CanReadBytes(1)); - assert(buf.GetReadableSpace() == 1); + assert_test(buf.GetReadableSpace() == 0); + assert_test(FreeSpace > 0); + assert_test(buf.Write("a", 1)); + assert_test(buf.CanReadBytes(1)); + assert_test(buf.GetReadableSpace() == 1); unsigned char v = 0; - assert(buf.ReadByte(v)); - assert(v == 'a'); - assert(buf.GetReadableSpace() == 0); + assert_test(buf.ReadByte(v)); + assert_test(v == 'a'); + assert_test(buf.GetReadableSpace() == 0); buf.CommitRead(); - assert(buf.GetFreeSpace() == FreeSpace); // We're back to normal + assert_test(buf.GetFreeSpace() == FreeSpace); // We're back to normal } } -- cgit v1.2.3 From e9e2852ce1d7b3cdbbcc115d63f1d4d0ab25457f Mon Sep 17 00:00:00 2001 From: Tycho Date: Mon, 10 Mar 2014 13:12:43 -0700 Subject: Fixed test asserts --- src/ByteBuffer.cpp | 3 --- src/CompositeChat.cpp | 62 ++++++++++++++++++++++++------------------------- src/CraftingRecipes.cpp | 2 ++ src/Globals.h | 7 +++--- 4 files changed, 37 insertions(+), 37 deletions(-) diff --git a/src/ByteBuffer.cpp b/src/ByteBuffer.cpp index ae4e72737..9d97d8614 100644 --- a/src/ByteBuffer.cpp +++ b/src/ByteBuffer.cpp @@ -46,9 +46,6 @@ #ifdef SELF_TEST -#define assert_test(x) ( !!(x) || \ - LOGERROR("Assertion failed: %s, file %s, line %i", #x, __FILE__, __LINE__ ), abort(1)) - /// Self-test of the VarInt-reading and writing code static class cByteBufferSelfTest { diff --git a/src/CompositeChat.cpp b/src/CompositeChat.cpp index 3eec35657..19ed30d78 100644 --- a/src/CompositeChat.cpp +++ b/src/CompositeChat.cpp @@ -32,15 +32,15 @@ public: cCompositeChat Msg; Msg.ParseText("Testing @2color codes and http://links parser"); const cCompositeChat::cParts & Parts = Msg.GetParts(); - assert(Parts.size() == 4); - assert(Parts[0]->m_PartType == cCompositeChat::ptText); - assert(Parts[1]->m_PartType == cCompositeChat::ptText); - assert(Parts[2]->m_PartType == cCompositeChat::ptUrl); - assert(Parts[3]->m_PartType == cCompositeChat::ptText); - assert(Parts[0]->m_Style == ""); - assert(Parts[1]->m_Style == "@2"); - assert(Parts[2]->m_Style == "@2"); - assert(Parts[3]->m_Style == "@2"); + assert_test(Parts.size() == 4); + assert_test(Parts[0]->m_PartType == cCompositeChat::ptText); + assert_test(Parts[1]->m_PartType == cCompositeChat::ptText); + assert_test(Parts[2]->m_PartType == cCompositeChat::ptUrl); + assert_test(Parts[3]->m_PartType == cCompositeChat::ptText); + assert_test(Parts[0]->m_Style == ""); + assert_test(Parts[1]->m_Style == "@2"); + assert_test(Parts[2]->m_Style == "@2"); + assert_test(Parts[3]->m_Style == "@2"); } void TestParser2(void) @@ -48,15 +48,15 @@ public: cCompositeChat Msg; Msg.ParseText("@3Advanced stuff: @5overriding color codes and http://links.with/@4color-in-them handling"); const cCompositeChat::cParts & Parts = Msg.GetParts(); - assert(Parts.size() == 4); - assert(Parts[0]->m_PartType == cCompositeChat::ptText); - assert(Parts[1]->m_PartType == cCompositeChat::ptText); - assert(Parts[2]->m_PartType == cCompositeChat::ptUrl); - assert(Parts[3]->m_PartType == cCompositeChat::ptText); - assert(Parts[0]->m_Style == "@3"); - assert(Parts[1]->m_Style == "@5"); - assert(Parts[2]->m_Style == "@5"); - assert(Parts[3]->m_Style == "@5"); + assert_test(Parts.size() == 4); + assert_test(Parts[0]->m_PartType == cCompositeChat::ptText); + assert_test(Parts[1]->m_PartType == cCompositeChat::ptText); + assert_test(Parts[2]->m_PartType == cCompositeChat::ptUrl); + assert_test(Parts[3]->m_PartType == cCompositeChat::ptText); + assert_test(Parts[0]->m_Style == "@3"); + assert_test(Parts[1]->m_Style == "@5"); + assert_test(Parts[2]->m_Style == "@5"); + assert_test(Parts[3]->m_Style == "@5"); } void TestParser3(void) @@ -64,11 +64,11 @@ public: cCompositeChat Msg; Msg.ParseText("http://links.starting the text"); const cCompositeChat::cParts & Parts = Msg.GetParts(); - assert(Parts.size() == 2); - assert(Parts[0]->m_PartType == cCompositeChat::ptUrl); - assert(Parts[1]->m_PartType == cCompositeChat::ptText); - assert(Parts[0]->m_Style == ""); - assert(Parts[1]->m_Style == ""); + assert_test(Parts.size() == 2); + assert_test(Parts[0]->m_PartType == cCompositeChat::ptUrl); + assert_test(Parts[1]->m_PartType == cCompositeChat::ptText); + assert_test(Parts[0]->m_Style == ""); + assert_test(Parts[1]->m_Style == ""); } void TestParser4(void) @@ -76,11 +76,11 @@ public: cCompositeChat Msg; Msg.ParseText("links finishing the text: http://some.server"); const cCompositeChat::cParts & Parts = Msg.GetParts(); - assert(Parts.size() == 2); - assert(Parts[0]->m_PartType == cCompositeChat::ptText); - assert(Parts[1]->m_PartType == cCompositeChat::ptUrl); - assert(Parts[0]->m_Style == ""); - assert(Parts[1]->m_Style == ""); + assert_test(Parts.size() == 2); + assert_test(Parts[0]->m_PartType == cCompositeChat::ptText); + assert_test(Parts[1]->m_PartType == cCompositeChat::ptUrl); + assert_test(Parts[0]->m_Style == ""); + assert_test(Parts[1]->m_Style == ""); } void TestParser5(void) @@ -88,9 +88,9 @@ public: cCompositeChat Msg; Msg.ParseText("http://only.links"); const cCompositeChat::cParts & Parts = Msg.GetParts(); - assert(Parts.size() == 1); - assert(Parts[0]->m_PartType == cCompositeChat::ptUrl); - assert(Parts[0]->m_Style == ""); + assert_test(Parts.size() == 1); + assert_test(Parts[0]->m_PartType == cCompositeChat::ptUrl); + assert_test(Parts[0]->m_Style == ""); } } gTest; diff --git a/src/CraftingRecipes.cpp b/src/CraftingRecipes.cpp index 868182394..be9f45caa 100644 --- a/src/CraftingRecipes.cpp +++ b/src/CraftingRecipes.cpp @@ -192,7 +192,9 @@ void cCraftingGrid::Dump(void) { for (int y = 0; y < m_Height; y++) for (int x = 0; x < m_Width; x++) { + #ifdef _DEBUG int idx = x + m_Width * y; + #endif LOGD("Slot (%d, %d): Type %d, health %d, count %d", x, y, m_Items[idx].m_ItemType, m_Items[idx].m_ItemDamage, m_Items[idx].m_ItemCount ); diff --git a/src/Globals.h b/src/Globals.h index b046e6db0..2cd160677 100644 --- a/src/Globals.h +++ b/src/Globals.h @@ -234,9 +234,10 @@ template class SizeChecker; // Pretty much the same as ASSERT() but stays in Release builds #define VERIFY( x ) ( !!(x) || ( LOGERROR("Verification failed: %s, file %s, line %i", #x, __FILE__, __LINE__ ), exit(1), 0 ) ) - - - +// Same as assert but in all Self test builds +#ifdef SELF_TEST +#define assert_test(x) ( !!(x) || (assert(0), exit(1), 0)) +#endif /// A generic interface used mainly in ForEach() functions template class cItemCallback -- cgit v1.2.3 From 98e15a34a416c31d4689836f4f38161f1270513c Mon Sep 17 00:00:00 2001 From: Tycho Date: Mon, 10 Mar 2014 13:18:53 -0700 Subject: Fixed xofts issues --- Tools/ProtoProxy/Connection.cpp | 2 +- src/ChunkDef.h | 26 ++++++++------------------ src/StringUtils.cpp | 2 +- src/WorldStorage/FastNBT.cpp | 2 +- src/WorldStorage/FireworksSerializer.cpp | 4 ++++ 5 files changed, 15 insertions(+), 21 deletions(-) diff --git a/Tools/ProtoProxy/Connection.cpp b/Tools/ProtoProxy/Connection.cpp index be908f303..73688d310 100644 --- a/Tools/ProtoProxy/Connection.cpp +++ b/Tools/ProtoProxy/Connection.cpp @@ -2697,7 +2697,7 @@ bool cConnection::ParseMetadata(cByteBuffer & a_Buffer, AString & a_Metadata) a_Metadata.push_back(x); while (x != 0x7f) { - //int Index = ((unsigned)((unsigned char)x)) & 0x1f; // Lower 5 bits = index + // int Index = ((unsigned)((unsigned char)x)) & 0x1f; // Lower 5 bits = index int Type = ((unsigned)((unsigned char)x)) >> 5; // Upper 3 bits = type int Length = 0; switch (Type) diff --git a/src/ChunkDef.h b/src/ChunkDef.h index a5059348c..fcda64f5c 100644 --- a/src/ChunkDef.h +++ b/src/ChunkDef.h @@ -124,9 +124,7 @@ public: (z < Width) && (z > -1) ) { - return MakeIndexNoCheck(static_cast(x), - static_cast(y), - static_cast(z)); + return MakeIndexNoCheck(x, y, z); } LOGERROR("cChunkDef::MakeIndex(): coords out of range: {%d, %d, %d}; returning fake index 0", x, y, z); ASSERT(!"cChunkDef::MakeIndex(): coords out of chunk range!"); @@ -134,13 +132,13 @@ public: } - inline static unsigned int MakeIndexNoCheck(unsigned int x, unsigned int y, unsigned int z) + inline static unsigned int MakeIndexNoCheck(int x, int y, int z) { #if AXIS_ORDER == AXIS_ORDER_XZY // For some reason, NOT using the Horner schema is faster. Weird. - return x + (z * cChunkDef::Width) + (y * cChunkDef::Width * cChunkDef::Width); // 1.2 is XZY + return static_cast(x + (z * cChunkDef::Width) + (y * cChunkDef::Width * cChunkDef::Width)); // 1.2 is XZY #elif AXIS_ORDER == AXIS_ORDER_YZX - return y + (z * cChunkDef::Width) + (x * cChunkDef::Height * cChunkDef::Width); // 1.1 is YZX + return static_cast(y + (z * cChunkDef::Width) + (x * cChunkDef::Height * cChunkDef::Width)); // 1.1 is YZX #endif } @@ -168,9 +166,7 @@ public: ASSERT((a_X >= 0) && (a_X < Width)); ASSERT((a_Y >= 0) && (a_Y < Height)); ASSERT((a_Z >= 0) && (a_Z < Width)); - a_BlockTypes[MakeIndexNoCheck(static_cast(a_X), - static_cast(a_Y), - static_cast(a_Z))] = a_Type; + a_BlockTypes[MakeIndexNoCheck(a_X, a_Y, a_Z)] = a_Type; } @@ -186,9 +182,7 @@ public: ASSERT((a_X >= 0) && (a_X < Width)); ASSERT((a_Y >= 0) && (a_Y < Height)); ASSERT((a_Z >= 0) && (a_Z < Width)); - return a_BlockTypes[MakeIndexNoCheck(static_cast(a_X), - static_cast(a_Y), - static_cast(a_Z))]; + return a_BlockTypes[MakeIndexNoCheck(a_X, a_Y, a_Z)]; } @@ -246,9 +240,7 @@ public: { if ((x < Width) && (x > -1) && (y < Height) && (y > -1) && (z < Width) && (z > -1)) { - unsigned int Index = MakeIndexNoCheck(static_cast(x), - static_cast(y), - static_cast(z)); + unsigned int Index = MakeIndexNoCheck(x, y, z); return (a_Buffer[Index / 2] >> ((Index & 1) * 4)) & 0x0f; } ASSERT(!"cChunkDef::GetNibble(): coords out of chunk range!"); @@ -282,9 +274,7 @@ public: return; } - unsigned int Index = MakeIndexNoCheck(static_cast(x), - static_cast(y), - static_cast(z)); + unsigned int Index = MakeIndexNoCheck(x, y, z); a_Buffer[Index / 2] = static_cast( (a_Buffer[Index / 2] & (0xf0 >> ((Index & 1) * 4))) | // The untouched nibble ((a_Nibble & 0x0f) << ((Index & 1) * 4)) // The nibble being set diff --git a/src/StringUtils.cpp b/src/StringUtils.cpp index 3e047fb5c..3f9275798 100644 --- a/src/StringUtils.cpp +++ b/src/StringUtils.cpp @@ -294,7 +294,7 @@ AString & RawBEToUTF8(const char * a_RawData, int a_NumShorts, AString & a_UTF8) a_UTF8.reserve(3 * a_NumShorts / 2); // a quick guess of the resulting size for (int i = 0; i < a_NumShorts; i++) { - int c = GetBEShort(a_RawData + i*2); + int c = GetBEShort(&a_RawData[i * 2]); if (c < 0x80) { a_UTF8.push_back((char)c); diff --git a/src/WorldStorage/FastNBT.cpp b/src/WorldStorage/FastNBT.cpp index f1f092e0b..be25fd1a4 100644 --- a/src/WorldStorage/FastNBT.cpp +++ b/src/WorldStorage/FastNBT.cpp @@ -510,7 +510,7 @@ void cFastNBTWriter::AddIntArray(const AString & a_Name, const int * a_Value, si size_t size = m_Result.length(); if ((cap - size) < (4 + a_NumElements * 4)) { - m_Result.reserve(size +4 + a_NumElements * 4); + m_Result.reserve(size + 4 + (a_NumElements * 4)); } m_Result.append((const char *)&len, 4); for (size_t i = 0; i < a_NumElements; i++) diff --git a/src/WorldStorage/FireworksSerializer.cpp b/src/WorldStorage/FireworksSerializer.cpp index bdd5952ad..3c97ae0a2 100644 --- a/src/WorldStorage/FireworksSerializer.cpp +++ b/src/WorldStorage/FireworksSerializer.cpp @@ -91,6 +91,8 @@ void cFireworkItem::ParseFromNBT(cFireworkItem & a_FireworkItem, const cParsedNB { // Divide by four as data length returned in bytes int DataLength = a_NBT.GetDataLength(explosiontag); + // round to the next highest multiple of four + DataLength -= DataLength % 4; if (DataLength == 0) { continue; @@ -105,6 +107,8 @@ void cFireworkItem::ParseFromNBT(cFireworkItem & a_FireworkItem, const cParsedNB else if (ExplosionName == "FadeColors") { int DataLength = a_NBT.GetDataLength(explosiontag) / 4; + // round to the next highest multiple of four + DataLength -= DataLength % 4; if (DataLength == 0) { continue; -- cgit v1.2.3 From 728870ed9dd8231fe493863d6cb51766c5b244ca Mon Sep 17 00:00:00 2001 From: Tycho Date: Tue, 11 Mar 2014 12:35:44 -0700 Subject: Fixed Warnings in PieceGenerator --- src/Generating/PieceGenerator.cpp | 14 +++++++------- src/Generating/PieceGenerator.h | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Generating/PieceGenerator.cpp b/src/Generating/PieceGenerator.cpp index e3de5b951..8fcc14389 100644 --- a/src/Generating/PieceGenerator.cpp +++ b/src/Generating/PieceGenerator.cpp @@ -31,14 +31,14 @@ public: Gen.PlacePieces(500, 50, 500, 3, OutPieces); // Print out the pieces: - printf("OutPieces.size() = %u\n", OutPieces.size()); + printf("OutPieces.size() = %zu\n", OutPieces.size()); size_t idx = 0; for (cPlacedPieces::const_iterator itr = OutPieces.begin(), end = OutPieces.end(); itr != end; ++itr, ++idx) { const Vector3i & Coords = (*itr)->GetCoords(); cCuboid Hitbox = (*itr)->GetHitBox(); Hitbox.Sort(); - printf("%u: {%d, %d, %d}, rot %d, hitbox {%d, %d, %d} - {%d, %d, %d} (%d * %d * %d)\n", idx, + printf("%zu: {%d, %d, %d}, rot %d, hitbox {%d, %d, %d} - {%d, %d, %d} (%d * %d * %d)\n", idx, Coords.x, Coords.y, Coords.z, (*itr)->GetNumCCWRotations(), Hitbox.p1.x, Hitbox.p1.y, Hitbox.p1.z, @@ -183,7 +183,6 @@ cPiece::cConnector cPiece::RotateMoveConnector(const cConnector & a_Connector, i cPiece::cConnector res(a_Connector); // Rotate the res connector: - Vector3i Size = GetSize(); switch (a_NumCCWRotations) { case 0: @@ -338,7 +337,7 @@ cPlacedPiece * cPieceGenerator::PlaceStartingPiece(int a_BlockX, int a_BlockY, i // Choose a random supported rotation: int Rotations[4] = {0}; int NumRotations = 1; - for (int i = 1; i < ARRAYCOUNT(Rotations); i++) + for (size_t i = 1; i < ARRAYCOUNT(Rotations); i++) { if (StartingPiece->CanRotateCCW(i)) { @@ -378,7 +377,7 @@ bool cPieceGenerator::TryPlacePieceAtConnector( static const int DirectionRotationTable[6][6] = { /* YM, YP, ZM, ZP, XM, XP - /* YM */ { 0, 0, 0, 0, 0, 0}, + YM */ { 0, 0, 0, 0, 0, 0}, /* YP */ { 0, 0, 0, 0, 0, 0}, /* ZM */ { 0, 0, 2, 0, 1, 3}, /* ZP */ { 0, 0, 0, 2, 3, 1}, @@ -503,11 +502,12 @@ bool cPieceGenerator::CheckConnection( // DEBUG: void cPieceGenerator::DebugConnectorPool(const cPieceGenerator::cFreeConnectors & a_ConnectorPool, size_t a_NumProcessed) { - printf(" Connector pool: %u items\n", a_ConnectorPool.size() - a_NumProcessed); + printf(" Connector pool: %zu items\n", a_ConnectorPool.size() - a_NumProcessed); size_t idx = 0; for (cPieceGenerator::cFreeConnectors::const_iterator itr = a_ConnectorPool.begin() + a_NumProcessed, end = a_ConnectorPool.end(); itr != end; ++itr, ++idx) { - printf(" %u: {%d, %d, %d}, type %d, direction %s, depth %d\n", + // Format specifier for size_t is zu + printf(" %zu: {%d, %d, %d}, type %d, direction %s, depth %d\n", idx, itr->m_Connector.m_Pos.x, itr->m_Connector.m_Pos.y, itr->m_Connector.m_Pos.z, itr->m_Connector.m_Type, diff --git a/src/Generating/PieceGenerator.h b/src/Generating/PieceGenerator.h index 9dd5bcfba..3386d7a94 100644 --- a/src/Generating/PieceGenerator.h +++ b/src/Generating/PieceGenerator.h @@ -122,9 +122,9 @@ public: const cPiece & GetPiece (void) const { return *m_Piece; } const Vector3i & GetCoords (void) const { return m_Coords; } - const int GetNumCCWRotations(void) const { return m_NumCCWRotations; } + int GetNumCCWRotations(void) const { return m_NumCCWRotations; } const cCuboid & GetHitBox (void) const { return m_HitBox; } - const int GetDepth (void) const { return m_Depth; } + int GetDepth (void) const { return m_Depth; } protected: const cPlacedPiece * m_Parent; -- cgit v1.2.3 From 0fc4a1ee06199db80edd4a9f79a4ba1c4369f656 Mon Sep 17 00:00:00 2001 From: Tycho Date: Tue, 11 Mar 2014 12:36:51 -0700 Subject: Move comment --- SetFlags.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SetFlags.cmake b/SetFlags.cmake index d9308f603..25310c368 100644 --- a/SetFlags.cmake +++ b/SetFlags.cmake @@ -187,8 +187,8 @@ macro(set_exe_flags) # we support non-IEEE 754 fpus so can make no guarentees about error add_flags_cxx("-ffast-math") - # clang does not provide the __extern_always_inline macro and a part of libm depends on this when using fast-math if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + # clang does not provide the __extern_always_inline macro and a part of libm depends on this when using fast-math add_flags_cxx("-D__extern_always_inline=inline") add_flags_cxx("-Werror -Weverything -Wno-c++98-compat-pedantic -Wno-string-conversion") add_flags_cxx("-Wno-extra-semi -Wno-error=switch-enum -Wno-documentation") -- cgit v1.2.3 From 80cc824c0cf8634439dfb3913cf17af714b03d99 Mon Sep 17 00:00:00 2001 From: Tycho Date: Tue, 11 Mar 2014 12:41:18 -0700 Subject: Fixed Chunkdef warnings --- src/ChunkDef.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ChunkDef.h b/src/ChunkDef.h index 5dd64e1b5..61ad49ad0 100644 --- a/src/ChunkDef.h +++ b/src/ChunkDef.h @@ -112,7 +112,7 @@ public: } - inline static unsigned int MakeIndex(int x, int y, int z ) + inline static int MakeIndex(int x, int y, int z ) { if ( (x < Width) && (x > -1) && @@ -271,7 +271,7 @@ public: } int Index = MakeIndexNoCheck(x, y, z); - a_Buffer[Index / 2] = ( + a_Buffer[Index / 2] = static_cast( (a_Buffer[Index / 2] & (0xf0 >> ((Index & 1) * 4))) | // The untouched nibble ((a_Nibble & 0x0f) << ((Index & 1) * 4)) // The nibble being set ); -- cgit v1.2.3 From bb4b35e438a77ff45cded8938e1e3e2724a1587e Mon Sep 17 00:00:00 2001 From: Tycho Date: Tue, 11 Mar 2014 12:54:46 -0700 Subject: Rollback submodule change --- MCServer/Plugins/Core | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MCServer/Plugins/Core b/MCServer/Plugins/Core index 3b416b07a..013a32a7f 160000 --- a/MCServer/Plugins/Core +++ b/MCServer/Plugins/Core @@ -1 +1 @@ -Subproject commit 3b416b07a339b3abcbc127070d56eea05b05373d +Subproject commit 013a32a7fb3c8a6cfe0aef892d4c7394d4e1be59 -- cgit v1.2.3 From 53faac10c50ba88ce540e0464123f388bd7db069 Mon Sep 17 00:00:00 2001 From: Tycho Date: Tue, 11 Mar 2014 13:41:15 -0700 Subject: Added macros to follow format string checking through wrappers --- src/Globals.h | 4 ++++ src/OSSupport/File.h | 2 +- src/StringUtils.h | 6 +++--- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Globals.h b/src/Globals.h index 2cd160677..e907614d7 100644 --- a/src/Globals.h +++ b/src/Globals.h @@ -38,6 +38,8 @@ // No alignment needed in MSVC #define ALIGN_8 #define ALIGN_16 + + #define FORMATSTRING(formatIndex,va_argsIndex) #elif defined(__GNUC__) @@ -56,6 +58,8 @@ // Some portability macros :) #define stricmp strcasecmp + + #define FORMATSTRING(formatIndex,va_argsIndex) __attribute__((format (printf, formatIndex, va_argsIndex))) #else diff --git a/src/OSSupport/File.h b/src/OSSupport/File.h index 07fce6661..e229035b7 100644 --- a/src/OSSupport/File.h +++ b/src/OSSupport/File.h @@ -131,7 +131,7 @@ public: /** Returns the list of all items in the specified folder (files, folders, nix pipes, whatever's there). */ static AStringVector GetFolderContents(const AString & a_Folder); // Exported in ManualBindings.cpp - int Printf(const char * a_Fmt, ...); + int Printf(const char * a_Fmt, ...) FORMATSTRING(2,3); /** Flushes all the bufferef output into the file (only when writing) */ void Flush(void); diff --git a/src/StringUtils.h b/src/StringUtils.h index b64108409..a7f22b100 100644 --- a/src/StringUtils.h +++ b/src/StringUtils.h @@ -22,13 +22,13 @@ typedef std::list AStringList; /** Add the formated string to the existing data in the string */ -extern AString & AppendVPrintf(AString & str, const char * format, va_list args); +extern AString & AppendVPrintf(AString & str, const char * format, va_list args) FORMATSTRING(2,0); /// Output the formatted text into the string -extern AString & Printf (AString & str, const char * format, ...); +extern AString & Printf (AString & str, const char * format, ...) FORMATSTRING(2,3); /// Output the formatted text into string, return string by value -extern AString Printf(const char * format, ...); +extern AString Printf(const char * format, ...) FORMATSTRING(1,2); /// Add the formatted string to the existing data in the string extern AString & AppendPrintf (AString & str, const char * format, ...); -- cgit v1.2.3 From f64f8790274c4ee63b4eb904110bd35f93652d78 Mon Sep 17 00:00:00 2001 From: Tycho Date: Tue, 11 Mar 2014 13:46:32 -0700 Subject: Fixed format errors in protocol --- src/Protocol/Protocol17x.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index 8c800036e..e76c0fe49 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -1251,7 +1251,7 @@ void cProtocol172::AddReceivedData(const char * a_Data, int a_Size) ASSERT(m_ReceivedData.GetReadableSpace() == OldReadableSpace); AString Hex; CreateHexDump(Hex, AllData.data(), AllData.size(), 16); - m_CommLogFile.Printf("Incoming data, %d (0x%x) unparsed bytes already present in buffer:\n%s\n", + m_CommLogFile.Printf("Incoming data, %zu (0x%zx) unparsed bytes already present in buffer:\n%s\n", AllData.size(), AllData.size(), Hex.c_str() ); } @@ -1351,7 +1351,7 @@ void cProtocol172::AddReceivedData(const char * a_Data, int a_Size) // Put a message in the comm log: if (g_ShouldLogCommIn) { - m_CommLogFile.Printf("^^^^^^ Wrong number of bytes read for this packet (exp %d left, got %d left) ^^^^^^\n\n\n", + m_CommLogFile.Printf("^^^^^^ Wrong number of bytes read for this packet (exp %d left, got %zu left) ^^^^^^\n\n\n", 1, bb.GetReadableSpace() ); m_CommLogFile.Flush(); @@ -1373,7 +1373,7 @@ void cProtocol172::AddReceivedData(const char * a_Data, int a_Size) ASSERT(m_ReceivedData.GetReadableSpace() == OldReadableSpace); AString Hex; CreateHexDump(Hex, AllData.data(), AllData.size(), 16); - m_CommLogFile.Printf("There are %d (0x%x) bytes of non-parse-able data left in the buffer:\n%s", + m_CommLogFile.Printf("There are %zu (0x%zx) bytes of non-parse-able data left in the buffer:\n%s", m_ReceivedData.GetReadableSpace(), m_ReceivedData.GetReadableSpace(), Hex.c_str() ); m_CommLogFile.Flush(); -- cgit v1.2.3 From a19f5fc484648d226899667410aeb82de354c714 Mon Sep 17 00:00:00 2001 From: Tycho Date: Tue, 11 Mar 2014 13:51:56 -0700 Subject: Move Format issues --- src/CommandOutput.h | 2 +- src/Log.cpp | 2 +- src/Log.h | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/CommandOutput.h b/src/CommandOutput.h index 3763d625f..81d9ddb84 100644 --- a/src/CommandOutput.h +++ b/src/CommandOutput.h @@ -17,7 +17,7 @@ public: virtual ~cCommandOutputCallback() {}; // Force a virtual destructor in subclasses /// Syntax sugar function, calls Out() with Printf()-ed parameters; appends a "\n" - void Out(const char * a_Fmt, ...); + void Out(const char * a_Fmt, ...) FORMATSTRING(2,3); /// Called when the command wants to output anything; may be called multiple times virtual void Out(const AString & a_Text) = 0; diff --git a/src/Log.cpp b/src/Log.cpp index 1ea327d5d..54e2b7812 100644 --- a/src/Log.cpp +++ b/src/Log.cpp @@ -118,7 +118,7 @@ void cLog::Log(const char * a_Format, va_list argList) AString Line; #ifdef _DEBUG - Printf(Line, "[%04x|%02d:%02d:%02d] %s", cIsThread::GetCurrentID(), timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, Message.c_str()); + Printf(Line, "[%04zu|%02d:%02d:%02d] %s", cIsThread::GetCurrentID(), timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, Message.c_str()); #else Printf(Line, "[%02d:%02d:%02d] %s", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, Message.c_str()); #endif diff --git a/src/Log.h b/src/Log.h index cba248dae..340fa23bc 100644 --- a/src/Log.h +++ b/src/Log.h @@ -14,8 +14,8 @@ private: public: cLog(const AString & a_FileName); ~cLog(); - void Log(const char * a_Format, va_list argList); - void Log(const char * a_Format, ...); + void Log(const char * a_Format, va_list argList) FORMATSTRING(2,0); + void Log(const char * a_Format, ...) FORMATSTRING(2,3); // tolua_begin void SimpleLog(const char * a_String); void OpenLog(const char * a_FileName); -- cgit v1.2.3 From 16b27c4b7ae2ccb03355148fa7fc7116190cc5fb Mon Sep 17 00:00:00 2001 From: Tycho Date: Tue, 11 Mar 2014 14:16:08 -0700 Subject: Fixed a load of format string errors --- src/Bindings/LuaState.cpp | 4 +++- src/ClientHandle.cpp | 2 +- src/CommandOutput.cpp | 4 ++-- src/CraftingRecipes.cpp | 2 +- src/FurnaceRecipe.cpp | 2 +- src/Generating/ChunkGenerator.cpp | 4 ++-- src/Item.cpp | 8 ++++---- src/MCLogger.h | 8 ++++---- src/OSSupport/SocketThreads.cpp | 2 +- src/Protocol/Protocol132.cpp | 2 +- src/Protocol/Protocol17x.cpp | 6 +++--- src/UI/Window.cpp | 2 +- src/WorldStorage/WSSCompact.cpp | 10 +++++----- 13 files changed, 29 insertions(+), 27 deletions(-) diff --git a/src/Bindings/LuaState.cpp b/src/Bindings/LuaState.cpp index aa6ee05b3..2351f0c24 100644 --- a/src/Bindings/LuaState.cpp +++ b/src/Bindings/LuaState.cpp @@ -1281,7 +1281,9 @@ void cLuaState::LogStack(lua_State * a_LuaState, const char * a_Header) { UNUSED(a_Header); // The param seems unused when compiling for release, so the compiler warns - LOGD((a_Header != NULL) ? a_Header : "Lua C API Stack contents:"); + + // Format string consisting only of %s is used to appease the compiler + LOGD("%s",(a_Header != NULL) ? a_Header : "Lua C API Stack contents:"); for (int i = lua_gettop(a_LuaState); i > 0; i--) { AString Value; diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index df728e83b..02b2e1c47 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -882,7 +882,7 @@ void cClientHandle::HandleBlockDigFinished(int a_BlockX, int a_BlockY, int a_Blo LOGD("Prevented a dig/aim bug in the client (finish {%d, %d, %d} vs start {%d, %d, %d}, HSD: %s)", a_BlockX, a_BlockY, a_BlockZ, m_LastDigBlockX, m_LastDigBlockY, m_LastDigBlockZ, - m_HasStartedDigging + (m_HasStartedDigging ? "True" : "False") ); return; } diff --git a/src/CommandOutput.cpp b/src/CommandOutput.cpp index c221682a1..74f857284 100644 --- a/src/CommandOutput.cpp +++ b/src/CommandOutput.cpp @@ -51,7 +51,7 @@ void cLogCommandOutputCallback::Finished(void) { case '\n': { - LOG(m_Buffer.substr(last, i - last).c_str()); + LOG("%s",m_Buffer.substr(last, i - last).c_str()); last = i + 1; break; } @@ -59,7 +59,7 @@ void cLogCommandOutputCallback::Finished(void) } // for i - m_Buffer[] if (last < len) { - LOG(m_Buffer.substr(last).c_str()); + LOG("%s",m_Buffer.substr(last).c_str()); } // Clear the buffer for the next command output: diff --git a/src/CraftingRecipes.cpp b/src/CraftingRecipes.cpp index be9f45caa..30f21686c 100644 --- a/src/CraftingRecipes.cpp +++ b/src/CraftingRecipes.cpp @@ -340,7 +340,7 @@ void cCraftingRecipes::LoadRecipes(void) } AddRecipeLine(LineNum, Recipe); } // for itr - Split[] - LOG("Loaded %d crafting recipes", m_Recipes.size()); + LOG("Loaded %zu crafting recipes", m_Recipes.size()); } diff --git a/src/FurnaceRecipe.cpp b/src/FurnaceRecipe.cpp index 2e2276981..dd2f259f3 100644 --- a/src/FurnaceRecipe.cpp +++ b/src/FurnaceRecipe.cpp @@ -175,7 +175,7 @@ void cFurnaceRecipe::ReloadRecipes(void) { LOGERROR("ERROR: FurnaceRecipe, syntax error" ); } - LOG("Loaded %u furnace recipes and %u fuels", m_pState->Recipes.size(), m_pState->Fuel.size()); + LOG("Loaded %zu furnace recipes and %zu fuels", m_pState->Recipes.size(), m_pState->Fuel.size()); } diff --git a/src/Generating/ChunkGenerator.cpp b/src/Generating/ChunkGenerator.cpp index ef38f1399..92f6009ac 100644 --- a/src/Generating/ChunkGenerator.cpp +++ b/src/Generating/ChunkGenerator.cpp @@ -116,7 +116,7 @@ void cChunkGenerator::QueueGenerateChunk(int a_ChunkX, int a_ChunkY, int a_Chunk // Add to queue, issue a warning if too many: if (m_Queue.size() >= QUEUE_WARNING_LIMIT) { - LOGWARN("WARNING: Adding chunk [%i, %i] to generation queue; Queue is too big! (%i)", a_ChunkX, a_ChunkZ, m_Queue.size()); + LOGWARN("WARNING: Adding chunk [%i, %i] to generation queue; Queue is too big! (%zu)", a_ChunkX, a_ChunkZ, m_Queue.size()); } m_Queue.push_back(cChunkCoords(a_ChunkX, a_ChunkY, a_ChunkZ)); } @@ -180,7 +180,7 @@ BLOCKTYPE cChunkGenerator::GetIniBlock(cIniFile & a_IniFile, const AString & a_S BLOCKTYPE Block = BlockStringToType(BlockType); if (Block < 0) { - LOGWARN("[&s].%s Could not parse block value \"%s\". Using default: \"%s\".", a_SectionName.c_str(), a_ValueName.c_str(), BlockType.c_str(),a_Default.c_str()); + LOGWARN("[%s].%s Could not parse block value \"%s\". Using default: \"%s\".", a_SectionName.c_str(), a_ValueName.c_str(), BlockType.c_str(),a_Default.c_str()); return BlockStringToType(a_Default); } return Block; diff --git a/src/Item.cpp b/src/Item.cpp index 61d57e763..c8dda209c 100644 --- a/src/Item.cpp +++ b/src/Item.cpp @@ -216,7 +216,7 @@ cItem * cItems::Get(int a_Idx) { if ((a_Idx < 0) || (a_Idx >= (int)size())) { - LOGWARNING("cItems: Attempt to get an out-of-bounds item at index %d; there are currently %d items. Returning a nil.", a_Idx, size()); + LOGWARNING("cItems: Attempt to get an out-of-bounds item at index %d; there are currently %zu items. Returning a nil.", a_Idx, size()); return NULL; } return &at(a_Idx); @@ -230,7 +230,7 @@ void cItems::Set(int a_Idx, const cItem & a_Item) { if ((a_Idx < 0) || (a_Idx >= (int)size())) { - LOGWARNING("cItems: Attempt to set an item at an out-of-bounds index %d; there are currently %d items. Not setting.", a_Idx, size()); + LOGWARNING("cItems: Attempt to set an item at an out-of-bounds index %d; there are currently %zu items. Not setting.", a_Idx, size()); return; } at(a_Idx) = a_Item; @@ -244,7 +244,7 @@ void cItems::Delete(int a_Idx) { if ((a_Idx < 0) || (a_Idx >= (int)size())) { - LOGWARNING("cItems: Attempt to delete an item at an out-of-bounds index %d; there are currently %d items. Ignoring.", a_Idx, size()); + LOGWARNING("cItems: Attempt to delete an item at an out-of-bounds index %d; there are currently %zu items. Ignoring.", a_Idx, size()); return; } erase(begin() + a_Idx); @@ -258,7 +258,7 @@ void cItems::Set(int a_Idx, short a_ItemType, char a_ItemCount, short a_ItemDama { if ((a_Idx < 0) || (a_Idx >= (int)size())) { - LOGWARNING("cItems: Attempt to set an item at an out-of-bounds index %d; there are currently %d items. Not setting.", a_Idx, size()); + LOGWARNING("cItems: Attempt to set an item at an out-of-bounds index %d; there are currently %zu items. Not setting.", a_Idx, size()); return; } at(a_Idx) = cItem(a_ItemType, a_ItemCount, a_ItemDamage); diff --git a/src/MCLogger.h b/src/MCLogger.h index c949a4cdf..348b51242 100644 --- a/src/MCLogger.h +++ b/src/MCLogger.h @@ -57,10 +57,10 @@ private: -extern void LOG(const char* a_Format, ...); -extern void LOGINFO(const char* a_Format, ...); -extern void LOGWARN(const char* a_Format, ...); -extern void LOGERROR(const char* a_Format, ...); +extern void LOG(const char* a_Format, ...) FORMATSTRING(1,2); +extern void LOGINFO(const char* a_Format, ...) FORMATSTRING(1,2); +extern void LOGWARN(const char* a_Format, ...) FORMATSTRING(1,2); +extern void LOGERROR(const char* a_Format, ...) FORMATSTRING(1,2); diff --git a/src/OSSupport/SocketThreads.cpp b/src/OSSupport/SocketThreads.cpp index a02661d2c..f37b00202 100644 --- a/src/OSSupport/SocketThreads.cpp +++ b/src/OSSupport/SocketThreads.cpp @@ -54,7 +54,7 @@ bool cSocketThreads::AddClient(const cSocket & a_Socket, cCallback * a_Client) } // No thread has free space, create a new one: - LOGD("Creating a new cSocketThread (currently have %d)", m_Threads.size()); + LOGD("Creating a new cSocketThread (currently have %zu)", m_Threads.size()); cSocketThread * Thread = new cSocketThread(this); if (!Thread->Start()) { diff --git a/src/Protocol/Protocol132.cpp b/src/Protocol/Protocol132.cpp index 8df550c7b..43fe90616 100644 --- a/src/Protocol/Protocol132.cpp +++ b/src/Protocol/Protocol132.cpp @@ -100,7 +100,7 @@ cProtocol132::~cProtocol132() { if (!m_DataToSend.empty()) { - LOGD("There are %d unsent bytes while deleting cProtocol132", m_DataToSend.size()); + LOGD("There are %zu unsent bytes while deleting cProtocol132", m_DataToSend.size()); } } diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index e76c0fe49..9e5fe53fb 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -1344,7 +1344,7 @@ void cProtocol172::AddReceivedData(const char * a_Data, int a_Size) if (bb.GetReadableSpace() != 1) { // Read more or less than packet length, report as error - LOGWARNING("Protocol 1.7: Wrong number of bytes read for packet 0x%x, state %d. Read %u bytes, packet contained %u bytes", + LOGWARNING("Protocol 1.7: Wrong number of bytes read for packet 0x%x, state %d. Read %zu bytes, packet contained %u bytes", PacketType, m_State, bb.GetUsedSpace() - bb.GetReadableSpace(), PacketLen ); @@ -2062,7 +2062,7 @@ void cProtocol172::ParseItemMetadata(cItem & a_Item, const AString & a_Metadata) { AString HexDump; CreateHexDump(HexDump, a_Metadata.data(), a_Metadata.size(), 16); - LOGWARNING("Cannot unGZIP item metadata (%u bytes):\n%s", a_Metadata.size(), HexDump.c_str()); + LOGWARNING("Cannot unGZIP item metadata (%zu bytes):\n%s", a_Metadata.size(), HexDump.c_str()); return; } @@ -2072,7 +2072,7 @@ void cProtocol172::ParseItemMetadata(cItem & a_Item, const AString & a_Metadata) { AString HexDump; CreateHexDump(HexDump, Uncompressed.data(), Uncompressed.size(), 16); - LOGWARNING("Cannot parse NBT item metadata: (%u bytes)\n%s", Uncompressed.size(), HexDump.c_str()); + LOGWARNING("Cannot parse NBT item metadata: (%zu bytes)\n%s", Uncompressed.size(), HexDump.c_str()); return; } diff --git a/src/UI/Window.cpp b/src/UI/Window.cpp index 1a8456f70..5249a4bca 100644 --- a/src/UI/Window.cpp +++ b/src/UI/Window.cpp @@ -637,7 +637,7 @@ int cWindow::DistributeItemToSlots(cPlayer & a_Player, const cItem & a_Item, int { if ((size_t)(a_Item.m_ItemCount) < a_SlotNums.size()) { - LOGWARNING("%s: Distributing less items (%d) than slots (%u)", __FUNCTION__, (int)a_Item.m_ItemCount, a_SlotNums.size()); + LOGWARNING("%s: Distributing less items (%d) than slots (%zu)", __FUNCTION__, (int)a_Item.m_ItemCount, a_SlotNums.size()); // This doesn't seem to happen with the 1.5.1 client, so we don't worry about it for now return 0; } diff --git a/src/WorldStorage/WSSCompact.cpp b/src/WorldStorage/WSSCompact.cpp index 1e84fb4ad..b1e8d12b7 100644 --- a/src/WorldStorage/WSSCompact.cpp +++ b/src/WorldStorage/WSSCompact.cpp @@ -569,7 +569,7 @@ void cWSSCompact::cPAKFile::UpdateChunk1To2() if( ChunksConverted % 32 == 0 ) { - LOGINFO("Updating \"%s\" version 1 to version 2: %d %%", m_FileName.c_str(), (ChunksConverted * 100) / m_ChunkHeaders.size() ); + LOGINFO("Updating \"%s\" version 1 to version 2: %zu %%", m_FileName.c_str(), (ChunksConverted * 100) / m_ChunkHeaders.size() ); } ChunksConverted++; @@ -607,7 +607,7 @@ void cWSSCompact::cPAKFile::UpdateChunk1To2() if (UncompressedSize != (int)UncompressedData.size()) { - LOGWARNING("Uncompressed data size differs (exp %d bytes, got %d) for chunk [%d, %d]", + LOGWARNING("Uncompressed data size differs (exp %d bytes, got %zu) for chunk [%d, %d]", UncompressedSize, UncompressedData.size(), Header->m_ChunkX, Header->m_ChunkZ ); @@ -713,7 +713,7 @@ void cWSSCompact::cPAKFile::UpdateChunk2To3() if( ChunksConverted % 32 == 0 ) { - LOGINFO("Updating \"%s\" version 2 to version 3: %d %%", m_FileName.c_str(), (ChunksConverted * 100) / m_ChunkHeaders.size() ); + LOGINFO("Updating \"%s\" version 2 to version 3: %zu %%", m_FileName.c_str(), (ChunksConverted * 100) / m_ChunkHeaders.size() ); } ChunksConverted++; @@ -751,7 +751,7 @@ void cWSSCompact::cPAKFile::UpdateChunk2To3() if (UncompressedSize != (int)UncompressedData.size()) { - LOGWARNING("Uncompressed data size differs (exp %d bytes, got %d) for chunk [%d, %d]", + LOGWARNING("Uncompressed data size differs (exp %d bytes, got %zu) for chunk [%d, %d]", UncompressedSize, UncompressedData.size(), Header->m_ChunkX, Header->m_ChunkZ ); @@ -866,7 +866,7 @@ bool cWSSCompact::LoadChunkFromData(const cChunkCoords & a_Chunk, int & a_Uncomp if (a_UncompressedSize != (int)UncompressedData.size()) { - LOGWARNING("Uncompressed data size differs (exp %d bytes, got %d) for chunk [%d, %d]", + LOGWARNING("Uncompressed data size differs (exp %d bytes, got %zu) for chunk [%d, %d]", a_UncompressedSize, UncompressedData.size(), a_Chunk.m_ChunkX, a_Chunk.m_ChunkZ ); -- cgit v1.2.3 From 7e6ee7ef8158a037c11405986513aa344ce68f42 Mon Sep 17 00:00:00 2001 From: Tycho Date: Tue, 11 Mar 2014 14:43:14 -0700 Subject: Fixed more Format issues --- src/ByteBuffer.cpp | 2 +- src/MCLogger.h | 14 +++++++------- src/Root.cpp | 10 +++++----- src/Server.cpp | 2 +- src/StringUtils.h | 2 +- src/World.cpp | 4 ++-- 6 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/ByteBuffer.cpp b/src/ByteBuffer.cpp index 9d97d8614..d3bcfe866 100644 --- a/src/ByteBuffer.cpp +++ b/src/ByteBuffer.cpp @@ -459,7 +459,7 @@ bool cByteBuffer::ReadVarUTF8String(AString & a_Value) } if (Size > MAX_STRING_SIZE) { - LOGWARNING("%s: String too large: %llu (%llu KiB)", __FUNCTION__, Size, Size / 1024); + LOGWARNING("%s: String too large: %u (%u KiB)", __FUNCTION__, Size, Size / 1024); } return ReadString(a_Value, (int)Size); } diff --git a/src/MCLogger.h b/src/MCLogger.h index 348b51242..ba9e4827f 100644 --- a/src/MCLogger.h +++ b/src/MCLogger.h @@ -21,10 +21,10 @@ public: // tolua_export ~cMCLogger(); // tolua_export - void Log(const char* a_Format, va_list a_ArgList); - void Info(const char* a_Format, va_list a_ArgList); - void Warn(const char* a_Format, va_list a_ArgList); - void Error(const char* a_Format, va_list a_ArgList); + void Log(const char* a_Format, va_list a_ArgList) FORMATSTRING(2,0); + void Info(const char* a_Format, va_list a_ArgList) FORMATSTRING(2,0); + void Warn(const char* a_Format, va_list a_ArgList) FORMATSTRING(2,0); + void Error(const char* a_Format, va_list a_ArgList) FORMATSTRING(2,0); void LogSimple(const char* a_Text, int a_LogType = 0 ); // tolua_export @@ -57,9 +57,9 @@ private: -extern void LOG(const char* a_Format, ...) FORMATSTRING(1,2); -extern void LOGINFO(const char* a_Format, ...) FORMATSTRING(1,2); -extern void LOGWARN(const char* a_Format, ...) FORMATSTRING(1,2); +extern void LOG(const char* a_Format, ...) FORMATSTRING(1,2); +extern void LOGINFO(const char* a_Format, ...) FORMATSTRING(1,2); +extern void LOGWARN(const char* a_Format, ...) FORMATSTRING(1,2); extern void LOGERROR(const char* a_Format, ...) FORMATSTRING(1,2); diff --git a/src/Root.cpp b/src/Root.cpp index 69f18104e..9a5dcac71 100644 --- a/src/Root.cpp +++ b/src/Root.cpp @@ -778,11 +778,11 @@ void cRoot::LogChunkStats(cCommandOutputCallback & a_Output) int Mem = NumValid * sizeof(cChunk); a_Output.Out(" Memory used by chunks: %d KiB (%d MiB)", (Mem + 1023) / 1024, (Mem + 1024 * 1024 - 1) / (1024 * 1024)); a_Output.Out(" Per-chunk memory size breakdown:"); - a_Output.Out(" block types: %6d bytes (%3d KiB)", sizeof(cChunkDef::BlockTypes), (sizeof(cChunkDef::BlockTypes) + 1023) / 1024); - a_Output.Out(" block metadata: %6d bytes (%3d KiB)", sizeof(cChunkDef::BlockNibbles), (sizeof(cChunkDef::BlockNibbles) + 1023) / 1024); - a_Output.Out(" block lighting: %6d bytes (%3d KiB)", 2 * sizeof(cChunkDef::BlockNibbles), (2 * sizeof(cChunkDef::BlockNibbles) + 1023) / 1024); - a_Output.Out(" heightmap: %6d bytes (%3d KiB)", sizeof(cChunkDef::HeightMap), (sizeof(cChunkDef::HeightMap) + 1023) / 1024); - a_Output.Out(" biomemap: %6d bytes (%3d KiB)", sizeof(cChunkDef::BiomeMap), (sizeof(cChunkDef::BiomeMap) + 1023) / 1024); + a_Output.Out(" block types: %6zu bytes (%3zu KiB)", sizeof(cChunkDef::BlockTypes), (sizeof(cChunkDef::BlockTypes) + 1023) / 1024); + a_Output.Out(" block metadata: %6zu bytes (%3zu KiB)", sizeof(cChunkDef::BlockNibbles), (sizeof(cChunkDef::BlockNibbles) + 1023) / 1024); + a_Output.Out(" block lighting: %6zu bytes (%3zu KiB)", 2 * sizeof(cChunkDef::BlockNibbles), (2 * sizeof(cChunkDef::BlockNibbles) + 1023) / 1024); + a_Output.Out(" heightmap: %6zu bytes (%3zu KiB)", sizeof(cChunkDef::HeightMap), (sizeof(cChunkDef::HeightMap) + 1023) / 1024); + a_Output.Out(" biomemap: %6zu bytes (%3zu KiB)", sizeof(cChunkDef::BiomeMap), (sizeof(cChunkDef::BiomeMap) + 1023) / 1024); int Rest = sizeof(cChunk) - sizeof(cChunkDef::BlockTypes) - 3 * sizeof(cChunkDef::BlockNibbles) - sizeof(cChunkDef::HeightMap) - sizeof(cChunkDef::BiomeMap); a_Output.Out(" other: %6d bytes (%3d KiB)", Rest, (Rest + 1023) / 1024); SumNumValid += NumValid; diff --git a/src/Server.cpp b/src/Server.cpp index fcbcaa919..194195136 100644 --- a/src/Server.cpp +++ b/src/Server.cpp @@ -550,7 +550,7 @@ void cServer::PrintHelp(const AStringVector & a_Split, cCommandOutputCallback & for (AStringPairs::const_iterator itr = Callback.m_Commands.begin(), end = Callback.m_Commands.end(); itr != end; ++itr) { const AStringPair & cmd = *itr; - a_Output.Out(Printf("%-*s%s\n", Callback.m_MaxLen, cmd.first.c_str(), cmd.second.c_str())); + a_Output.Out(Printf("%-*s%s\n", static_cast(Callback.m_MaxLen), cmd.first.c_str(), cmd.second.c_str())); } // for itr - Callback.m_Commands[] a_Output.Finished(); } diff --git a/src/StringUtils.h b/src/StringUtils.h index a7f22b100..728ce31e6 100644 --- a/src/StringUtils.h +++ b/src/StringUtils.h @@ -31,7 +31,7 @@ extern AString & Printf (AString & str, const char * format, ...) FORMATST extern AString Printf(const char * format, ...) FORMATSTRING(1,2); /// Add the formatted string to the existing data in the string -extern AString & AppendPrintf (AString & str, const char * format, ...); +extern AString & AppendPrintf (AString & str, const char * format, ...) FORMATSTRING(2,3); /// Split the string at any of the listed delimiters, return as a stringvector extern AStringVector StringSplit(const AString & str, const AString & delim); diff --git a/src/World.cpp b/src/World.cpp index a9db6bf00..520ed9ae7 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -103,7 +103,7 @@ protected: { for (;;) { - LOG("%d chunks to load, %d chunks to generate", + LOG("%zu chunks to load, %d chunks to generate", m_World->GetStorage().GetLoadQueueLength(), m_World->GetGenerator().GetQueueLength() ); @@ -155,7 +155,7 @@ protected: { for (;;) { - LOG("%d chunks remaining to light", m_Lighting->GetQueueLength() + LOG("%zu chunks remaining to light", m_Lighting->GetQueueLength() ); // Wait for 2 sec, but be "reasonably wakeable" when the thread is to finish -- cgit v1.2.3 From 9c6ca5a3edcfbcd1e9a18eec463ce7702770ceb2 Mon Sep 17 00:00:00 2001 From: Tycho Date: Tue, 11 Mar 2014 14:43:56 -0700 Subject: made format-nonliteral an error --- SetFlags.cmake | 1 - 1 file changed, 1 deletion(-) diff --git a/SetFlags.cmake b/SetFlags.cmake index 25310c368..42cfa6769 100644 --- a/SetFlags.cmake +++ b/SetFlags.cmake @@ -199,7 +199,6 @@ macro(set_exe_flags) add_flags_cxx("-Wno-error=exit-time-destructors -Wno-error=missing-variable-declarations") add_flags_cxx("-Wno-error=global-constructors -Wno-implicit-fallthrough") add_flags_cxx("-Wno-missing-noreturn -Wno-error=unreachable-code -Wno-error=undef") - add_flags_cxx("-Wno-error=format-nonliteral") endif() endif() -- cgit v1.2.3 From 3d15319e3c125507e48a66b3cdbb30feeaa652c1 Mon Sep 17 00:00:00 2001 From: Tycho Date: Tue, 11 Mar 2014 15:55:37 -0700 Subject: Added macros support to tools --- Tools/MCADefrag/Globals.h | 5 ++++- Tools/ProtoProxy/Globals.h | 7 ++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Tools/MCADefrag/Globals.h b/Tools/MCADefrag/Globals.h index 6f4bbdc76..0f31de7e3 100644 --- a/Tools/MCADefrag/Globals.h +++ b/Tools/MCADefrag/Globals.h @@ -37,7 +37,8 @@ // Some portability macros :) #define stricmp strcasecmp - + + #define FORMATSTRING(formatIndex,va_argsIndex) #else #error "You are using an unsupported compiler, you might need to #define some stuff here for your compiler" @@ -58,6 +59,8 @@ #define ALIGN_8 #define ALIGN_16 */ + + #define FORMATSTRING(formatIndex,va_argsIndex) __attribute__((format (printf, formatIndex, va_argsIndex))) #endif diff --git a/Tools/ProtoProxy/Globals.h b/Tools/ProtoProxy/Globals.h index 547903e7a..0724d3a52 100644 --- a/Tools/ProtoProxy/Globals.h +++ b/Tools/ProtoProxy/Globals.h @@ -37,6 +37,8 @@ // Some portability macros :) #define stricmp strcasecmp + + #define FORMATSTRING(formatIndex,va_argsIndex) #else @@ -59,6 +61,9 @@ #define ALIGN_16 */ + #define FORMATSTRING(formatIndex,va_argsIndex) __attribute__((format (printf, formatIndex, va_argsIndex))) + + #endif @@ -233,4 +238,4 @@ public: #define LOGERROR printf #define LOGINFO printf -#define LOGWARNING printf \ No newline at end of file +#define LOGWARNING printf -- cgit v1.2.3 From ef58b0eb54c700800597031c37c3e76fef87cdfb Mon Sep 17 00:00:00 2001 From: Tycho Date: Wed, 12 Mar 2014 09:49:37 -0700 Subject: Fixed comments an assert --- Tools/ProtoProxy/Connection.cpp | 4 ++-- src/Globals.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Tools/ProtoProxy/Connection.cpp b/Tools/ProtoProxy/Connection.cpp index 73688d310..46119ff42 100644 --- a/Tools/ProtoProxy/Connection.cpp +++ b/Tools/ProtoProxy/Connection.cpp @@ -2772,7 +2772,7 @@ void cConnection::LogMetadata(const AString & a_Metadata, size_t a_IndentCount) { int Index = ((unsigned)((unsigned char)a_Metadata[pos])) & 0x1f; // Lower 5 bits = index int Type = ((unsigned)((unsigned char)a_Metadata[pos])) >> 5; // Upper 3 bits = type - //int Length = 0; + // int Length = 0; switch (Type) { case 0: @@ -2827,7 +2827,7 @@ void cConnection::LogMetadata(const AString & a_Metadata, size_t a_IndentCount) ASSERT(!"Cannot parse item description from metadata"); return; } - //int After = bb.GetReadableSpace(); + // int After = bb.GetReadableSpace(); int BytesConsumed = BytesLeft - bb.GetReadableSpace(); Log("%sslot[%d] = %s (%d bytes)", Indent.c_str(), Index, ItemDesc.c_str(), BytesConsumed); diff --git a/src/Globals.h b/src/Globals.h index 2cd160677..6661aa476 100644 --- a/src/Globals.h +++ b/src/Globals.h @@ -236,7 +236,7 @@ template class SizeChecker; // Same as assert but in all Self test builds #ifdef SELF_TEST -#define assert_test(x) ( !!(x) || (assert(0), exit(1), 0)) +#define assert_test(x) ( !!(x) || (assert(!#x), exit(1), 0)) #endif /// A generic interface used mainly in ForEach() functions -- cgit v1.2.3 From a584b7b3bc95783025d9861964bd987f324ba981 Mon Sep 17 00:00:00 2001 From: Tycho Date: Wed, 12 Mar 2014 10:09:08 -0700 Subject: Fixed printf format compatabilty --- src/Generating/PieceGenerator.cpp | 9 ++++----- src/Globals.h | 5 +++++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/Generating/PieceGenerator.cpp b/src/Generating/PieceGenerator.cpp index 50bfe65fe..8999a5ff7 100644 --- a/src/Generating/PieceGenerator.cpp +++ b/src/Generating/PieceGenerator.cpp @@ -31,14 +31,14 @@ public: Gen.PlacePieces(500, 50, 500, 3, OutPieces); // Print out the pieces: - printf("OutPieces.size() = %zu\n", OutPieces.size()); + printf("OutPieces.size() = " SIZE_T_FMT "\n", OutPieces.size()); size_t idx = 0; for (cPlacedPieces::const_iterator itr = OutPieces.begin(), end = OutPieces.end(); itr != end; ++itr, ++idx) { const Vector3i & Coords = (*itr)->GetCoords(); cCuboid Hitbox = (*itr)->GetHitBox(); Hitbox.Sort(); - printf("%zu: {%d, %d, %d}, rot %d, hitbox {%d, %d, %d} - {%d, %d, %d} (%d * %d * %d)\n", idx, + printf(SIZE_T_FMT ": {%d, %d, %d}, rot %d, hitbox {%d, %d, %d} - {%d, %d, %d} (%d * %d * %d)\n", idx, Coords.x, Coords.y, Coords.z, (*itr)->GetNumCCWRotations(), Hitbox.p1.x, Hitbox.p1.y, Hitbox.p1.z, @@ -502,12 +502,11 @@ bool cPieceGenerator::CheckConnection( // DEBUG: void cPieceGenerator::DebugConnectorPool(const cPieceGenerator::cFreeConnectors & a_ConnectorPool, size_t a_NumProcessed) { - printf(" Connector pool: %zu items\n", a_ConnectorPool.size() - a_NumProcessed); + printf(" Connector pool: " SIZE_T_FMT " items\n", a_ConnectorPool.size() - a_NumProcessed); size_t idx = 0; for (cPieceGenerator::cFreeConnectors::const_iterator itr = a_ConnectorPool.begin() + a_NumProcessed, end = a_ConnectorPool.end(); itr != end; ++itr, ++idx) { - // Format specifier for size_t is zu - printf(" %zu: {%d, %d, %d}, type %d, direction %s, depth %d\n", + printf(" " SIZE_T_FMT ": {%d, %d, %d}, type %d, direction %s, depth %d\n", idx, itr->m_Connector.m_Pos.x, itr->m_Connector.m_Pos.y, itr->m_Connector.m_Pos.z, itr->m_Connector.m_Type, diff --git a/src/Globals.h b/src/Globals.h index 5ced0cc39..b42a06970 100644 --- a/src/Globals.h +++ b/src/Globals.h @@ -38,6 +38,9 @@ // No alignment needed in MSVC #define ALIGN_8 #define ALIGN_16 + + // MSVC has its own custom version of zu format + #define SIZE_T_FMT "%Iu" #elif defined(__GNUC__) @@ -56,6 +59,8 @@ // Some portability macros :) #define stricmp strcasecmp + + #define SIZE_T_FMT "%zu" #else -- cgit v1.2.3 From 862e2194433b5d47aaf88261091b35a1ee663482 Mon Sep 17 00:00:00 2001 From: Tycho Date: Wed, 12 Mar 2014 10:34:50 -0700 Subject: Added additional macros to support the MSVC size_t format and changed all formats to use the macros --- src/CraftingRecipes.cpp | 2 +- src/FurnaceRecipe.cpp | 2 +- src/Generating/ChunkGenerator.cpp | 2 +- src/Globals.h | 4 ++++ src/Item.cpp | 8 ++++---- src/Log.cpp | 2 +- src/OSSupport/SocketThreads.cpp | 2 +- src/Protocol/Protocol132.cpp | 2 +- src/Protocol/Protocol17x.cpp | 12 ++++++------ src/Root.cpp | 10 +++++----- src/UI/Window.cpp | 2 +- src/World.cpp | 4 ++-- src/WorldStorage/WSSCompact.cpp | 10 +++++----- 13 files changed, 33 insertions(+), 29 deletions(-) diff --git a/src/CraftingRecipes.cpp b/src/CraftingRecipes.cpp index 30f21686c..30e7a8733 100644 --- a/src/CraftingRecipes.cpp +++ b/src/CraftingRecipes.cpp @@ -340,7 +340,7 @@ void cCraftingRecipes::LoadRecipes(void) } AddRecipeLine(LineNum, Recipe); } // for itr - Split[] - LOG("Loaded %zu crafting recipes", m_Recipes.size()); + LOG("Loaded " SIZE_T_FMT " crafting recipes", m_Recipes.size()); } diff --git a/src/FurnaceRecipe.cpp b/src/FurnaceRecipe.cpp index dd2f259f3..1810d7c49 100644 --- a/src/FurnaceRecipe.cpp +++ b/src/FurnaceRecipe.cpp @@ -175,7 +175,7 @@ void cFurnaceRecipe::ReloadRecipes(void) { LOGERROR("ERROR: FurnaceRecipe, syntax error" ); } - LOG("Loaded %zu furnace recipes and %zu fuels", m_pState->Recipes.size(), m_pState->Fuel.size()); + LOG("Loaded " SIZE_T_FMT " furnace recipes and " SIZE_T_FMT " fuels", m_pState->Recipes.size(), m_pState->Fuel.size()); } diff --git a/src/Generating/ChunkGenerator.cpp b/src/Generating/ChunkGenerator.cpp index 92f6009ac..73f0223e8 100644 --- a/src/Generating/ChunkGenerator.cpp +++ b/src/Generating/ChunkGenerator.cpp @@ -116,7 +116,7 @@ void cChunkGenerator::QueueGenerateChunk(int a_ChunkX, int a_ChunkY, int a_Chunk // Add to queue, issue a warning if too many: if (m_Queue.size() >= QUEUE_WARNING_LIMIT) { - LOGWARN("WARNING: Adding chunk [%i, %i] to generation queue; Queue is too big! (%zu)", a_ChunkX, a_ChunkZ, m_Queue.size()); + LOGWARN("WARNING: Adding chunk [%i, %i] to generation queue; Queue is too big! (" SIZE_T_FMT ")", a_ChunkX, a_ChunkZ, m_Queue.size()); } m_Queue.push_back(cChunkCoords(a_ChunkX, a_ChunkY, a_ChunkZ)); } diff --git a/src/Globals.h b/src/Globals.h index faa168c59..08d9e971a 100644 --- a/src/Globals.h +++ b/src/Globals.h @@ -43,6 +43,8 @@ // MSVC has its own custom version of zu format #define SIZE_T_FMT "%Iu" + #define SIZE_T_FMT_PRECISION(x) "%" #x "Iu" + #define SIZE_T_FMT_HEX "%Ix" #elif defined(__GNUC__) @@ -65,6 +67,8 @@ #define FORMATSTRING(formatIndex,va_argsIndex) __attribute__((format (printf, formatIndex, va_argsIndex))) #define SIZE_T_FMT "%zu" + #define SIZE_T_FMT_PRECISION(x) "%" #x "zu" + #define SIZE_T_FMT_HEX "%zx" #else diff --git a/src/Item.cpp b/src/Item.cpp index c8dda209c..856b68be6 100644 --- a/src/Item.cpp +++ b/src/Item.cpp @@ -216,7 +216,7 @@ cItem * cItems::Get(int a_Idx) { if ((a_Idx < 0) || (a_Idx >= (int)size())) { - LOGWARNING("cItems: Attempt to get an out-of-bounds item at index %d; there are currently %zu items. Returning a nil.", a_Idx, size()); + LOGWARNING("cItems: Attempt to get an out-of-bounds item at index %d; there are currently " SIZE_T_FMT " items. Returning a nil.", a_Idx, size()); return NULL; } return &at(a_Idx); @@ -230,7 +230,7 @@ void cItems::Set(int a_Idx, const cItem & a_Item) { if ((a_Idx < 0) || (a_Idx >= (int)size())) { - LOGWARNING("cItems: Attempt to set an item at an out-of-bounds index %d; there are currently %zu items. Not setting.", a_Idx, size()); + LOGWARNING("cItems: Attempt to set an item at an out-of-bounds index %d; there are currently " SIZE_T_FMT " items. Not setting.", a_Idx, size()); return; } at(a_Idx) = a_Item; @@ -244,7 +244,7 @@ void cItems::Delete(int a_Idx) { if ((a_Idx < 0) || (a_Idx >= (int)size())) { - LOGWARNING("cItems: Attempt to delete an item at an out-of-bounds index %d; there are currently %zu items. Ignoring.", a_Idx, size()); + LOGWARNING("cItems: Attempt to delete an item at an out-of-bounds index %d; there are currently " SIZE_T_FMT " items. Ignoring.", a_Idx, size()); return; } erase(begin() + a_Idx); @@ -258,7 +258,7 @@ void cItems::Set(int a_Idx, short a_ItemType, char a_ItemCount, short a_ItemDama { if ((a_Idx < 0) || (a_Idx >= (int)size())) { - LOGWARNING("cItems: Attempt to set an item at an out-of-bounds index %d; there are currently %zu items. Not setting.", a_Idx, size()); + LOGWARNING("cItems: Attempt to set an item at an out-of-bounds index %d; there are currently " SIZE_T_FMT " items. Not setting.", a_Idx, size()); return; } at(a_Idx) = cItem(a_ItemType, a_ItemCount, a_ItemDamage); diff --git a/src/Log.cpp b/src/Log.cpp index 54e2b7812..395326398 100644 --- a/src/Log.cpp +++ b/src/Log.cpp @@ -118,7 +118,7 @@ void cLog::Log(const char * a_Format, va_list argList) AString Line; #ifdef _DEBUG - Printf(Line, "[%04zu|%02d:%02d:%02d] %s", cIsThread::GetCurrentID(), timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, Message.c_str()); + Printf(Line, "[" SIZE_T_FMT_PRECISION(04) "|%02d:%02d:%02d] %s", cIsThread::GetCurrentID(), timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, Message.c_str()); #else Printf(Line, "[%02d:%02d:%02d] %s", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, Message.c_str()); #endif diff --git a/src/OSSupport/SocketThreads.cpp b/src/OSSupport/SocketThreads.cpp index f37b00202..0bc1d6b55 100644 --- a/src/OSSupport/SocketThreads.cpp +++ b/src/OSSupport/SocketThreads.cpp @@ -54,7 +54,7 @@ bool cSocketThreads::AddClient(const cSocket & a_Socket, cCallback * a_Client) } // No thread has free space, create a new one: - LOGD("Creating a new cSocketThread (currently have %zu)", m_Threads.size()); + LOGD("Creating a new cSocketThread (currently have " SIZE_T_FMT ")", m_Threads.size()); cSocketThread * Thread = new cSocketThread(this); if (!Thread->Start()) { diff --git a/src/Protocol/Protocol132.cpp b/src/Protocol/Protocol132.cpp index 43fe90616..be9c503ed 100644 --- a/src/Protocol/Protocol132.cpp +++ b/src/Protocol/Protocol132.cpp @@ -100,7 +100,7 @@ cProtocol132::~cProtocol132() { if (!m_DataToSend.empty()) { - LOGD("There are %zu unsent bytes while deleting cProtocol132", m_DataToSend.size()); + LOGD("There are " SIZE_T_FMT " unsent bytes while deleting cProtocol132", m_DataToSend.size()); } } diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index 9e5fe53fb..6fc344eaf 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -1251,7 +1251,7 @@ void cProtocol172::AddReceivedData(const char * a_Data, int a_Size) ASSERT(m_ReceivedData.GetReadableSpace() == OldReadableSpace); AString Hex; CreateHexDump(Hex, AllData.data(), AllData.size(), 16); - m_CommLogFile.Printf("Incoming data, %zu (0x%zx) unparsed bytes already present in buffer:\n%s\n", + m_CommLogFile.Printf("Incoming data, " SIZE_T_FMT " (0x" SIZE_T_FMT_HEX ") unparsed bytes already present in buffer:\n%s\n", AllData.size(), AllData.size(), Hex.c_str() ); } @@ -1344,14 +1344,14 @@ void cProtocol172::AddReceivedData(const char * a_Data, int a_Size) if (bb.GetReadableSpace() != 1) { // Read more or less than packet length, report as error - LOGWARNING("Protocol 1.7: Wrong number of bytes read for packet 0x%x, state %d. Read %zu bytes, packet contained %u bytes", + LOGWARNING("Protocol 1.7: Wrong number of bytes read for packet 0x%x, state %d. Read " SIZE_T_FMT " bytes, packet contained %u bytes", PacketType, m_State, bb.GetUsedSpace() - bb.GetReadableSpace(), PacketLen ); // Put a message in the comm log: if (g_ShouldLogCommIn) { - m_CommLogFile.Printf("^^^^^^ Wrong number of bytes read for this packet (exp %d left, got %zu left) ^^^^^^\n\n\n", + m_CommLogFile.Printf("^^^^^^ Wrong number of bytes read for this packet (exp %d left, got " SIZE_T_FMT " left) ^^^^^^\n\n\n", 1, bb.GetReadableSpace() ); m_CommLogFile.Flush(); @@ -1373,7 +1373,7 @@ void cProtocol172::AddReceivedData(const char * a_Data, int a_Size) ASSERT(m_ReceivedData.GetReadableSpace() == OldReadableSpace); AString Hex; CreateHexDump(Hex, AllData.data(), AllData.size(), 16); - m_CommLogFile.Printf("There are %zu (0x%zx) bytes of non-parse-able data left in the buffer:\n%s", + m_CommLogFile.Printf("There are " SIZE_T_FMT " (0x" SIZE_T_FMT_HEX ") bytes of non-parse-able data left in the buffer:\n%s", m_ReceivedData.GetReadableSpace(), m_ReceivedData.GetReadableSpace(), Hex.c_str() ); m_CommLogFile.Flush(); @@ -2062,7 +2062,7 @@ void cProtocol172::ParseItemMetadata(cItem & a_Item, const AString & a_Metadata) { AString HexDump; CreateHexDump(HexDump, a_Metadata.data(), a_Metadata.size(), 16); - LOGWARNING("Cannot unGZIP item metadata (%zu bytes):\n%s", a_Metadata.size(), HexDump.c_str()); + LOGWARNING("Cannot unGZIP item metadata (" SIZE_T_FMT " bytes):\n%s", a_Metadata.size(), HexDump.c_str()); return; } @@ -2072,7 +2072,7 @@ void cProtocol172::ParseItemMetadata(cItem & a_Item, const AString & a_Metadata) { AString HexDump; CreateHexDump(HexDump, Uncompressed.data(), Uncompressed.size(), 16); - LOGWARNING("Cannot parse NBT item metadata: (%zu bytes)\n%s", Uncompressed.size(), HexDump.c_str()); + LOGWARNING("Cannot parse NBT item metadata: (" SIZE_T_FMT " bytes)\n%s", Uncompressed.size(), HexDump.c_str()); return; } diff --git a/src/Root.cpp b/src/Root.cpp index 9a5dcac71..3555afb45 100644 --- a/src/Root.cpp +++ b/src/Root.cpp @@ -778,11 +778,11 @@ void cRoot::LogChunkStats(cCommandOutputCallback & a_Output) int Mem = NumValid * sizeof(cChunk); a_Output.Out(" Memory used by chunks: %d KiB (%d MiB)", (Mem + 1023) / 1024, (Mem + 1024 * 1024 - 1) / (1024 * 1024)); a_Output.Out(" Per-chunk memory size breakdown:"); - a_Output.Out(" block types: %6zu bytes (%3zu KiB)", sizeof(cChunkDef::BlockTypes), (sizeof(cChunkDef::BlockTypes) + 1023) / 1024); - a_Output.Out(" block metadata: %6zu bytes (%3zu KiB)", sizeof(cChunkDef::BlockNibbles), (sizeof(cChunkDef::BlockNibbles) + 1023) / 1024); - a_Output.Out(" block lighting: %6zu bytes (%3zu KiB)", 2 * sizeof(cChunkDef::BlockNibbles), (2 * sizeof(cChunkDef::BlockNibbles) + 1023) / 1024); - a_Output.Out(" heightmap: %6zu bytes (%3zu KiB)", sizeof(cChunkDef::HeightMap), (sizeof(cChunkDef::HeightMap) + 1023) / 1024); - a_Output.Out(" biomemap: %6zu bytes (%3zu KiB)", sizeof(cChunkDef::BiomeMap), (sizeof(cChunkDef::BiomeMap) + 1023) / 1024); + a_Output.Out(" block types: " SIZE_T_FMT_PRECISION(6) " bytes (" SIZE_T_FMT_PRECISION(3) " KiB)", sizeof(cChunkDef::BlockTypes), (sizeof(cChunkDef::BlockTypes) + 1023) / 1024); + a_Output.Out(" block metadata: " SIZE_T_FMT_PRECISION(6) " bytes (" SIZE_T_FMT_PRECISION(3) " KiB)", sizeof(cChunkDef::BlockNibbles), (sizeof(cChunkDef::BlockNibbles) + 1023) / 1024); + a_Output.Out(" block lighting: " SIZE_T_FMT_PRECISION(6) " bytes (" SIZE_T_FMT_PRECISION(3) " KiB)", 2 * sizeof(cChunkDef::BlockNibbles), (2 * sizeof(cChunkDef::BlockNibbles) + 1023) / 1024); + a_Output.Out(" heightmap: " SIZE_T_FMT_PRECISION(6) " bytes (" SIZE_T_FMT_PRECISION(3) " KiB)", sizeof(cChunkDef::HeightMap), (sizeof(cChunkDef::HeightMap) + 1023) / 1024); + a_Output.Out(" biomemap: " SIZE_T_FMT_PRECISION(6) " bytes (" SIZE_T_FMT_PRECISION(3) " KiB)", sizeof(cChunkDef::BiomeMap), (sizeof(cChunkDef::BiomeMap) + 1023) / 1024); int Rest = sizeof(cChunk) - sizeof(cChunkDef::BlockTypes) - 3 * sizeof(cChunkDef::BlockNibbles) - sizeof(cChunkDef::HeightMap) - sizeof(cChunkDef::BiomeMap); a_Output.Out(" other: %6d bytes (%3d KiB)", Rest, (Rest + 1023) / 1024); SumNumValid += NumValid; diff --git a/src/UI/Window.cpp b/src/UI/Window.cpp index 5249a4bca..aae7b99a3 100644 --- a/src/UI/Window.cpp +++ b/src/UI/Window.cpp @@ -637,7 +637,7 @@ int cWindow::DistributeItemToSlots(cPlayer & a_Player, const cItem & a_Item, int { if ((size_t)(a_Item.m_ItemCount) < a_SlotNums.size()) { - LOGWARNING("%s: Distributing less items (%d) than slots (%zu)", __FUNCTION__, (int)a_Item.m_ItemCount, a_SlotNums.size()); + LOGWARNING("%s: Distributing less items (%d) than slots (" SIZE_T_FMT ")", __FUNCTION__, (int)a_Item.m_ItemCount, a_SlotNums.size()); // This doesn't seem to happen with the 1.5.1 client, so we don't worry about it for now return 0; } diff --git a/src/World.cpp b/src/World.cpp index 3a6e63e57..8c3a1ff8a 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -102,7 +102,7 @@ protected: { for (;;) { - LOG("%zu chunks to load, %d chunks to generate", + LOG("" SIZE_T_FMT " chunks to load, %d chunks to generate", m_World->GetStorage().GetLoadQueueLength(), m_World->GetGenerator().GetQueueLength() ); @@ -154,7 +154,7 @@ protected: { for (;;) { - LOG("%zu chunks remaining to light", m_Lighting->GetQueueLength() + LOG("" SIZE_T_FMT " chunks remaining to light", m_Lighting->GetQueueLength() ); // Wait for 2 sec, but be "reasonably wakeable" when the thread is to finish diff --git a/src/WorldStorage/WSSCompact.cpp b/src/WorldStorage/WSSCompact.cpp index b1e8d12b7..bb9d4b9e6 100644 --- a/src/WorldStorage/WSSCompact.cpp +++ b/src/WorldStorage/WSSCompact.cpp @@ -569,7 +569,7 @@ void cWSSCompact::cPAKFile::UpdateChunk1To2() if( ChunksConverted % 32 == 0 ) { - LOGINFO("Updating \"%s\" version 1 to version 2: %zu %%", m_FileName.c_str(), (ChunksConverted * 100) / m_ChunkHeaders.size() ); + LOGINFO("Updating \"%s\" version 1 to version 2: " SIZE_T_FMT " %%", m_FileName.c_str(), (ChunksConverted * 100) / m_ChunkHeaders.size() ); } ChunksConverted++; @@ -607,7 +607,7 @@ void cWSSCompact::cPAKFile::UpdateChunk1To2() if (UncompressedSize != (int)UncompressedData.size()) { - LOGWARNING("Uncompressed data size differs (exp %d bytes, got %zu) for chunk [%d, %d]", + LOGWARNING("Uncompressed data size differs (exp %d bytes, got " SIZE_T_FMT ") for chunk [%d, %d]", UncompressedSize, UncompressedData.size(), Header->m_ChunkX, Header->m_ChunkZ ); @@ -713,7 +713,7 @@ void cWSSCompact::cPAKFile::UpdateChunk2To3() if( ChunksConverted % 32 == 0 ) { - LOGINFO("Updating \"%s\" version 2 to version 3: %zu %%", m_FileName.c_str(), (ChunksConverted * 100) / m_ChunkHeaders.size() ); + LOGINFO("Updating \"%s\" version 2 to version 3: " SIZE_T_FMT " %%", m_FileName.c_str(), (ChunksConverted * 100) / m_ChunkHeaders.size() ); } ChunksConverted++; @@ -751,7 +751,7 @@ void cWSSCompact::cPAKFile::UpdateChunk2To3() if (UncompressedSize != (int)UncompressedData.size()) { - LOGWARNING("Uncompressed data size differs (exp %d bytes, got %zu) for chunk [%d, %d]", + LOGWARNING("Uncompressed data size differs (exp %d bytes, got " SIZE_T_FMT ") for chunk [%d, %d]", UncompressedSize, UncompressedData.size(), Header->m_ChunkX, Header->m_ChunkZ ); @@ -866,7 +866,7 @@ bool cWSSCompact::LoadChunkFromData(const cChunkCoords & a_Chunk, int & a_Uncomp if (a_UncompressedSize != (int)UncompressedData.size()) { - LOGWARNING("Uncompressed data size differs (exp %d bytes, got %zu) for chunk [%d, %d]", + LOGWARNING("Uncompressed data size differs (exp %d bytes, got " SIZE_T_FMT ") for chunk [%d, %d]", a_UncompressedSize, UncompressedData.size(), a_Chunk.m_ChunkX, a_Chunk.m_ChunkZ ); -- cgit v1.2.3 From 9a28d1bbe1fc85981ded03e1d190612e6a688b5e Mon Sep 17 00:00:00 2001 From: Tycho Date: Wed, 12 Mar 2014 11:56:24 -0700 Subject: Fixed comma --- src/Globals.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Globals.h b/src/Globals.h index 08d9e971a..45d403f27 100644 --- a/src/Globals.h +++ b/src/Globals.h @@ -39,7 +39,7 @@ #define ALIGN_8 #define ALIGN_16 - #define FORMATSTRING(formatIndex,va_argsIndex) + #define FORMATSTRING(formatIndex, va_argsIndex) // MSVC has its own custom version of zu format #define SIZE_T_FMT "%Iu" @@ -64,7 +64,7 @@ // Some portability macros :) #define stricmp strcasecmp - #define FORMATSTRING(formatIndex,va_argsIndex) __attribute__((format (printf, formatIndex, va_argsIndex))) + #define FORMATSTRING(formatIndex, va_argsIndex) __attribute__((format (printf, formatIndex, va_argsIndex))) #define SIZE_T_FMT "%zu" #define SIZE_T_FMT_PRECISION(x) "%" #x "zu" -- cgit v1.2.3 From cd6ab5617cd7b26b13cfe26a950ca17fecefd550 Mon Sep 17 00:00:00 2001 From: Tycho Date: Fri, 14 Mar 2014 06:11:49 -0700 Subject: Fixed xofts issues --- src/ByteBuffer.cpp | 2 +- src/CommandOutput.cpp | 4 ++-- src/CommandOutput.h | 2 +- src/Generating/PieceGenerator.h | 4 ++-- src/Globals.h | 3 ++- src/Log.cpp | 2 +- src/Log.h | 4 ++-- src/MCLogger.h | 16 ++++++++-------- src/OSSupport/File.h | 2 +- src/StringUtils.h | 8 ++++---- 10 files changed, 24 insertions(+), 23 deletions(-) diff --git a/src/ByteBuffer.cpp b/src/ByteBuffer.cpp index d3bcfe866..1893d89a8 100644 --- a/src/ByteBuffer.cpp +++ b/src/ByteBuffer.cpp @@ -767,7 +767,7 @@ bool cByteBuffer::ReadUTF16String(AString & a_String, int a_NumChars) { return false; } - RawBEToUTF8((RawData.data()), a_NumChars, a_String); + RawBEToUTF8(RawData.data(), a_NumChars, a_String); return true; } diff --git a/src/CommandOutput.cpp b/src/CommandOutput.cpp index 74f857284..2c116b3d6 100644 --- a/src/CommandOutput.cpp +++ b/src/CommandOutput.cpp @@ -51,7 +51,7 @@ void cLogCommandOutputCallback::Finished(void) { case '\n': { - LOG("%s",m_Buffer.substr(last, i - last).c_str()); + LOG("%s", m_Buffer.substr(last, i - last).c_str()); last = i + 1; break; } @@ -59,7 +59,7 @@ void cLogCommandOutputCallback::Finished(void) } // for i - m_Buffer[] if (last < len) { - LOG("%s",m_Buffer.substr(last).c_str()); + LOG("%s", m_Buffer.substr(last).c_str()); } // Clear the buffer for the next command output: diff --git a/src/CommandOutput.h b/src/CommandOutput.h index 81d9ddb84..5682b4fd8 100644 --- a/src/CommandOutput.h +++ b/src/CommandOutput.h @@ -17,7 +17,7 @@ public: virtual ~cCommandOutputCallback() {}; // Force a virtual destructor in subclasses /// Syntax sugar function, calls Out() with Printf()-ed parameters; appends a "\n" - void Out(const char * a_Fmt, ...) FORMATSTRING(2,3); + void Out(const char * a_Fmt, ...) FORMATSTRING(2, 3); /// Called when the command wants to output anything; may be called multiple times virtual void Out(const AString & a_Text) = 0; diff --git a/src/Generating/PieceGenerator.h b/src/Generating/PieceGenerator.h index 3386d7a94..bef9d3463 100644 --- a/src/Generating/PieceGenerator.h +++ b/src/Generating/PieceGenerator.h @@ -122,9 +122,9 @@ public: const cPiece & GetPiece (void) const { return *m_Piece; } const Vector3i & GetCoords (void) const { return m_Coords; } - int GetNumCCWRotations(void) const { return m_NumCCWRotations; } + int GetNumCCWRotations(void) const { return m_NumCCWRotations; } const cCuboid & GetHitBox (void) const { return m_HitBox; } - int GetDepth (void) const { return m_Depth; } + int GetDepth (void) const { return m_Depth; } protected: const cPlacedPiece * m_Parent; diff --git a/src/Globals.h b/src/Globals.h index 45d403f27..c2542f0d8 100644 --- a/src/Globals.h +++ b/src/Globals.h @@ -114,7 +114,8 @@ template class SizeChecker; template -class SizeChecker { +class SizeChecker +{ T v; }; diff --git a/src/Log.cpp b/src/Log.cpp index 395326398..a7be04b1a 100644 --- a/src/Log.cpp +++ b/src/Log.cpp @@ -118,7 +118,7 @@ void cLog::Log(const char * a_Format, va_list argList) AString Line; #ifdef _DEBUG - Printf(Line, "[" SIZE_T_FMT_PRECISION(04) "|%02d:%02d:%02d] %s", cIsThread::GetCurrentID(), timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, Message.c_str()); + Printf(Line, "[%04lx|%02d:%02d:%02d] %s", cIsThread::GetCurrentID(), timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, Message.c_str()); #else Printf(Line, "[%02d:%02d:%02d] %s", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, Message.c_str()); #endif diff --git a/src/Log.h b/src/Log.h index 340fa23bc..d6a406154 100644 --- a/src/Log.h +++ b/src/Log.h @@ -14,8 +14,8 @@ private: public: cLog(const AString & a_FileName); ~cLog(); - void Log(const char * a_Format, va_list argList) FORMATSTRING(2,0); - void Log(const char * a_Format, ...) FORMATSTRING(2,3); + void Log(const char * a_Format, va_list argList) FORMATSTRING(2, 0); + void Log(const char * a_Format, ...) FORMATSTRING(2, 3); // tolua_begin void SimpleLog(const char * a_String); void OpenLog(const char * a_FileName); diff --git a/src/MCLogger.h b/src/MCLogger.h index ba9e4827f..996e60329 100644 --- a/src/MCLogger.h +++ b/src/MCLogger.h @@ -21,10 +21,10 @@ public: // tolua_export ~cMCLogger(); // tolua_export - void Log(const char* a_Format, va_list a_ArgList) FORMATSTRING(2,0); - void Info(const char* a_Format, va_list a_ArgList) FORMATSTRING(2,0); - void Warn(const char* a_Format, va_list a_ArgList) FORMATSTRING(2,0); - void Error(const char* a_Format, va_list a_ArgList) FORMATSTRING(2,0); + void Log(const char* a_Format, va_list a_ArgList) FORMATSTRING(2, 0); + void Info(const char* a_Format, va_list a_ArgList) FORMATSTRING(2, 0); + void Warn(const char* a_Format, va_list a_ArgList) FORMATSTRING(2, 0); + void Error(const char* a_Format, va_list a_ArgList) FORMATSTRING(2, 0); void LogSimple(const char* a_Text, int a_LogType = 0 ); // tolua_export @@ -57,10 +57,10 @@ private: -extern void LOG(const char* a_Format, ...) FORMATSTRING(1,2); -extern void LOGINFO(const char* a_Format, ...) FORMATSTRING(1,2); -extern void LOGWARN(const char* a_Format, ...) FORMATSTRING(1,2); -extern void LOGERROR(const char* a_Format, ...) FORMATSTRING(1,2); +extern void LOG(const char* a_Format, ...) FORMATSTRING(1, 2); +extern void LOGINFO(const char* a_Format, ...) FORMATSTRING(1, 2); +extern void LOGWARN(const char* a_Format, ...) FORMATSTRING(1, 2); +extern void LOGERROR(const char* a_Format, ...) FORMATSTRING(1, 2); diff --git a/src/OSSupport/File.h b/src/OSSupport/File.h index e229035b7..b394c5cb9 100644 --- a/src/OSSupport/File.h +++ b/src/OSSupport/File.h @@ -131,7 +131,7 @@ public: /** Returns the list of all items in the specified folder (files, folders, nix pipes, whatever's there). */ static AStringVector GetFolderContents(const AString & a_Folder); // Exported in ManualBindings.cpp - int Printf(const char * a_Fmt, ...) FORMATSTRING(2,3); + int Printf(const char * a_Fmt, ...) FORMATSTRING(2, 3); /** Flushes all the bufferef output into the file (only when writing) */ void Flush(void); diff --git a/src/StringUtils.h b/src/StringUtils.h index 728ce31e6..4feff7553 100644 --- a/src/StringUtils.h +++ b/src/StringUtils.h @@ -22,16 +22,16 @@ typedef std::list AStringList; /** Add the formated string to the existing data in the string */ -extern AString & AppendVPrintf(AString & str, const char * format, va_list args) FORMATSTRING(2,0); +extern AString & AppendVPrintf(AString & str, const char * format, va_list args) FORMATSTRING(2, 0); /// Output the formatted text into the string -extern AString & Printf (AString & str, const char * format, ...) FORMATSTRING(2,3); +extern AString & Printf (AString & str, const char * format, ...) FORMATSTRING(2, 3); /// Output the formatted text into string, return string by value -extern AString Printf(const char * format, ...) FORMATSTRING(1,2); +extern AString Printf(const char * format, ...) FORMATSTRING(1, 2); /// Add the formatted string to the existing data in the string -extern AString & AppendPrintf (AString & str, const char * format, ...) FORMATSTRING(2,3); +extern AString & AppendPrintf (AString & str, const char * format, ...) FORMATSTRING(2, 3); /// Split the string at any of the listed delimiters, return as a stringvector extern AStringVector StringSplit(const AString & str, const AString & delim); -- cgit v1.2.3