1
0

Merge pull request #798 from worktycho/warnings

Fixed Format string warnings
This commit is contained in:
worktycho 2014-03-14 14:34:29 +00:00
commit b8cffe569f
45 changed files with 224 additions and 202 deletions

View File

@ -182,14 +182,23 @@ macro(set_exe_flags)
string(REPLACE "-w" "" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}") 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_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
string(REPLACE "-w" "" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}") string(REPLACE "-w" "" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}")
add_flags_cxx("-Wall -Wextra") add_flags_cxx("-Wall -Wextra -Wno-unused-parameter -Wno-error=switch")
# we support non-IEEE 754 fpus so can make no guarentees about error # we support non-IEEE 754 fpus so can make no guarentees about error
add_flags_cxx("-ffast-math") 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") 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("-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")
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")
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")
endif() endif()
endif() endif()

View File

@ -37,7 +37,8 @@
// Some portability macros :) // Some portability macros :)
#define stricmp strcasecmp #define stricmp strcasecmp
#define FORMATSTRING(formatIndex,va_argsIndex)
#else #else
#error "You are using an unsupported compiler, you might need to #define some stuff here for your compiler" #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_8
#define ALIGN_16 #define ALIGN_16
*/ */
#define FORMATSTRING(formatIndex,va_argsIndex) __attribute__((format (printf, formatIndex, va_argsIndex)))
#endif #endif

View File

@ -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); DataLog(a_Data, a_Size, "Encrypting %d bytes to %s", a_Size, a_Peer);
const Byte * Data = (const Byte *)a_Data; const Byte * Data = (const Byte *)a_Data;
while (a_Size > 0) while (a_Size > 0)
{ {
Byte Buffer[64 KiB]; 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); a_Encryptor.ProcessData(Buffer, Data, NumBytes);
bool res = SendData(a_Socket, (const char *)Buffer, NumBytes, a_Peer); bool res = SendData(a_Socket, (const char *)Buffer, NumBytes, a_Peer);
if (!res) if (!res)
@ -2263,7 +2261,9 @@ bool cConnection::HandleServerSpawnObjectVehicle(void)
HANDLE_SERVER_PACKET_READ(ReadByte, Byte, Yaw); HANDLE_SERVER_PACKET_READ(ReadByte, Byte, Yaw);
HANDLE_SERVER_PACKET_READ(ReadBEInt, int, DataIndicator); HANDLE_SERVER_PACKET_READ(ReadBEInt, int, DataIndicator);
AString ExtraData; AString ExtraData;
short VelocityX, VelocityY, VelocityZ; short VelocityX = 0;
short VelocityY = 0;
short VelocityZ = 0;
if (DataIndicator != 0) if (DataIndicator != 0)
{ {
HANDLE_SERVER_PACKET_READ(ReadBEShort, short, SpeedX); 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); a_Metadata.push_back(x);
while (x != 0x7f) 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 Type = ((unsigned)((unsigned char)x)) >> 5; // Upper 3 bits = type
int Length = 0; int Length = 0;
switch (Type) 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 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 Type = ((unsigned)((unsigned char)a_Metadata[pos])) >> 5; // Upper 3 bits = type
int Length = 0; // int Length = 0;
switch (Type) switch (Type)
{ {
case 0: case 0:
@ -2827,7 +2827,7 @@ void cConnection::LogMetadata(const AString & a_Metadata, size_t a_IndentCount)
ASSERT(!"Cannot parse item description from metadata"); ASSERT(!"Cannot parse item description from metadata");
return; return;
} }
int After = bb.GetReadableSpace(); // int After = bb.GetReadableSpace();
int BytesConsumed = BytesLeft - bb.GetReadableSpace(); int BytesConsumed = BytesLeft - bb.GetReadableSpace();
Log("%sslot[%d] = %s (%d bytes)", Indent.c_str(), Index, ItemDesc.c_str(), BytesConsumed); Log("%sslot[%d] = %s (%d bytes)", Indent.c_str(), Index, ItemDesc.c_str(), BytesConsumed);

View File

@ -109,7 +109,7 @@ protected:
bool SendData(SOCKET a_Socket, cByteBuffer & a_Data, const char * a_Peer); 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 /// 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 /// 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); bool SendEncryptedData(SOCKET a_Socket, cAESCFBEncryptor & a_Encryptor, cByteBuffer & a_Data, const char * a_Peer);

View File

@ -37,6 +37,8 @@
// Some portability macros :) // Some portability macros :)
#define stricmp strcasecmp #define stricmp strcasecmp
#define FORMATSTRING(formatIndex,va_argsIndex)
#else #else
@ -59,6 +61,9 @@
#define ALIGN_16 #define ALIGN_16
*/ */
#define FORMATSTRING(formatIndex,va_argsIndex) __attribute__((format (printf, formatIndex, va_argsIndex)))
#endif #endif
@ -233,4 +238,4 @@ public:
#define LOGERROR printf #define LOGERROR printf
#define LOGINFO printf #define LOGINFO printf
#define LOGWARNING printf #define LOGWARNING printf

View File

@ -1285,7 +1285,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 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--) for (int i = lua_gettop(a_LuaState); i > 0; i--)
{ {
AString Value; AString Value;

View File

@ -62,11 +62,11 @@ public:
cByteBuffer buf(50); cByteBuffer buf(50);
buf.Write("\x05\xac\x02\x00", 4); buf.Write("\x05\xac\x02\x00", 4);
UInt32 v1; UInt32 v1;
assert(buf.ReadVarInt(v1) && (v1 == 5)); assert_test(buf.ReadVarInt(v1) && (v1 == 5));
UInt32 v2; UInt32 v2;
assert(buf.ReadVarInt(v2) && (v2 == 300)); assert_test(buf.ReadVarInt(v2) && (v2 == 300));
UInt32 v3; UInt32 v3;
assert(buf.ReadVarInt(v3) && (v3 == 0)); assert_test(buf.ReadVarInt(v3) && (v3 == 0));
} }
void TestWrite(void) void TestWrite(void)
@ -77,8 +77,8 @@ public:
buf.WriteVarInt(0); buf.WriteVarInt(0);
AString All; AString All;
buf.ReadAll(All); buf.ReadAll(All);
assert(All.size() == 4); assert_test(All.size() == 4);
assert(memcmp(All.data(), "\x05\xac\x02\x00", All.size()) == 0); assert_test(memcmp(All.data(), "\x05\xac\x02\x00", All.size()) == 0);
} }
void TestWrap(void) void TestWrap(void)
@ -87,17 +87,17 @@ public:
for (int i = 0; i < 1000; i++) for (int i = 0; i < 1000; i++)
{ {
size_t FreeSpace = buf.GetFreeSpace(); size_t FreeSpace = buf.GetFreeSpace();
assert(buf.GetReadableSpace() == 0); assert_test(buf.GetReadableSpace() == 0);
assert(FreeSpace > 0); assert_test(FreeSpace > 0);
assert(buf.Write("a", 1)); assert_test(buf.Write("a", 1));
assert(buf.CanReadBytes(1)); assert_test(buf.CanReadBytes(1));
assert(buf.GetReadableSpace() == 1); assert_test(buf.GetReadableSpace() == 1);
unsigned char v = 0; unsigned char v = 0;
assert(buf.ReadByte(v)); assert_test(buf.ReadByte(v));
assert(v == 'a'); assert_test(v == 'a');
assert(buf.GetReadableSpace() == 0); assert_test(buf.GetReadableSpace() == 0);
buf.CommitRead(); buf.CommitRead();
assert(buf.GetFreeSpace() == FreeSpace); // We're back to normal assert_test(buf.GetFreeSpace() == FreeSpace); // We're back to normal
} }
} }
@ -459,7 +459,7 @@ bool cByteBuffer::ReadVarUTF8String(AString & a_Value)
} }
if (Size > MAX_STRING_SIZE) 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); return ReadString(a_Value, (int)Size);
} }
@ -767,7 +767,7 @@ bool cByteBuffer::ReadUTF16String(AString & a_String, int a_NumChars)
{ {
return false; return false;
} }
RawBEToUTF8((short *)(RawData.data()), a_NumChars, a_String); RawBEToUTF8(RawData.data(), a_NumChars, a_String);
return true; return true;
} }

