From: <fu...@us...> - 2009-06-22 19:57:31
|
Revision: 6584 http://gemrb.svn.sourceforge.net/gemrb/?rev=6584&view=rev Author: fuzzie Date: 2009-06-22 19:57:22 +0000 (Mon, 22 Jun 2009) Log Message: ----------- try to fix segfaults caused by Spellbook::AddSpellMemorization adding NULLs Modified Paths: -------------- gemrb/trunk/gemrb/plugins/Core/Spellbook.cpp Modified: gemrb/trunk/gemrb/plugins/Core/Spellbook.cpp =================================================================== --- gemrb/trunk/gemrb/plugins/Core/Spellbook.cpp 2009-06-22 18:30:08 UTC (rev 6583) +++ gemrb/trunk/gemrb/plugins/Core/Spellbook.cpp 2009-06-22 19:57:22 UTC (rev 6584) @@ -516,15 +516,22 @@ return false; } - while (s->size() <= level ) { - s->push_back( NULL ); + while (s->size() < level ) { + // this code previously added NULLs, leading to crashes, + // so this is an attempt to make it not broken + CRESpellMemorization *newsm = new CRESpellMemorization(); + newsm->Type = sm->Type; + newsm->Level = (ieWord) s->size(); + newsm->Number = newsm->Number2 = 0; + s->push_back( newsm ); } - if ((*s)[level]) { - return false; + // only add this one if necessary + if (s->size() == level) { + s->push_back(sm); + return true; } - (*s)[level] = sm; - return true; + return false; } //apply the wisdom bonus on all spell levels for type This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |