Log in

View Full Version : Possible divide by 0 unhandled in AddLootDropToNPC


fourier
05-16-2010, 08:59 AM
Not sure if this should be posted here or on projecteq since its a database issue unhandled by code. I noticed this happened in code and matching db revision 1410. In loottables.cpp in function (with non pool based looting enabled):


void ZoneDatabase::AddLootDropToNPC(NPC* npc,int32 lootdrop_id, ItemList* itemlist)

.....

unsigned int drop_chance = rand() % totalchance;


If totalchance is 0 as a result of:


// line 396:
for (r = 0; r < lds->NumEntries; r++) {
totalchance += lds->Entries[r].chance;
}


Then drop_chance will not be assigned and a divide by 0 error will occur. Mathematically , x % 0 should return x (Knuth says), but it seems c++ treats it as a dbz.

I fixed this by deleting rows in lootdrop_entries that had 0 value for the chance column. One example was ssratemple's shissar lorekeeper, if i recall correctly.

joligario
05-16-2010, 10:58 AM
Good catch on the 0% chances. I am fixing PEQ's database on this right now. There were 11 entries total as of the last database push.