View File

@ -43,7 +43,7 @@ public:
size_t GetReadableSpace(void) const; size_t GetReadableSpace(void) const;
/// Returns the current data start index. For debugging purposes. /// 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 /// Returns true if the specified amount of bytes are available for reading
bool CanReadBytes(size_t a_Count) const; bool CanReadBytes(size_t a_Count) const;

View File

@ -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 ( if (
(x < Width) && (x > -1) && (x < Width) && (x > -1) &&
@ -128,7 +128,7 @@ public:
} }
inline static unsigned int MakeIndexNoCheck(int x, int y, int z) inline static int MakeIndexNoCheck(int x, int y, int z)
{ {
#if AXIS_ORDER == AXIS_ORDER_XZY #if AXIS_ORDER == AXIS_ORDER_XZY
// For some reason, NOT using the Horner schema is faster. Weird. // For some reason, NOT using the Horner schema is faster. Weird.
@ -251,7 +251,7 @@ public:
ASSERT(!"cChunkDef::SetNibble(): index out of range!"); ASSERT(!"cChunkDef::SetNibble(): index out of range!");
return; return;
} }
a_Buffer[a_BlockIdx / 2] = ( a_Buffer[a_BlockIdx / 2] = static_cast<NIBBLETYPE>(
(a_Buffer[a_BlockIdx / 2] & (0xf0 >> ((a_BlockIdx & 1) * 4))) | // The untouched nibble (a_Buffer[a_BlockIdx / 2] & (0xf0 >> ((a_BlockIdx & 1) * 4))) | // The untouched nibble
((a_Nibble & 0x0f) << ((a_BlockIdx & 1) * 4)) // The nibble being set ((a_Nibble & 0x0f) << ((a_BlockIdx & 1) * 4)) // The nibble being set
); );
@ -271,20 +271,20 @@ public:
} }
int Index = MakeIndexNoCheck(x, y, z); int Index = MakeIndexNoCheck(x, y, z);
a_Buffer[Index / 2] = ( a_Buffer[Index / 2] = static_cast<NIBBLETYPE>(
(a_Buffer[Index / 2] & (0xf0 >> ((Index & 1) * 4))) | // The untouched nibble (a_Buffer[Index / 2] & (0xf0 >> ((Index & 1) * 4))) | // The untouched nibble
((a_Nibble & 0x0f) << ((Index & 1) * 4)) // The nibble being set ((a_Nibble & 0x0f) << ((Index & 1) * 4)) // The nibble being set
); );
} }
inline static char GetNibble(const NIBBLETYPE * a_Buffer, const Vector3i & a_BlockPos ) inline static NIBBLETYPE GetNibble(const NIBBLETYPE * a_Buffer, const Vector3i & a_BlockPos )
{ {
return GetNibble(a_Buffer, a_BlockPos.x, a_BlockPos.y, a_BlockPos.z ); return GetNibble(a_Buffer, a_BlockPos.x, a_BlockPos.y, a_BlockPos.z );
} }
inline static void SetNibble(NIBBLETYPE * a_Buffer, const Vector3i & a_BlockPos, char a_Value ) inline static void SetNibble(NIBBLETYPE * a_Buffer, const Vector3i & a_BlockPos, NIBBLETYPE a_Value )
{ {
SetNibble( a_Buffer, a_BlockPos.x, a_BlockPos.y, a_BlockPos.z, a_Value ); SetNibble( a_Buffer, a_BlockPos.x, a_BlockPos.y, a_BlockPos.z, a_Value );
} }
@ -302,6 +302,9 @@ The virtual methods are called in the same order as they're declared here.
class cChunkDataCallback abstract class cChunkDataCallback abstract
{ {
public: public:
virtual ~cChunkDataCallback() {}
/** Called before any other callbacks to inform of the current coords /** Called before any other callbacks to inform of the current coords
(only in processes where multiple chunks can be processed, such as cWorld::ForEachChunkInRect()). (only in processes where multiple chunks can be processed, such as cWorld::ForEachChunkInRect()).
If false is returned, the chunk is skipped. If false is returned, the chunk is skipped.
@ -428,6 +431,9 @@ Used primarily for entity moving while both chunks are locked.
class cClientDiffCallback class cClientDiffCallback
{ {
public: public:
virtual ~cClientDiffCallback() {}
/// Called for clients that are in Chunk1 and not in Chunk2, /// Called for clients that are in Chunk1 and not in Chunk2,
virtual void Removed(cClientHandle * a_Client) = 0; virtual void Removed(cClientHandle * a_Client) = 0;
@ -488,6 +494,9 @@ typedef std::vector<cChunkCoords> cChunkCoordsVector;
class cChunkCoordCallback class cChunkCoordCallback
{ {
public: public:
virtual ~cChunkCoordCallback() {}
virtual void Call(int a_ChunkX, int a_ChunkZ) = 0; virtual void Call(int a_ChunkX, int a_ChunkZ) = 0;
} ; } ;

View File

@ -33,19 +33,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 */ /** Maximum number of explosions to send this tick, server will start dropping if exceeded */
#define MAX_EXPLOSIONS_PER_TICK 20 #define MAX_EXPLOSIONS_PER_TICK 20
@ -892,7 +879,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)", 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, a_BlockX, a_BlockY, a_BlockZ,
m_LastDigBlockX, m_LastDigBlockY, m_LastDigBlockZ, m_LastDigBlockX, m_LastDigBlockY, m_LastDigBlockZ,
m_HasStartedDigging (m_HasStartedDigging ? "True" : "False")
); );
return; return;
} }

