From 827ca0211f55e05d0ecc2319bfc4fd9f51a37053 Mon Sep 17 00:00:00 2001 From: dshaligram Date: Fri, 5 Oct 2007 09:10:34 +0000 Subject: Fixed segfault when using &Z (bobbens). git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@2334 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/spl-util.cc | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'crawl-ref/source/spl-util.cc') diff --git a/crawl-ref/source/spl-util.cc b/crawl-ref/source/spl-util.cc index eb0865091b..e4065c2beb 100644 --- a/crawl-ref/source/spl-util.cc +++ b/crawl-ref/source/spl-util.cc @@ -73,14 +73,6 @@ void init_spell_descs(void) // which corrupts the heap. for (unsigned int i = 0; i < SPELLDATASIZE - 1; i++) spell_list[spelldata[i].id] = i; - - for (int i = 0; i < NUM_SPELLS; i++) - { - if (spell_list[i] == -1) - spell_list[i] = spell_list[SPELL_NO_SPELL]; - } - - return; } // end init_spell_descs() spell_type spell_by_name(const char* name) @@ -93,7 +85,11 @@ spell_type spell_by_name(const char* name) for (int i = 0; i < NUM_SPELLS; i++) { spell_type type = static_cast(i); - strncpy( spname, spell_title(type), sizeof( spname ) ); + const char *sptitle = spell_title(type); + if (!sptitle) + continue; + + strncpy( spname, sptitle, sizeof( spname ) ); if (strcasecmp(spname, name) == 0) return (type); @@ -278,7 +274,8 @@ int count_bits(unsigned int bits) const char *spell_title(spell_type spell) { - return (seekspell(spell)->title); + const spell_desc *spd = seekspell(spell); + return (spd? spd->title : NULL); } @@ -835,7 +832,7 @@ int spell_type2skill(unsigned int spelltype) */ //jmf: simplified; moved init code to top function, init_spell_descs() -static struct spell_desc *seekspell(spell_type spell) +static spell_desc *seekspell(spell_type spell) { return (&spelldata[spell_list[spell]]); } -- cgit v1.2.3-54-g00ecf