From 0bdd2768ffc88560de411b5224883e4f161519b4 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Wed, 15 Oct 2014 19:46:43 +0200 Subject: [PATCH 1/2] Fixed possible crash It could crash if MinAmount - MaxAmount was 0 because it would execute (Number % 0) --- src/ItemGrid.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/ItemGrid.cpp b/src/ItemGrid.cpp index 6a3d0867..7ebc419c 100644 --- a/src/ItemGrid.cpp +++ b/src/ItemGrid.cpp @@ -658,7 +658,14 @@ void cItemGrid::GenerateRandomLootWithBooks(const cLootProbab * a_LootProbabs, s if (LootRnd < 0) { CurrentLoot = a_LootProbabs[i].m_Item; - CurrentLoot.m_ItemCount = a_LootProbabs[i].m_MinAmount + (Rnd % (a_LootProbabs[i].m_MaxAmount - a_LootProbabs[i].m_MinAmount)); + if ((a_LootProbabs[i].m_MaxAmount - a_LootProbabs[i].m_MinAmount) > 0) + { + CurrentLoot.m_ItemCount = a_LootProbabs[i].m_MinAmount + (Rnd % (a_LootProbabs[i].m_MaxAmount - a_LootProbabs[i].m_MinAmount)); + } + else + { + CurrentLoot.m_ItemCount = a_LootProbabs[i].m_MinAmount; + } Rnd >>= 8; break; } From 799ae87d3fe17e37462cf26f902fdc3565e4b562 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Thu, 16 Oct 2014 11:00:15 +0200 Subject: [PATCH 2/2] BioGen: Fixed a compiler warning. --- src/Generating/BioGen.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Generating/BioGen.cpp b/src/Generating/BioGen.cpp index 8924a799..9b3d4e98 100644 --- a/src/Generating/BioGen.cpp +++ b/src/Generating/BioGen.cpp @@ -760,8 +760,8 @@ void cBioGenTwoLevel::GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap int DistortZ[cChunkDef::Width + 1][cChunkDef::Width + 1]; for (int x = 0; x <= 4; x++) for (int z = 0; z <= 4; z++) { - float BlockX = BaseX + x * 4; - float BlockZ = BaseZ + z * 4; + float BlockX = static_cast(BaseX + x * 4); + float BlockZ = static_cast(BaseZ + z * 4); double NoiseX = m_AmpX1 * m_Noise1.CubicNoise2D(BlockX * m_FreqX1, BlockZ * m_FreqX1); NoiseX += m_AmpX2 * m_Noise2.CubicNoise2D(BlockX * m_FreqX2, BlockZ * m_FreqX2); NoiseX += m_AmpX3 * m_Noise3.CubicNoise2D(BlockX * m_FreqX3, BlockZ * m_FreqX3);