View File

@ -51,7 +51,7 @@ void cLogCommandOutputCallback::Finished(void)
{ {
case '\n': case '\n':
{ {
LOG(m_Buffer.substr(last, i - last).c_str()); LOG("%s", m_Buffer.substr(last, i - last).c_str());
last = i + 1; last = i + 1;
break; break;
} }
@ -59,7 +59,7 @@ void cLogCommandOutputCallback::Finished(void)
} // for i - m_Buffer[] } // for i - m_Buffer[]
if (last < len) 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: // Clear the buffer for the next command output:

View File

@ -17,7 +17,7 @@ public:
virtual ~cCommandOutputCallback() {}; // Force a virtual destructor in subclasses virtual ~cCommandOutputCallback() {}; // Force a virtual destructor in subclasses
/// Syntax sugar function, calls Out() with Printf()-ed parameters; appends a "\n" /// 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 /// Called when the command wants to output anything; may be called multiple times
virtual void Out(const AString & a_Text) = 0; virtual void Out(const AString & a_Text) = 0;

View File

@ -32,15 +32,15 @@ public:
cCompositeChat Msg; cCompositeChat Msg;
Msg.ParseText("Testing @2color codes and http://links parser"); Msg.ParseText("Testing @2color codes and http://links parser");
const cCompositeChat::cParts & Parts = Msg.GetParts(); const cCompositeChat::cParts & Parts = Msg.GetParts();
assert(Parts.size() == 4); assert_test(Parts.size() == 4);
assert(Parts[0]->m_PartType == cCompositeChat::ptText); assert_test(Parts[0]->m_PartType == cCompositeChat::ptText);
assert(Parts[1]->m_PartType == cCompositeChat::ptText); assert_test(Parts[1]->m_PartType == cCompositeChat::ptText);
assert(Parts[2]->m_PartType == cCompositeChat::ptUrl); assert_test(Parts[2]->m_PartType == cCompositeChat::ptUrl);
assert(Parts[3]->m_PartType == cCompositeChat::ptText); assert_test(Parts[3]->m_PartType == cCompositeChat::ptText);
assert(Parts[0]->m_Style == ""); assert_test(Parts[0]->m_Style == "");
assert(Parts[1]->m_Style == "@2"); assert_test(Parts[1]->m_Style == "@2");
assert(Parts[2]->m_Style == "@2"); assert_test(Parts[2]->m_Style == "@2");
assert(Parts[3]->m_Style == "@2"); assert_test(Parts[3]->m_Style == "@2");
} }
void TestParser2(void) void TestParser2(void)
@ -48,15 +48,15 @@ public:
cCompositeChat Msg; cCompositeChat Msg;
Msg.ParseText("@3Advanced stuff: @5overriding color codes and http://links.with/@4color-in-them handling"); Msg.ParseText("@3Advanced stuff: @5overriding color codes and http://links.with/@4color-in-them handling");
const cCompositeChat::cParts & Parts = Msg.GetParts(); const cCompositeChat::cParts & Parts = Msg.GetParts();
assert(Parts.size() == 4); assert_test(Parts.size() == 4);
assert(Parts[0]->m_PartType == cCompositeChat::ptText); assert_test(Parts[0]->m_PartType == cCompositeChat::ptText);
assert(Parts[1]->m_PartType == cCompositeChat::ptText); assert_test(Parts[1]->m_PartType == cCompositeChat::ptText);
assert(Parts[2]->m_PartType == cCompositeChat::ptUrl); assert_test(Parts[2]->m_PartType == cCompositeChat::ptUrl);
assert(Parts[3]->m_PartType == cCompositeChat::ptText); assert_test(Parts[3]->m_PartType == cCompositeChat::ptText);
assert(Parts[0]->m_Style == "@3"); assert_test(Parts[0]->m_Style == "@3");
assert(Parts[1]->m_Style == "@5"); assert_test(Parts[1]->m_Style == "@5");
assert(Parts[2]->m_Style == "@5"); assert_test(Parts[2]->m_Style == "@5");
assert(Parts[3]->m_Style == "@5"); assert_test(Parts[3]->m_Style == "@5");
} }
void TestParser3(void) void TestParser3(void)
@ -64,11 +64,11 @@ public:
cCompositeChat Msg; cCompositeChat Msg;
Msg.ParseText("http://links.starting the text"); Msg.ParseText("http://links.starting the text");
const cCompositeChat::cParts & Parts = Msg.GetParts(); const cCompositeChat::cParts & Parts = Msg.GetParts();
assert(Parts.size() == 2); assert_test(Parts.size() == 2);
assert(Parts[0]->m_PartType == cCompositeChat::ptUrl); assert_test(Parts[0]->m_PartType == cCompositeChat::ptUrl);
assert(Parts[1]->m_PartType == cCompositeChat::ptText); assert_test(Parts[1]->m_PartType == cCompositeChat::ptText);
assert(Parts[0]->m_Style == ""); assert_test(Parts[0]->m_Style == "");
assert(Parts[1]->m_Style == ""); assert_test(Parts[1]->m_Style == "");
} }
void TestParser4(void) void TestParser4(void)
@ -76,11 +76,11 @@ public:
cCompositeChat Msg; cCompositeChat Msg;
Msg.ParseText("links finishing the text: http://some.server"); Msg.ParseText("links finishing the text: http://some.server");
const cCompositeChat::cParts & Parts = Msg.GetParts(); const cCompositeChat::cParts & Parts = Msg.GetParts();
assert(Parts.size() == 2); assert_test(Parts.size() == 2);
assert(Parts[0]->m_PartType == cCompositeChat::ptText); assert_test(Parts[0]->m_PartType == cCompositeChat::ptText);
assert(Parts[1]->m_PartType == cCompositeChat::ptUrl); assert_test(Parts[1]->m_PartType == cCompositeChat::ptUrl);
assert(Parts[0]->m_Style == ""); assert_test(Parts[0]->m_Style == "");
assert(Parts[1]->m_Style == ""); assert_test(Parts[1]->m_Style == "");
} }
void TestParser5(void) void TestParser5(void)
@ -88,9 +88,9 @@ public:
cCompositeChat Msg; cCompositeChat Msg;
Msg.ParseText("http://only.links"); Msg.ParseText("http://only.links");
const cCompositeChat::cParts & Parts = Msg.GetParts(); const cCompositeChat::cParts & Parts = Msg.GetParts();
assert(Parts.size() == 1); assert_test(Parts.size() == 1);
assert(Parts[0]->m_PartType == cCompositeChat::ptUrl); assert_test(Parts[0]->m_PartType == cCompositeChat::ptUrl);
assert(Parts[0]->m_Style == ""); assert_test(Parts[0]->m_Style == "");
} }
} gTest; } gTest;

