summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/spl-util.cc
diff options
context:
space:
mode:
authorzelgadis <zelgadis@c06c8d41-db1a-0410-9941-cceddc491573>2008-12-21 03:57:31 +0000
committerzelgadis <zelgadis@c06c8d41-db1a-0410-9941-cceddc491573>2008-12-21 03:57:31 +0000
commit8a71071e3d9dd698f31846f2261e5b77ca7085c8 (patch)
tree6aa1c6e81a2d8e4accc556597d9642ac5b2e10f7 /crawl-ref/source/spl-util.cc
parent0e1304a15a7c5fd3a5dbe3b24f4722aeef8578f2 (diff)
downloadcrawl-ref-8a71071e3d9dd698f31846f2261e5b77ca7085c8.tar.gz
crawl-ref-8a71071e3d9dd698f31846f2261e5b77ca7085c8.zip
Change the spell_type enumerations so that SPELL_NO_SPELL is 0 and the first
valid spell (Identify) is 1. This way any bug that causes a spell_type variable to be 0 will be recognized as an invalid spell. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@7892 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source/spl-util.cc')
-rw-r--r--crawl-ref/source/spl-util.cc11
1 files changed, 6 insertions, 5 deletions
diff --git a/crawl-ref/source/spl-util.cc b/crawl-ref/source/spl-util.cc
index c4b96b7ffa..584e297770 100644
--- a/crawl-ref/source/spl-util.cc
+++ b/crawl-ref/source/spl-util.cc
@@ -89,10 +89,7 @@ void init_spell_descs(void)
for (int i = 0; i < NUM_SPELLS; i++)
spell_list[i] = -1;
- // can only use up to SPELLDATASIZE _MINUS ONE_, or the
- // last entry tries to set spell_list[SPELL_NO_SPELL]
- // which corrupts the heap.
- for (unsigned int i = 0; i < SPELLDATASIZE - 1; i++)
+ for (unsigned int i = 0; i < SPELLDATASIZE; i++)
spell_list[spelldata[i].id] = i;
}
@@ -901,14 +898,18 @@ int spell_skill2type(unsigned int skill)
//jmf: Simplified; moved init code to top function, init_spell_descs().
static spell_desc *_seekspell(spell_type spell)
{
+ ASSERT(spell >= 0 && spell < NUM_SPELLS);
+
const int index = spell_list[spell];
ASSERT(index != -1);
+
return (&spelldata[index]);
}
bool is_valid_spell(spell_type spell)
{
- return (spell < NUM_SPELLS && spell_list[spell] != -1);
+ return (spell > SPELL_NO_SPELL && spell < NUM_SPELLS
+ && spell_list[spell] != -1);
}
static bool _cloud_helper(cloud_func func, const coord_def& where,