diff options
author | Andrei Karas <akaras@inbox.ru> | 2011-09-12 18:29:12 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2011-09-13 04:41:55 +0300 |
commit | 6bd4fff31e0b44b8b71876250c626fe8c15b4105 (patch) | |
tree | cdd7f984a0850864316ae23c33120b6d282b70ba /src/dropshortcut.cpp | |
parent | f457675ecfd704c99e84fe14f0a1dd49a69a9c76 (diff) | |
download | ManaVerse-6bd4fff31e0b44b8b71876250c626fe8c15b4105.tar.gz ManaVerse-6bd4fff31e0b44b8b71876250c626fe8c15b4105.tar.bz2 ManaVerse-6bd4fff31e0b44b8b71876250c626fe8c15b4105.tar.xz ManaVerse-6bd4fff31e0b44b8b71876250c626fe8c15b4105.zip |
Add missing checks to some files and style fixes.
Diffstat (limited to 'src/dropshortcut.cpp')
-rw-r--r-- | src/dropshortcut.cpp | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/dropshortcut.cpp b/src/dropshortcut.cpp index 48eed92bc..79f895490 100644 --- a/src/dropshortcut.cpp +++ b/src/dropshortcut.cpp @@ -150,6 +150,10 @@ void DropShortcut::dropItems(int cnt) bool DropShortcut::dropItem(int cnt) { + const Inventory *inv = PlayerInfo::getInventory(); + if (!inv) + return false; + int itemId = 0; unsigned char itemColor = 1; while (mLastDropIndex < DROP_SHORTCUT_ITEMS && itemId < 1) @@ -160,7 +164,7 @@ bool DropShortcut::dropItem(int cnt) } if (itemId > 0) { - Item *item = PlayerInfo::getInventory()->findItem(itemId, itemColor); + Item *item = inv->findItem(itemId, itemColor); if (item && item->getQuantity() > 0) { Net::getInventoryHandler()->dropItem(item, cnt); @@ -180,8 +184,7 @@ bool DropShortcut::dropItem(int cnt) } if (itemId > 0) { - Item *item = PlayerInfo::getInventory()->findItem( - itemId, itemColor); + Item *item = inv->findItem(itemId, itemColor); if (item && item->getQuantity() > 0) { Net::getInventoryHandler()->dropItem(item, cnt); @@ -210,6 +213,9 @@ void DropShortcut::setItemSelected(Item *item) void DropShortcut::setItem(int index) { + if (index < 0 || index >= DROP_SHORTCUT_ITEMS) + return; + mItems[index] = mItemSelected; mItemColors[index] = mItemColorSelected; save(); |