View File

@ -192,7 +192,9 @@ void cCraftingGrid::Dump(void)
{ {
for (int y = 0; y < m_Height; y++) for (int x = 0; x < m_Width; x++) for (int y = 0; y < m_Height; y++) for (int x = 0; x < m_Width; x++)
{ {
#ifdef _DEBUG
int idx = x + m_Width * y; int idx = x + m_Width * y;
#endif
LOGD("Slot (%d, %d): Type %d, health %d, count %d", 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 x, y, m_Items[idx].m_ItemType, m_Items[idx].m_ItemDamage, m_Items[idx].m_ItemCount
); );
@ -338,7 +340,7 @@ void cCraftingRecipes::LoadRecipes(void)
} }
AddRecipeLine(LineNum, Recipe); AddRecipeLine(LineNum, Recipe);
} // for itr - Split[] } // for itr - Split[]
LOG("Loaded %d crafting recipes", m_Recipes.size()); LOG("Loaded " SIZE_T_FMT " crafting recipes", m_Recipes.size());
} }

View File

@ -2,6 +2,7 @@
#pragma once #pragma once
#include "ChatColor.h" #include "ChatColor.h"
#include <limits>
@ -489,7 +490,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) 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<double>::epsilon())
{ {
a_Pan = atan2(a_Z, a_X) * 180 / PI - 90; a_Pan = atan2(a_Z, a_X) * 180 / PI - 90;
} }

View File

@ -175,7 +175,7 @@ void cFurnaceRecipe::ReloadRecipes(void)
{ {
LOGERROR("ERROR: FurnaceRecipe, syntax error" ); LOGERROR("ERROR: FurnaceRecipe, syntax error" );
} }
LOG("Loaded %u furnace recipes and %u 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());
} }

View File

@ -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: // Add to queue, issue a warning if too many:
if (m_Queue.size() >= QUEUE_WARNING_LIMIT) 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! (" SIZE_T_FMT ")", a_ChunkX, a_ChunkZ, m_Queue.size());
} }
m_Queue.push_back(cChunkCoords(a_ChunkX, a_ChunkY, a_ChunkZ)); 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); BLOCKTYPE Block = BlockStringToType(BlockType);
if (Block < 0) 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 BlockStringToType(a_Default);
} }
return Block; return Block;

View File

