From 0bdd2768ffc88560de411b5224883e4f161519b4 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Wed, 15 Oct 2014 19:46:43 +0200 Subject: 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 6a3d08679..7ebc419cb 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; } -- cgit v1.2.3