Add proper error messages to GUIInventoryMenu when inventory lists are invalid
authorPerttu Ahola <celeron55@gmail.com>
Fri, 1 Jun 2012 16:33:20 +0000 (19:33 +0300)
committerPerttu Ahola <celeron55@gmail.com>
Sun, 3 Jun 2012 19:31:00 +0000 (22:31 +0300)
src/guiInventoryMenu.cpp

index f3346090666bb05b72f87ae590e5b864437e19a5..c7cff329e5c4d1dbd6ab84686df06d8abbf4e9a5 100644 (file)
@@ -531,10 +531,18 @@ bool GUIInventoryMenu::OnEvent(const SEvent& event)
                        assert(inv_s);
 
                        InventoryList *list = inv_s->getList(s.listname);
-                       if(list != NULL && (u32) s.i < list->getSize())
-                               s_count = list->getItem(s.i).count;
-                       else
+                       if(list == NULL){
+                               errorstream<<"InventoryMenu: The selected inventory list "
+                                               <<"does not exist"<<std::endl;
+                               s.i = -1;  // make it invalid again
+                       } else if((u32)s.i >= list->getSize()){
+                               errorstream<<"InventoryMenu: The selected inventory list "
+                                               <<"is too small (i="<<s.i<<", size="
+                                               <<list->getSize()<<")"<<std::endl;
                                s.i = -1;  // make it invalid again
+                       } else{
+                               s_count = list->getItem(s.i).count;
+                       }
                }
 
                bool identical = (m_selected_item != NULL) && s.isValid() &&