summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Bindings/LuaState.cpp4
-rw-r--r--src/ByteBuffer.cpp32
-rw-r--r--src/ByteBuffer.h2
-rw-r--r--src/ChunkDef.h21
-rw-r--r--src/ClientHandle.cpp15
-rw-r--r--src/CommandOutput.cpp4
-rw-r--r--src/CommandOutput.h2
-rw-r--r--src/CompositeChat.cpp62
-rw-r--r--src/CraftingRecipes.cpp4
-rw-r--r--src/Defines.h3
-rw-r--r--src/FurnaceRecipe.cpp2
-rw-r--r--src/Generating/ChunkGenerator.cpp4
-rw-r--r--src/Generating/PieceGenerator.cpp11
-rw-r--r--src/Generating/PieceGenerator.h4
-rw-r--r--src/Globals.h40
-rw-r--r--src/Item.cpp8
-rw-r--r--src/LightingThread.cpp6
-rw-r--r--src/Log.cpp2
-rw-r--r--src/Log.h4
-rw-r--r--src/MCLogger.h16
-rw-r--r--src/Map.h2
-rw-r--r--src/MersenneTwister.h10
-rw-r--r--src/OSSupport/BlockingTCPLink.cpp2
-rw-r--r--src/OSSupport/File.h2
-rw-r--r--src/OSSupport/IsThread.h2
-rw-r--r--src/OSSupport/Socket.cpp3
-rw-r--r--src/OSSupport/SocketThreads.cpp2
-rw-r--r--src/Protocol/Protocol125.cpp13
-rw-r--r--src/Protocol/Protocol132.cpp2
-rw-r--r--src/Protocol/Protocol17x.cpp12
-rw-r--r--src/Root.cpp10
-rw-r--r--src/Server.cpp2
-rw-r--r--src/StringUtils.cpp7
-rw-r--r--src/StringUtils.h10
-rw-r--r--src/UI/Window.cpp2
-rw-r--r--src/World.cpp4
-rw-r--r--src/WorldStorage/FastNBT.cpp16
-rw-r--r--src/WorldStorage/FireworksSerializer.cpp18
-rw-r--r--src/WorldStorage/WSSAnvil.cpp4
-rw-r--r--src/WorldStorage/WSSCompact.cpp13
40 files changed, 193 insertions, 189 deletions
diff --git a/src/Bindings/LuaState.cpp b/src/Bindings/LuaState.cpp
index dfc428bbc..f24e15c3b 100644
--- a/src/Bindings/LuaState.cpp
+++ b/src/Bindings/LuaState.cpp
@@ -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
- 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/ByteBuffer.cpp b/src/ByteBuffer.cpp
index 96a135562..d3bcfe866 100644
--- a/src/ByteBuffer.cpp
+++ b/src/ByteBuffer.cpp
@@ -62,11 +62,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 +77,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 +87,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
}
}
@@ -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);
}
@@ -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/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/ChunkDef.h b/src/ChunkDef.h
index 04a7f5af2..9c7753820 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) &&
@@ -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
// For some reason, NOT using the Horner schema is faster. Weird.
@@ -251,7 +251,7 @@ public:
ASSERT(!"cChunkDef::SetNibble(): index out of range!");
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_Nibble & 0x0f) << ((a_BlockIdx & 1) * 4)) // The nibble being set
);
@@ -271,20 +271,20 @@ public:
}
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_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 );
}
- 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 );
}
@@ -302,6 +302,9 @@ The virtual methods are called in the same order as they're declared here.
class cChunkDataCallback abstract
{
public:
+
+ virtual ~cChunkDataCallback() {}
+
/** Called before any other callbacks to inform of the current coords
(only in processes where multiple chunks can be processed, such as cWorld::ForEachChunkInRect()).
If false is returned, the chunk is skipped.
@@ -428,6 +431,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;
@@ -488,6 +494,9 @@ typedef std::vector<cChunkCoords> cChunkCoordsVector;
class cChunkCoordCallback
{
public:
+
+ virtual ~cChunkCoordCallback() {}
+
virtual void Call(int a_ChunkX, int a_ChunkZ) = 0;
} ;
diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp
index 9083d7ae0..46c10ae82 100644
--- a/src/ClientHandle.cpp
+++ b/src/ClientHandle.cpp
@@ -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 */
#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)",
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/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/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..30e7a8733 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
);
@@ -338,7 +340,7 @@ void cCraftingRecipes::LoadRecipes(void)
}
AddRecipeLine(LineNum, Recipe);
} // for itr - Split[]
- LOG("Loaded %d crafting recipes", m_Recipes.size());
+ LOG("Loaded " SIZE_T_FMT " crafting recipes", m_Recipes.size());
}
diff --git a/src/Defines.h b/src/Defines.h
index d2fcce576..3b7654265 100644
--- a/src/Defines.h
+++ b/src/Defines.h
@@ -2,6 +2,7 @@
#pragma once
#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)
{
- if (a_X != 0)
+ if (fabs(a_X) < std::numeric_limits<double>::epsilon())
{
a_Pan = atan2(a_Z, a_X) * 180 / PI - 90;
}
diff --git a/src/FurnaceRecipe.cpp b/src/FurnaceRecipe.cpp
index 2e2276981..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 %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());
}
diff --git a/src/Generating/ChunkGenerator.cpp b/src/Generating/ChunkGenerator.cpp
index ef38f1399..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! (%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));
}
@@ -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/Generating/PieceGenerator.cpp b/src/Generating/PieceGenerator.cpp
index cf5ab6226..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() = %u\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("%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,
(*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))
{
@@ -503,11 +502,11 @@ 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: " 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)
{
- 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,
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;
diff --git a/src/Globals.h b/src/Globals.h
index b8acfca64..45d403f27 100644
--- a/src/Globals.h
+++ b/src/Globals.h
@@ -38,6 +38,13 @@
// No alignment needed in MSVC
#define ALIGN_8
#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__)
@@ -56,6 +63,12 @@
// Some portability macros :)
#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
@@ -81,7 +94,7 @@
#endif
-
+#include <stddef.h>
// Integral types with predefined sizes:
@@ -96,8 +109,22 @@ typedef unsigned short UInt16;
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
// This should be used in the private: declarations for any class that shouldn't allow copying itself
@@ -179,7 +206,7 @@ typedef unsigned char Byte;
#include <memory>
#include <set>
#include <queue>
-
+#include <limits>
@@ -220,9 +247,10 @@ typedef unsigned char Byte;
// 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(!#x), exit(1), 0))
+#endif
/// A generic interface used mainly in ForEach() functions
template <typename Type> class cItemCallback
@@ -262,5 +290,3 @@ T Clamp(T a_Value, T a_Min, T a_Max)
#include "Entities/Effects.h"
-
-
diff --git a/src/Item.cpp b/src/Item.cpp
index 61d57e763..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 %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 &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 " 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 %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;
}
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 " SIZE_T_FMT " items. Not setting.", a_Idx, size());
return;
}
at(a_Idx) = cItem(a_ItemType, a_ItemCount, a_ItemDamage);
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/Log.cpp b/src/Log.cpp
index 1ea327d5d..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, "[%04x|%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/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);
diff --git a/src/MCLogger.h b/src/MCLogger.h
index c949a4cdf..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,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/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..759b8a1ae 100644
--- a/src/MersenneTwister.h
+++ b/src/MersenneTwister.h
@@ -62,7 +62,7 @@
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()
@@ -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] =
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)))
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/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);
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;
diff --git a/src/OSSupport/SocketThreads.cpp b/src/OSSupport/SocketThreads.cpp
index a02661d2c..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 %d)", 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/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);
diff --git a/src/Protocol/Protocol132.cpp b/src/Protocol/Protocol132.cpp
index 8df550c7b..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 %d 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 8c800036e..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, %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()
);
}
@@ -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 %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
);
// 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 " 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 %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_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 (%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;
}
@@ -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: (" SIZE_T_FMT " bytes)\n%s", Uncompressed.size(), HexDump.c_str());
return;
}
diff --git a/src/Root.cpp b/src/Root.cpp
index 69f18104e..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: %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: " 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/Server.cpp b/src/Server.cpp
index 1b168ff20..d1e53bfff 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<int>(Callback.m_MaxLen), cmd.first.c_str(), cmd.second.c_str()));
} // for itr - Callback.m_Commands[]
a_Output.Finished();
}
diff --git a/src/StringUtils.cpp b/src/StringUtils.cpp
index 3fe75d611..3f9275798 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..728ce31e6 100644
--- a/src/StringUtils.h
+++ b/src/StringUtils.h
@@ -22,16 +22,16 @@ typedef std::list<AString> 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, ...);
+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);
@@ -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);
diff --git a/src/UI/Window.cpp b/src/UI/Window.cpp
index 1a8456f70..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 (%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
return 0;
}
diff --git a/src/World.cpp b/src/World.cpp
index 3d01dc40f..8c3a1ff8a 100644
--- a/src/World.cpp
+++ b/src/World.cpp
@@ -102,7 +102,7 @@ protected:
{
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->GetGenerator().GetQueueLength()
);
@@ -154,7 +154,7 @@ protected:
{
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
diff --git a/src/WorldStorage/FastNBT.cpp b/src/WorldStorage/FastNBT.cpp
index 8f80c3f75..be25fd1a4 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
}
diff --git a/src/WorldStorage/FireworksSerializer.cpp b/src/WorldStorage/FireworksSerializer.cpp
index 1f05b470d..3c97ae0a2 100644
--- a/src/WorldStorage/FireworksSerializer.cpp
+++ b/src/WorldStorage/FireworksSerializer.cpp
@@ -90,30 +90,34 @@ 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);
+ // round to the next highest multiple of four
+ DataLength -= DataLength % 4;
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")
{
int DataLength = a_NBT.GetDataLength(explosiontag) / 4;
+ // round to the next highest multiple of four
+ DataLength -= DataLength % 4;
if (DataLength == 0)
{
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));
}
}
}
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
diff --git a/src/WorldStorage/WSSCompact.cpp b/src/WorldStorage/WSSCompact.cpp
index 5e49e4909..bb9d4b9e6 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 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;
@@ -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: " 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 %d) 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: %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++;
@@ -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 " SIZE_T_FMT ") for chunk [%d, %d]",
UncompressedSize, UncompressedData.size(),
Header->m_ChunkX, Header->m_ChunkZ
);
@@ -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;
@@ -867,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 " SIZE_T_FMT ") for chunk [%d, %d]",
a_UncompressedSize, UncompressedData.size(),
a_Chunk.m_ChunkX, a_Chunk.m_ChunkZ
);