From 2e3bb9206d2f53ce4b9d48207b52a1ec79f88860 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Sun, 14 Mar 2021 14:41:12 +0100 Subject: [PATCH] :bug: Fix uninitialized values for items generated in a loop Fixes #1121 --- Source/items.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Source/items.cpp b/Source/items.cpp index 7a3c7d15a..8d1f87781 100644 --- a/Source/items.cpp +++ b/Source/items.cpp @@ -1765,7 +1765,7 @@ void GetStaffSpell(int i, int lvl, BOOL onlygood) lvl = 10; int s = SPL_FIREBOLT; - enum spell_id bs = SPL_NULL; + enum spell_id bs = SPL_NULL; while (rv > 0) { int sLevel = GetSpellStaffLevel(s); if (sLevel != -1 && l >= sLevel) { @@ -5328,13 +5328,14 @@ void CreateSpellBook(int x, int y, int ispell, BOOL sendmsg, BOOL delta) return; int ii = AllocateItem(); - GetSuperItemSpace(x, y, ii); while (true) { + memset(&item[ii], 0, sizeof(*item)); SetupAllItems(ii, idx, AdvanceRndSeed(), 2 * lvl, 1, TRUE, FALSE, delta); if (item[ii]._iMiscId == IMISC_BOOK && item[ii]._iSpell == ispell) break; } + GetSuperItemSpace(x, y, ii); if (sendmsg) NetSendCmdDItem(FALSE, ii); @@ -5348,16 +5349,17 @@ static void CreateMagicItem(int x, int y, int lvl, int imisc, int imid, int icur return; int ii = AllocateItem(); - GetSuperItemSpace(x, y, ii); int idx = RndTypeItems(imisc, imid, lvl); while (true) { + memset(&item[ii], 0, sizeof(*item)); SetupAllItems(ii, idx, AdvanceRndSeed(), 2 * lvl, 1, TRUE, FALSE, delta); if (item[ii]._iCurs == icurs) break; idx = RndTypeItems(imisc, imid, lvl); } + GetSuperItemSpace(x, y, ii); if (sendmsg) NetSendCmdDItem(FALSE, ii);