@ -31,14 +31,14 @@ public:
Gen.PlacePieces(500, 50, 500, 3, OutPieces); Gen.PlacePieces(500, 50, 500, 3, OutPieces);
// Print out the pieces: // Print out the pieces:
printf("OutPieces.size() = %u\n", OutPieces.size()); printf("OutPieces.size() = " SIZE_T_FMT "\n", OutPieces.size());
size_t idx = 0; size_t idx = 0;
for (cPlacedPieces::const_iterator itr = OutPieces.begin(), end = OutPieces.end(); itr != end; ++itr, ++idx) for (cPlacedPieces::const_iterator itr = OutPieces.begin(), end = OutPieces.end(); itr != end; ++itr, ++idx)
{ {
const Vector3i & Coords = (*itr)->GetCoords(); const Vector3i & Coords = (*itr)->GetCoords();
cCuboid Hitbox = (*itr)->GetHitBox(); cCuboid Hitbox = (*itr)->GetHitBox();
Hitbox.Sort(); Hitbox.Sort();
printf("%u: {%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, Coords.x, Coords.y, Coords.z,
(*itr)->GetNumCCWRotations(), (*itr)->GetNumCCWRotations(),
Hitbox.p1.x, Hitbox.p1.y, Hitbox.p1.z, 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); cPiece::cConnector res(a_Connector);
// Rotate the res connector: // Rotate the res connector:
Vector3i Size = GetSize();
switch (a_NumCCWRotations) switch (a_NumCCWRotations)
{ {
case 0: case 0:
@ -338,7 +337,7 @@ cPlacedPiece * cPieceGenerator::PlaceStartingPiece(int a_BlockX, int a_BlockY, i
// Choose a random supported rotation: // Choose a random supported rotation:
int Rotations[4] = {0}; int Rotations[4] = {0};
int NumRotations = 1; int NumRotations = 1;
for (int i = 1; i < ARRAYCOUNT(Rotations); i++) for (size_t i = 1; i < ARRAYCOUNT(Rotations); i++)
{ {
if (StartingPiece->CanRotateCCW(i)) if (StartingPiece->CanRotateCCW(i))
{ {
@ -503,11 +502,11 @@ bool cPieceGenerator::CheckConnection(
// DEBUG: // DEBUG:
void cPieceGenerator::DebugConnectorPool(const cPieceGenerator::cFreeConnectors & a_ConnectorPool, size_t a_NumProcessed) 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: " SIZE_T_FMT " items\n", a_ConnectorPool.size() - a_NumProcessed);
size_t idx = 0; size_t idx = 0;
for (cPieceGenerator::cFreeConnectors::const_iterator itr = a_ConnectorPool.begin() + a_NumProcessed, end = a_ConnectorPool.end(); itr != end; ++itr, ++idx) 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", printf(" " SIZE_T_FMT ": {%d, %d, %d}, type %d, direction %s, depth %d\n",
idx, idx,
itr->m_Connector.m_Pos.x, itr->m_Connector.m_Pos.y, itr->m_Connector.m_Pos.z, itr->m_Connector.m_Pos.x, itr->m_Connector.m_Pos.y, itr->m_Connector.m_Pos.z,
itr->m_Connector.m_Type, itr->m_Connector.m_Type,

View File

@ -122,9 +122,9 @@ public:
const cPiece & GetPiece (void) const { return *m_Piece; } const cPiece & GetPiece (void) const { return *m_Piece; }
const Vector3i & GetCoords (void) const { return m_Coords; } 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 cCuboid & GetHitBox (void) const { return m_HitBox; }
const int GetDepth (void) const { return m_Depth; } int GetDepth (void) const { return m_Depth; }
protected: protected:
const cPlacedPiece * m_Parent; const cPlacedPiece * m_Parent;

View File

@ -38,6 +38,13 @@
// No alignment needed in MSVC // No alignment needed in MSVC
#define ALIGN_8 #define ALIGN_8
#define ALIGN_16 #define ALIGN_16
#define FORMATSTRING(formatIndex, va_argsIndex)
// 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__) #elif defined(__GNUC__)
@ -56,6 +63,12 @@
// Some portability macros :) // Some portability macros :)
#define stricmp strcasecmp #define stricmp strcasecmp
#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 #else
@ -81,7 +94,7 @@
#endif #endif
#include <stddef.h>
// Integral types with predefined sizes: // Integral types with predefined sizes:
@ -96,8 +109,23 @@ typedef unsigned short UInt16;
typedef unsigned char Byte; typedef unsigned char Byte;
// If you get an error about specialization check the size of integral types
template <typename T, size_t Size, bool x = sizeof(T) == Size>
class SizeChecker;
template <typename T, size_t Size>
class SizeChecker<T, Size, true>
{
T v;
};
template class SizeChecker<Int64, 8>;
template class SizeChecker<Int32, 4>;
template class SizeChecker<Int16, 2>;
template class SizeChecker<UInt64, 8>;
template class SizeChecker<UInt32, 4>;
template class SizeChecker<UInt16, 2>;
// A macro to disallow the copy constructor and operator= functions // 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 // This should be used in the private: declarations for any class that shouldn't allow copying itself
@ -179,7 +207,7 @@ typedef unsigned char Byte;
#include <memory> #include <memory>
#include <set> #include <set>
#include <queue> #include <queue>
#include <limits>
@ -220,9 +248,10 @@ typedef unsigned char Byte;
// Pretty much the same as ASSERT() but stays in Release builds // 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 ) ) #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(!#x), exit(1), 0))
#endif
/// A generic interface used mainly in ForEach() functions /// A generic interface used mainly in ForEach() functions
template <typename Type> class cItemCallback template <typename Type> class cItemCallback
@ -262,5 +291,3 @@ T Clamp(T a_Value, T a_Min, T a_Max)
#include "Entities/Effects.h" #include "Entities/Effects.h"

View File

@ -216,7 +216,7 @@ cItem * cItems::Get(int a_Idx)
{ {
if ((a_Idx < 0) || (a_Idx >= (int)size())) 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 " SIZE_T_FMT " items. Returning a nil.", a_Idx, size());
return NULL; return NULL;
} }
return &at(a_Idx); 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())) 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 " SIZE_T_FMT " items. Not setting.", a_Idx, size());
return; return;
} }
at(a_Idx) = a_Item; at(a_Idx) = a_Item;
@ -244,7 +244,7 @@ void cItems::Delete(int a_Idx)
{ {
if ((a_Idx < 0) || (a_Idx >= (int)size())) 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 " SIZE_T_FMT " items. Ignoring.", a_Idx, size());
return; return;
} }
erase(begin() + a_Idx); 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())) 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 " SIZE_T_FMT " items. Not setting.", a_Idx, size());
return; return;
} }
at(a_Idx) = cItem(a_ItemType, a_ItemCount, a_ItemDamage); at(a_Idx) = cItem(a_ItemType, a_ItemCount, a_ItemDamage);

View File

@ -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[]: /// Chunk data callback that takes the chunk data and puts them into cLightingThread's m_BlockTypes[] / m_HeightMap[]:
class cReader : class cReader :

View File

@ -118,7 +118,7 @@ void cLog::Log(const char * a_Format, va_list argList)
AString Line; AString Line;
#ifdef _DEBUG #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, "[%04lx|%02d:%02d:%02d] %s", cIsThread::GetCurrentID(), timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, Message.c_str());
#else #else
Printf(Line, "[%02d:%02d:%02d] %s", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, Message.c_str()); Printf(Line, "[%02d:%02d:%02d] %s", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, Message.c_str());
#endif #endif

View File

@ -14,8 +14,8 @@ private:
public: public:
cLog(const AString & a_FileName); cLog(const AString & a_FileName);
~cLog(); ~cLog();
void Log(const char * a_Format, va_list argList); void Log(const char * a_Format, va_list argList) FORMATSTRING(2, 0);
void Log(const char * a_Format, ...); void Log(const char * a_Format, ...) FORMATSTRING(2, 3);
// tolua_begin // tolua_begin
void SimpleLog(const char * a_String); void SimpleLog(const char * a_String);
void OpenLog(const char * a_FileName); void OpenLog(const char * a_FileName);

View File

@ -21,10 +21,10 @@ public: // tolua_export
~cMCLogger(); // tolua_export ~cMCLogger(); // tolua_export
void Log(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); void Info(const char* a_Format, va_list a_ArgList) FORMATSTRING(2, 0);
void Warn(const char* a_Format, va_list a_ArgList); void Warn(const char* a_Format, va_list a_ArgList) FORMATSTRING(2, 0);
void Error(const char* a_Format, va_list a_ArgList); 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 void LogSimple(const char* a_Text, int a_LogType = 0 ); // tolua_export
@ -57,10 +57,10 @@ private:
extern void LOG(const char* a_Format, ...); extern void LOG(const char* a_Format, ...) FORMATSTRING(1, 2);
extern void LOGINFO(const char* a_Format, ...); extern void LOGINFO(const char* a_Format, ...) FORMATSTRING(1, 2);
extern void LOGWARN(const char* a_Format, ...); extern void LOGWARN(const char* a_Format, ...) FORMATSTRING(1, 2);
extern void LOGERROR(const char* a_Format, ...); extern void LOGERROR(const char* a_Format, ...) FORMATSTRING(1, 2);

View File

@ -64,7 +64,7 @@ public:
unsigned int GetPixelX(void) const { return m_PixelX; } unsigned int GetPixelX(void) const { return m_PixelX; }
unsigned int GetPixelZ(void) const { return m_PixelZ; } 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; } eType GetType(void) const { return m_Type; }

View File

@ -62,7 +62,7 @@
class MTRand { class MTRand {
// Data // Data
public: 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 { N = 624 }; // length of state vector
enum { SAVE = N + 1 }; // length of array for save() enum { SAVE = N + 1 }; // length of array for save()
@ -72,7 +72,7 @@ protected:
uint32 state[N]; // internal state uint32 state[N]; // internal state
uint32 *pNext; // next value to get from 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 // Methods
public: 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. // only MSBs of the state array. Modified 9 Jan 2002 by Makoto Matsumoto.
uint32 *s = state; uint32 *s = state;
uint32 *r = state; uint32 *r = state;
int i = 1; uint32 i = 1;
*s++ = seed & 0xffffffffUL; *s++ = seed & 0xffffffffUL;
for( ; i < N; ++i ) for( ; i < N; ++i )
{ {
@ -205,9 +205,9 @@ inline void MTRand::seed( uint32 *const bigSeed, const uint32 seedLength )
// in each element are discarded. // in each element are discarded.
// Just call seed() if you want to get array from /dev/urandom // Just call seed() if you want to get array from /dev/urandom
initialize(19650218UL); initialize(19650218UL);
int i = 1; uint32 i = 1;
uint32 j = 0; uint32 j = 0;
int k = ( (uint32)N > seedLength ? (uint32)N : seedLength ); uint32 k = ( (uint32)N > seedLength ? (uint32)N : seedLength );
for( ; k; --k ) for( ; k; --k )
{ {
state[i] = state[i] =

View File

@ -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_family = AF_INET;
server.sin_port = htons( (unsigned short)iPort); server.sin_port = htons( (unsigned short)iPort);
if (connect(m_Socket, (struct sockaddr *)&server, sizeof(server))) if (connect(m_Socket, (struct sockaddr *)&server, sizeof(server)))

View File

@ -131,7 +131,7 @@ public:
/** Returns the list of all items in the specified folder (files, folders, nix pipes, whatever's there). */ /** 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 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) */ /** Flushes all the bufferef output into the file (only when writing) */
void Flush(void); void Flush(void);

View File

@ -34,7 +34,7 @@ protected:
public: public:
cIsThread(const AString & iThreadName); cIsThread(const AString & iThreadName);
~cIsThread(); virtual ~cIsThread();
/// Starts the thread; returns without waiting for the actual start /// Starts the thread; returns without waiting for the actual start
bool Start(void); bool Start(void);

View File

@ -307,7 +307,8 @@ bool cSocket::ConnectIPv4(const AString & a_HostNameOrAddr, unsigned short a_Por
CloseSocket(); CloseSocket();
return false; 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; sockaddr_in server;

View File

@ -54,7 +54,7 @@ bool cSocketThreads::AddClient(const cSocket & a_Socket, cCallback * a_Client)
} }
// No thread has free space, create a new one: // 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 " SIZE_T_FMT ")", m_Threads.size());
cSocketThread * Thread = new cSocketThread(this); cSocketThread * Thread = new cSocketThread(this);
if (!Thread->Start()) if (!Thread->Start())
{ {

View File

@ -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) int cProtocol125::ParseArmAnim(void)
{ {
HANDLE_PACKET_READ(ReadBEInt, int, EntityID); HANDLE_PACKET_READ(ReadBEInt, int, EntityID);

View File

@ -100,7 +100,7 @@ cProtocol132::~cProtocol132()
{ {
if (!m_DataToSend.empty()) if (!m_DataToSend.empty())
{ {
LOGD("There are %d unsent bytes while deleting cProtocol132", m_DataToSend.size()); LOGD("There are " SIZE_T_FMT " unsent bytes while deleting cProtocol132", m_DataToSend.size());
} }
} }

View File

@ -1251,7 +1251,7 @@ void cProtocol172::AddReceivedData(const char * a_Data, int a_Size)
ASSERT(m_ReceivedData.GetReadableSpace() == OldReadableSpace); ASSERT(m_ReceivedData.GetReadableSpace() == OldReadableSpace);
AString Hex; AString Hex;
CreateHexDump(Hex, AllData.data(), AllData.size(), 16); 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, " SIZE_T_FMT " (0x" SIZE_T_FMT_HEX ") unparsed bytes already present in buffer:\n%s\n",
AllData.size(), AllData.size(), Hex.c_str() 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) if (bb.GetReadableSpace() != 1)
{ {
// Read more or less than packet length, report as error // 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 " SIZE_T_FMT " bytes, packet contained %u bytes",
PacketType, m_State, bb.GetUsedSpace() - bb.GetReadableSpace(), PacketLen PacketType, m_State, bb.GetUsedSpace() - bb.GetReadableSpace(), PacketLen
); );
// Put a message in the comm log: // Put a message in the comm log:
if (g_ShouldLogCommIn) 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 " SIZE_T_FMT " left) ^^^^^^\n\n\n",
1, bb.GetReadableSpace() 1, bb.GetReadableSpace()
); );
m_CommLogFile.Flush(); m_CommLogFile.Flush();
@ -1373,7 +1373,7 @@ void cProtocol172::AddReceivedData(const char * a_Data, int a_Size)
ASSERT(m_ReceivedData.GetReadableSpace() == OldReadableSpace); ASSERT(m_ReceivedData.GetReadableSpace() == OldReadableSpace);
AString Hex; AString Hex;
CreateHexDump(Hex, AllData.data(), AllData.size(), 16); 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 " 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_ReceivedData.GetReadableSpace(), m_ReceivedData.GetReadableSpace(), Hex.c_str()
); );
m_CommLogFile.Flush(); m_CommLogFile.Flush();
@ -2062,7 +2062,7 @@ void cProtocol172::ParseItemMetadata(cItem & a_Item, const AString & a_Metadata)
{ {
AString HexDump; AString HexDump;
CreateHexDump(HexDump, a_Metadata.data(), a_Metadata.size(), 16); 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 (" SIZE_T_FMT " bytes):\n%s", a_Metadata.size(), HexDump.c_str());
return; return;
} }
@ -2072,7 +2072,7 @@ void cProtocol172::ParseItemMetadata(cItem & a_Item, const AString & a_Metadata)
{ {
AString HexDump; AString HexDump;
CreateHexDump(HexDump, Uncompressed.data(), Uncompressed.size(), 16); 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: (" SIZE_T_FMT " bytes)\n%s", Uncompressed.size(), HexDump.c_str());
return; return;
} }

View File

@ -778,11 +778,11 @@ void cRoot::LogChunkStats(cCommandOutputCallback & a_Output)
int Mem = NumValid * sizeof(cChunk); 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(" 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(" 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 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: %6d bytes (%3d KiB)", sizeof(cChunkDef::BlockNibbles), (sizeof(cChunkDef::BlockNibbles) + 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: %6d bytes (%3d KiB)", 2 * sizeof(cChunkDef::BlockNibbles), (2 * 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: %6d bytes (%3d KiB)", sizeof(cChunkDef::HeightMap), (sizeof(cChunkDef::HeightMap) + 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: %6d bytes (%3d KiB)", sizeof(cChunkDef::BiomeMap), (sizeof(cChunkDef::BiomeMap) + 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); 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); a_Output.Out(" other: %6d bytes (%3d KiB)", Rest, (Rest + 1023) / 1024);
SumNumValid += NumValid; SumNumValid += NumValid;

View File

@ -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) for (AStringPairs::const_iterator itr = Callback.m_Commands.begin(), end = Callback.m_Commands.end(); itr != end; ++itr)
{ {
const AStringPair & cmd = *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<int>(Callback.m_MaxLen), cmd.first.c_str(), cmd.second.c_str()));
} // for itr - Callback.m_Commands[] } // for itr - Callback.m_Commands[]
a_Output.Finished(); a_Output.Finished();
} }

