summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPeter Bell <peterbell10@live.co.uk>2020-05-09 17:51:54 +0200
committerpeterbell10 <peterbell10@live.co.uk>2020-05-09 21:37:16 +0200
commit1123c95cf2efdcb23ff557b956d58538ca24aefe (patch)
treee8f39c2519ad06afc4f52d8fbc1d8fb334aeea42 /src
parentUpdate submodules (#4727) (diff)
downloadcuberite-1123c95cf2efdcb23ff557b956d58538ca24aefe.tar
cuberite-1123c95cf2efdcb23ff557b956d58538ca24aefe.tar.gz
cuberite-1123c95cf2efdcb23ff557b956d58538ca24aefe.tar.bz2
cuberite-1123c95cf2efdcb23ff557b956d58538ca24aefe.tar.lz
cuberite-1123c95cf2efdcb23ff557b956d58538ca24aefe.tar.xz
cuberite-1123c95cf2efdcb23ff557b956d58538ca24aefe.tar.zst
cuberite-1123c95cf2efdcb23ff557b956d58538ca24aefe.zip
Diffstat (limited to '')
-rw-r--r--src/BlockArea.cpp12
-rw-r--r--src/CraftingRecipes.cpp10
-rw-r--r--src/Generating/CompoGen.cpp4
-rw-r--r--src/Globals.h7
-rw-r--r--src/LazyArray.h2
-rw-r--r--src/Noise/OctavedNoise.h4
-rw-r--r--src/Simulator/DelayedFluidSimulator.cpp2
7 files changed, 22 insertions, 19 deletions
diff --git a/src/BlockArea.cpp b/src/BlockArea.cpp
index 1d63f147d..4aa5175f2 100644
--- a/src/BlockArea.cpp
+++ b/src/BlockArea.cpp
@@ -2086,7 +2086,7 @@ bool cBlockArea::SetSize(int a_SizeX, int a_SizeY, int a_SizeZ, int a_DataTypes)
// Try to allocate the new storage
if ((a_DataTypes & baTypes) != 0)
{
- NewBlocks.reset(new BLOCKTYPE[a_SizeX * a_SizeY * a_SizeZ]);
+ NewBlocks.reset(new BLOCKTYPE[ToUnsigned(a_SizeX * a_SizeY * a_SizeZ)]);
if (NewBlocks == nullptr)
{
return false;
@@ -2094,7 +2094,7 @@ bool cBlockArea::SetSize(int a_SizeX, int a_SizeY, int a_SizeZ, int a_DataTypes)
}
if ((a_DataTypes & baMetas) != 0)
{
- NewMetas.reset(new NIBBLETYPE[a_SizeX * a_SizeY * a_SizeZ]);
+ NewMetas.reset(new NIBBLETYPE[ToUnsigned(a_SizeX * a_SizeY * a_SizeZ)]);
if (NewMetas == nullptr)
{
return false;
@@ -2102,7 +2102,7 @@ bool cBlockArea::SetSize(int a_SizeX, int a_SizeY, int a_SizeZ, int a_DataTypes)
}
if ((a_DataTypes & baLight) != 0)
{
- NewLight.reset(new NIBBLETYPE[a_SizeX * a_SizeY * a_SizeZ]);
+ NewLight.reset(new NIBBLETYPE[ToUnsigned(a_SizeX * a_SizeY * a_SizeZ)]);
if (NewLight == nullptr)
{
return false;
@@ -2110,7 +2110,7 @@ bool cBlockArea::SetSize(int a_SizeX, int a_SizeY, int a_SizeZ, int a_DataTypes)
}
if ((a_DataTypes & baSkyLight) != 0)
{
- NewSkyLight.reset(new NIBBLETYPE[a_SizeX * a_SizeY * a_SizeZ]);
+ NewSkyLight.reset(new NIBBLETYPE[ToUnsigned(a_SizeX * a_SizeY * a_SizeZ)]);
if (NewSkyLight == nullptr)
{
return false;
@@ -2270,7 +2270,7 @@ void cBlockArea::CropBlockTypes(int a_AddMinX, int a_SubMaxX, int a_AddMinY, int
int NewSizeX = GetSizeX() - a_AddMinX - a_SubMaxX;
int NewSizeY = GetSizeY() - a_AddMinY - a_SubMaxY;
int NewSizeZ = GetSizeZ() - a_AddMinZ - a_SubMaxZ;
- BLOCKARRAY NewBlockTypes{ new BLOCKTYPE[NewSizeX * NewSizeY * NewSizeZ] };
+ BLOCKARRAY NewBlockTypes{ new BLOCKTYPE[ToUnsigned(NewSizeX * NewSizeY * NewSizeZ)] };
size_t idx = 0;
for (int y = 0; y < NewSizeY; y++)
{
@@ -2295,7 +2295,7 @@ void cBlockArea::CropNibbles(NIBBLEARRAY & a_Array, int a_AddMinX, int a_SubMaxX
int NewSizeX = GetSizeX() - a_AddMinX - a_SubMaxX;
int NewSizeY = GetSizeY() - a_AddMinY - a_SubMaxY;
int NewSizeZ = GetSizeZ() - a_AddMinZ - a_SubMaxZ;
- NIBBLEARRAY NewNibbles{ new NIBBLETYPE[NewSizeX * NewSizeY * NewSizeZ] };
+ NIBBLEARRAY NewNibbles{ new NIBBLETYPE[ToUnsigned(NewSizeX * NewSizeY * NewSizeZ)] };
size_t idx = 0;
for (int y = 0; y < NewSizeY; y++)
{
diff --git a/src/CraftingRecipes.cpp b/src/CraftingRecipes.cpp
index 1a8a68523..fc0ce92f1 100644
--- a/src/CraftingRecipes.cpp
+++ b/src/CraftingRecipes.cpp
@@ -18,7 +18,7 @@
cCraftingGrid::cCraftingGrid(int a_Width, int a_Height) :
m_Width(a_Width),
m_Height(a_Height),
- m_Items(new cItem[a_Width * a_Height])
+ m_Items(new cItem[ToUnsigned(a_Width * a_Height)])
{
}
@@ -27,9 +27,7 @@ cCraftingGrid::cCraftingGrid(int a_Width, int a_Height) :
cCraftingGrid::cCraftingGrid(const cItem * a_Items, int a_Width, int a_Height) :
- m_Width(a_Width),
- m_Height(a_Height),
- m_Items(new cItem[a_Width * a_Height])
+ cCraftingGrid(a_Width, a_Height)
{
for (int i = a_Width * a_Height - 1; i >= 0; i--)
{
@@ -42,9 +40,7 @@ cCraftingGrid::cCraftingGrid(const cItem * a_Items, int a_Width, int a_Height) :
cCraftingGrid::cCraftingGrid(const cCraftingGrid & a_Original) :
- m_Width(a_Original.m_Width),
- m_Height(a_Original.m_Height),
- m_Items(new cItem[a_Original.m_Width * a_Original.m_Height])
+ cCraftingGrid(a_Original.m_Width, a_Original.m_Height)
{
for (int i = m_Width * m_Height - 1; i >= 0; i--)
{
diff --git a/src/Generating/CompoGen.cpp b/src/Generating/CompoGen.cpp
index 899ff54c1..13b05222c 100644
--- a/src/Generating/CompoGen.cpp
+++ b/src/Generating/CompoGen.cpp
@@ -332,8 +332,8 @@ void cCompoGenNether::InitializeCompoGen(cIniFile & a_IniFile)
cCompoGenCache::cCompoGenCache(cTerrainCompositionGenPtr a_Underlying, int a_CacheSize) :
m_Underlying(a_Underlying),
m_CacheSize(a_CacheSize),
- m_CacheOrder(new int[a_CacheSize]),
- m_CacheData(new sCacheData[a_CacheSize]),
+ m_CacheOrder(new int[ToUnsigned(a_CacheSize)]),
+ m_CacheData(new sCacheData[ToUnsigned(a_CacheSize)]),
m_NumHits(0),
m_NumMisses(0),
m_TotalChain(0)
diff --git a/src/Globals.h b/src/Globals.h
index 02b007e09..e6fde373e 100644
--- a/src/Globals.h
+++ b/src/Globals.h
@@ -390,6 +390,13 @@ using cTickTimeLong = std::chrono::duration<Int64, cTickTime::period>;
#error TOLUA_EXPOSITION should never actually be defined
#endif
+template <typename T>
+auto ToUnsigned(T a_Val)
+{
+ ASSERT(a_Val >= 0);
+ return static_cast<std::make_unsigned_t<T>>(a_Val);
+}
+
diff --git a/src/LazyArray.h b/src/LazyArray.h
index 7015d6c47..310a1e2c6 100644
--- a/src/LazyArray.h
+++ b/src/LazyArray.h
@@ -83,7 +83,7 @@ public:
{
if (m_Array == nullptr)
{
- m_Array.reset(new T[m_Size]);
+ m_Array.reset(new T[ToUnsigned(m_Size)]);
}
return m_Array.get();
}
diff --git a/src/Noise/OctavedNoise.h b/src/Noise/OctavedNoise.h
index 6dd79365f..b9f3d132e 100644
--- a/src/Noise/OctavedNoise.h
+++ b/src/Noise/OctavedNoise.h
@@ -61,7 +61,7 @@ public:
std::unique_ptr<NOISE_DATATYPE[]> workspaceHeap;
if (a_Workspace == nullptr)
{
- workspaceHeap.reset(new NOISE_DATATYPE[a_SizeX * a_SizeY]);
+ workspaceHeap.reset(new NOISE_DATATYPE[ToUnsigned(a_SizeX * a_SizeY)]);
a_Workspace = workspaceHeap.get();
}
@@ -121,7 +121,7 @@ public:
std::unique_ptr<NOISE_DATATYPE[]> workspaceHeap;
if (a_Workspace == nullptr)
{
- workspaceHeap.reset(new NOISE_DATATYPE[a_SizeX * a_SizeY * a_SizeZ]);
+ workspaceHeap.reset(new NOISE_DATATYPE[ToUnsigned(a_SizeX * a_SizeY * a_SizeZ)]);
a_Workspace = workspaceHeap.get();
}
diff --git a/src/Simulator/DelayedFluidSimulator.cpp b/src/Simulator/DelayedFluidSimulator.cpp
index 784e40250..d4537656d 100644
--- a/src/Simulator/DelayedFluidSimulator.cpp
+++ b/src/Simulator/DelayedFluidSimulator.cpp
@@ -44,7 +44,7 @@ bool cDelayedFluidSimulatorChunkData::cSlot::Add(int a_RelX, int a_RelY, int a_R
// cDelayedFluidSimulatorChunkData:
cDelayedFluidSimulatorChunkData::cDelayedFluidSimulatorChunkData(int a_TickDelay) :
- m_Slots(new cSlot[a_TickDelay])
+ m_Slots(new cSlot[ToUnsigned(a_TickDelay)])
{
}