From 46cd4e737a5a74f823877c1fd00a6af84005612f Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Fri, 7 May 2010 03:58:26 +0300 Subject: Fix reading arrays at index -1. Signed-off-by: Jared Adams --- src/gui/widgets/emoteshortcutcontainer.cpp | 3 ++- src/gui/widgets/itemshortcutcontainer.cpp | 12 ++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/gui/widgets/emoteshortcutcontainer.cpp b/src/gui/widgets/emoteshortcutcontainer.cpp index 2b07ad1e..82fb9f8d 100644 --- a/src/gui/widgets/emoteshortcutcontainer.cpp +++ b/src/gui/widgets/emoteshortcutcontainer.cpp @@ -124,11 +124,12 @@ void EmoteShortcutContainer::mouseDragged(gcn::MouseEvent &event) if (!mEmoteMoved && mEmoteClicked) { const int index = getIndexFromGrid(event.getX(), event.getY()); - const int emoteId = emoteShortcut->getEmote(index); if (index == -1) return; + const int emoteId = emoteShortcut->getEmote(index); + if (emoteId) { mEmoteMoved = emoteId; diff --git a/src/gui/widgets/itemshortcutcontainer.cpp b/src/gui/widgets/itemshortcutcontainer.cpp index 92e3e2e5..83efd4d4 100644 --- a/src/gui/widgets/itemshortcutcontainer.cpp +++ b/src/gui/widgets/itemshortcutcontainer.cpp @@ -142,9 +142,13 @@ void ItemShortcutContainer::mouseDragged(gcn::MouseEvent &event) if (!mItemMoved && mItemClicked) { const int index = getIndexFromGrid(event.getX(), event.getY()); + + if (index == -1) + return; + const int itemId = itemShortcut->getItem(index); - if (index == -1 || itemId < 0) + if (itemId < 0) return; Item *item = player_node->getInventory()->findItem(itemId); @@ -227,9 +231,13 @@ void ItemShortcutContainer::mouseReleased(gcn::MouseEvent &event) void ItemShortcutContainer::mouseMoved(gcn::MouseEvent &event) { const int index = getIndexFromGrid(event.getX(), event.getY()); + + if (index == -1) + return; + const int itemId = itemShortcut->getItem(index); - if (index == -1 || itemId < 0) + if (itemId < 0) return; Item *item = player_node->getInventory()->findItem(itemId); -- cgit v1.2.3-60-g2f50