View File

@ -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 // 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.clear();
a_UTF8.reserve(3 * a_NumShorts / 2); // a quick guess of the resulting size a_UTF8.reserve(3 * a_NumShorts / 2); // a quick guess of the resulting size
for (int i = 0; i < a_NumShorts; i++) for (int i = 0; i < a_NumShorts; i++)
{ {
int c = ntohs(*(a_RawData + i)); int c = GetBEShort(&a_RawData[i * 2]);
if (c < 0x80) if (c < 0x80)
{ {
a_UTF8.push_back((char)c); a_UTF8.push_back((char)c);
@ -364,10 +364,7 @@ Notice from the original file:
#define UNI_MAX_BMP 0x0000FFFF #define UNI_MAX_BMP 0x0000FFFF
#define UNI_MAX_UTF16 0x0010FFFF #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_START 0xD800
#define UNI_SUR_HIGH_END 0xDBFF
#define UNI_SUR_LOW_START 0xDC00 #define UNI_SUR_LOW_START 0xDC00
#define UNI_SUR_LOW_END 0xDFFF #define UNI_SUR_LOW_END 0xDFFF

View File

@ -22,16 +22,16 @@ typedef std::list<AString> AStringList;
/** Add the formated string to the existing data in the string */ /** 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 /// 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 /// 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 /// 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 /// Split the string at any of the listed delimiters, return as a stringvector
extern AStringVector StringSplit(const AString & str, const AString & delim); extern AStringVector StringSplit(const AString & str, const AString & delim);
@ -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 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 /// 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 /// 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); extern AString & UTF8ToRawBEUTF16(const char * a_UTF8, size_t a_UTF8Length, AString & a_UTF16);

View File

@ -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()) 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 (" 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 // This doesn't seem to happen with the 1.5.1 client, so we don't worry about it for now
return 0; return 0;
} }

View File

@ -102,7 +102,7 @@ protected:
{ {
for (;;) for (;;)
{ {
LOG("%d chunks to load, %d chunks to generate", LOG("" SIZE_T_FMT " chunks to load, %d chunks to generate",
m_World->GetStorage().GetLoadQueueLength(), m_World->GetStorage().GetLoadQueueLength(),
m_World->GetGenerator().GetQueueLength() m_World->GetGenerator().GetQueueLength()
); );
@ -154,7 +154,7 @@ protected:
{ {
for (;;) for (;;)
{ {
LOG("%d 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 // Wait for 2 sec, but be "reasonably wakeable" when the thread is to finish

View File

@ -506,22 +506,18 @@ void cFastNBTWriter::AddIntArray(const AString & a_Name, const int * a_Value, si
{ {
TagCommon(a_Name, TAG_IntArray); TagCommon(a_Name, TAG_IntArray);
Int32 len = htonl(a_NumElements); 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); 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++) for (size_t i = 0; i < a_NumElements; i++)
{ {
int Element = htonl(a_Value[i]); int Element = htonl(a_Value[i]);
m_Result.append((const char *)&Element, 4); 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
} }

View File

@ -90,30 +90,34 @@ void cFireworkItem::ParseFromNBT(cFireworkItem & a_FireworkItem, const cParsedNB
if (ExplosionName == "Colors") if (ExplosionName == "Colors")
{ {
// Divide by four as data length returned in bytes // Divide by four as data length returned in bytes
int DataLength = a_NBT.GetDataLength(explosiontag) / 4; int DataLength = a_NBT.GetDataLength(explosiontag);
// round to the next highest multiple of four
DataLength -= DataLength % 4;
if (DataLength == 0) if (DataLength == 0)
{ {
continue; continue;
} }
const int * ColourData = (const int *)(a_NBT.GetData(explosiontag)); const char * ColourData = (a_NBT.GetData(explosiontag));
for (int i = 0; i < DataLength; i++) 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") else if (ExplosionName == "FadeColors")
{ {
int DataLength = a_NBT.GetDataLength(explosiontag) / 4; int DataLength = a_NBT.GetDataLength(explosiontag) / 4;
// round to the next highest multiple of four
DataLength -= DataLength % 4;
if (DataLength == 0) if (DataLength == 0)
{ {
continue; continue;
} }
const int * FadeColourData = (const int *)(a_NBT.GetData(explosiontag)); const char * FadeColourData = (a_NBT.GetData(explosiontag));
for (int i = 0; i < DataLength; i++) 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));
} }
} }
} }

View File

@ -507,10 +507,10 @@ cChunkDef::BiomeMap * cWSSAnvil::LoadBiomeMapFromNBT(cChunkDef::BiomeMap * a_Bio
// The biomes stored don't match in size // The biomes stored don't match in size
return NULL; 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++) 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) if ((*a_BiomeMap)[i] == 0xff)
{ {
// Unassigned biomes // Unassigned biomes

View File

@ -39,7 +39,7 @@ struct cWSSCompact::sChunkHeader
/// The maximum number of PAK files that are cached /// The maximum number of PAK files that are cached
const int MAX_PAK_FILES = 16; const size_t MAX_PAK_FILES = 16;
/// The maximum number of unsaved chunks before the cPAKFile saves them to disk /// The maximum number of unsaved chunks before the cPAKFile saves them to disk
const int MAX_DIRTY_CHUNKS = 16; const int MAX_DIRTY_CHUNKS = 16;
@ -569,7 +569,7 @@ void cWSSCompact::cPAKFile::UpdateChunk1To2()
if( ChunksConverted % 32 == 0 ) 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: " SIZE_T_FMT " %%", m_FileName.c_str(), (ChunksConverted * 100) / m_ChunkHeaders.size() );
} }
ChunksConverted++; ChunksConverted++;
@ -607,7 +607,7 @@ void cWSSCompact::cPAKFile::UpdateChunk1To2()
if (UncompressedSize != (int)UncompressedData.size()) 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 " SIZE_T_FMT ") for chunk [%d, %d]",
UncompressedSize, UncompressedData.size(), UncompressedSize, UncompressedData.size(),
Header->m_ChunkX, Header->m_ChunkZ Header->m_ChunkX, Header->m_ChunkZ
); );
@ -713,7 +713,7 @@ void cWSSCompact::cPAKFile::UpdateChunk2To3()
if( ChunksConverted % 32 == 0 ) 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: " SIZE_T_FMT " %%", m_FileName.c_str(), (ChunksConverted * 100) / m_ChunkHeaders.size() );
} }
ChunksConverted++; ChunksConverted++;
@ -751,7 +751,7 @@ void cWSSCompact::cPAKFile::UpdateChunk2To3()
if (UncompressedSize != (int)UncompressedData.size()) 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 " SIZE_T_FMT ") for chunk [%d, %d]",
UncompressedSize, UncompressedData.size(), UncompressedSize, UncompressedData.size(),
Header->m_ChunkX, Header->m_ChunkZ Header->m_ChunkX, Header->m_ChunkZ
); );
@ -764,7 +764,6 @@ void cWSSCompact::cPAKFile::UpdateChunk2To3()
// Cannot use cChunk::MakeIndex because it might change again????????? // Cannot use cChunk::MakeIndex because it might change again?????????
// For compatibility, use what we know is current // 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) ) #define MAKE_3_INDEX( x, y, z ) ( x + (z * 16) + (y * 16 * 16) )
unsigned int InChunkOffset = 0; unsigned int InChunkOffset = 0;
@ -867,7 +866,7 @@ bool cWSSCompact::LoadChunkFromData(const cChunkCoords & a_Chunk, int & a_Uncomp
if (a_UncompressedSize != (int)UncompressedData.size()) 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 " SIZE_T_FMT ") for chunk [%d, %d]",
a_UncompressedSize, UncompressedData.size(), a_UncompressedSize, UncompressedData.size(),
a_Chunk.m_ChunkX, a_Chunk.m_ChunkZ a_Chunk.m_ChunkX, a_Chunk.m_ChunkZ
); );