From 8139324f50a0685218d606c7e89e44f3c3ab9da8 Mon Sep 17 00:00:00 2001 From: haranp Date: Wed, 10 Jun 2009 22:15:27 +0000 Subject: Fix 2800089: the standard does not guarantee that you can convert from integer types to pointers and back. While we're at it, fix an older bug which might trigger if we ever have a platform where different pointer types have different sizes. Technically the standard does not guarantee (I think) that this isn't the case. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@9947 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/abl-show.cc | 8 ++++---- crawl-ref/source/spl-book.cc | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'crawl-ref') diff --git a/crawl-ref/source/abl-show.cc b/crawl-ref/source/abl-show.cc index 30d4e972b5..c811679bef 100644 --- a/crawl-ref/source/abl-show.cc +++ b/crawl-ref/source/abl-show.cc @@ -1985,7 +1985,7 @@ int choose_ability_menu(const std::vector& talents) { MenuEntry* me = new MenuEntry(_describe_talent(talents[i]), MEL_ITEM, 1, talents[i].hotkey); - me->data = reinterpret_cast(numbers+i); + me->data = &numbers[i]; abil_menu.add_entry(me); } } @@ -1999,7 +1999,7 @@ int choose_ability_menu(const std::vector& talents) { MenuEntry* me = new MenuEntry(_describe_talent(talents[i]), MEL_ITEM, 1, talents[i].hotkey); - me->data = reinterpret_cast(numbers+i); + me->data = &numbers[i]; abil_menu.add_entry(me); } } @@ -2015,12 +2015,12 @@ int choose_ability_menu(const std::vector& talents) ASSERT(sel.size() == 1); ASSERT(sel[0]->hotkeys.size() == 1); - int selected = *(reinterpret_cast(sel[0]->data)); + int selected = *(static_cast(sel[0]->data)); if (abil_menu.menu_action == Menu::ACT_EXAMINE) _print_talent_description(talents[selected]); else - return (*(reinterpret_cast(sel[0]->data))); + return (*(static_cast(sel[0]->data))); } } diff --git a/crawl-ref/source/spl-book.cc b/crawl-ref/source/spl-book.cc index c400cbf099..bf83e90f73 100644 --- a/crawl-ref/source/spl-book.cc +++ b/crawl-ref/source/spl-book.cc @@ -1523,7 +1523,7 @@ static spell_type _choose_mem_spell(spell_list &spells, MenuEntry* me = new MenuEntry(desc.str(), MEL_ITEM, 1, index_to_letter(i % 52)); - me->data = (void*) i; + me->data = &spells[i]; spell_menu.add_entry(me); } @@ -1539,7 +1539,7 @@ static spell_type _choose_mem_spell(spell_list &spells, ASSERT(sel.size() == 1); - const spell_type spell = spells[(int) sel[0]->data]; + const spell_type spell = *static_cast(sel[0]->data); ASSERT(is_valid_spell(spell)); return (spell); -- cgit v1.2.3-54-g00ecf