From a88fd9951f8e4faa48e0ea328df203c13e247fb1 Mon Sep 17 00:00:00 2001 From: dshaligram Date: Fri, 5 Oct 2007 10:58:57 +0000 Subject: Refix &Z crash-fix, which didn't actually fix the crash. :P git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@2335 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/spl-util.cc | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 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 e4065c2beb..918592a9ef 100644 --- a/crawl-ref/source/spl-util.cc +++ b/crawl-ref/source/spl-util.cc @@ -75,34 +75,27 @@ void init_spell_descs(void) spell_list[spelldata[i].id] = i; } // end init_spell_descs() -spell_type spell_by_name(const char* name) +spell_type spell_by_name(std::string name) { - if (name == NULL || strlen(name) == 0) + if (name.empty()) return (SPELL_NO_SPELL); - char spname[80]; - + lowercase(name); + for (int i = 0; i < NUM_SPELLS; i++) { spell_type type = static_cast(i); const char *sptitle = spell_title(type); if (!sptitle) continue; - - strncpy( spname, sptitle, sizeof( spname ) ); - if (strcasecmp(spname, name) == 0) + if (name == lowercase_string(sptitle)) return (type); } return (SPELL_NO_SPELL); } -spell_type spell_by_name(std::string name) -{ - return spell_by_name(name.c_str()); -} - int get_spell_slot_by_letter( char letter ) { ASSERT( isalpha( letter ) ); @@ -834,7 +827,8 @@ int spell_type2skill(unsigned int spelltype) //jmf: simplified; moved init code to top function, init_spell_descs() static spell_desc *seekspell(spell_type spell) { - return (&spelldata[spell_list[spell]]); + const int index = spell_list[spell]; + return (index != -1? &spelldata[index] : NULL); } static bool cloud_helper(int (*func)(int, int, int, cloud_type, kill_category), -- cgit v1.2.3-54-g00ecf