Skip to content

Commit

Permalink
Fixed possible crash
Browse files Browse the repository at this point in the history
It could crash if MinAmount - MaxAmount was 0 because it would execute (Number % 0)
  • Loading branch information
NiLSPACE committed Oct 15, 2014
1 parent 06b4664 commit 0bdd276
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/ItemGrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 0bdd276

Please sign in to comment.