mirror of
https://github.com/moparisthebest/minetest
synced 2024-12-22 23:58:48 -05:00
Fix invalid listname and listsize not handled correctly in set_size
This commit is contained in:
parent
35606cfb67
commit
90e7832408
@ -1726,6 +1726,7 @@ methods:
|
|||||||
- is_empty(listname): return true if list is empty
|
- is_empty(listname): return true if list is empty
|
||||||
- get_size(listname): get size of a list
|
- get_size(listname): get size of a list
|
||||||
- set_size(listname, size): set size of a list
|
- set_size(listname, size): set size of a list
|
||||||
|
^ returns false on error (e.g. invalid listname or listsize)
|
||||||
- get_width(listname): get width of a list
|
- get_width(listname): get width of a list
|
||||||
- set_width(listname, width): set width of list; currently used for crafting
|
- set_width(listname, width): set width of list; currently used for crafting
|
||||||
- get_stack(listname, i): get a copy of stack index i in list
|
- get_stack(listname, i): get a copy of stack index i in list
|
||||||
|
@ -957,6 +957,9 @@ InventoryList * Inventory::addList(const std::string &name, u32 size)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
//don't create list with invalid name
|
||||||
|
if (name.find(" ") != std::string::npos) return NULL;
|
||||||
|
|
||||||
InventoryList *list = new InventoryList(name, size, m_itemdef);
|
InventoryList *list = new InventoryList(name, size, m_itemdef);
|
||||||
m_lists.push_back(list);
|
m_lists.push_back(list);
|
||||||
return list;
|
return list;
|
||||||
|
@ -117,24 +117,38 @@ int InvRef::l_set_size(lua_State *L)
|
|||||||
NO_MAP_LOCK_REQUIRED;
|
NO_MAP_LOCK_REQUIRED;
|
||||||
InvRef *ref = checkobject(L, 1);
|
InvRef *ref = checkobject(L, 1);
|
||||||
const char *listname = luaL_checkstring(L, 2);
|
const char *listname = luaL_checkstring(L, 2);
|
||||||
|
|
||||||
int newsize = luaL_checknumber(L, 3);
|
int newsize = luaL_checknumber(L, 3);
|
||||||
|
if (newsize < 0) {
|
||||||
|
lua_pushboolean(L, false);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
Inventory *inv = getinv(L, ref);
|
Inventory *inv = getinv(L, ref);
|
||||||
if(inv == NULL){
|
if(inv == NULL){
|
||||||
return 0;
|
lua_pushboolean(L, false);
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
if(newsize == 0){
|
if(newsize == 0){
|
||||||
inv->deleteList(listname);
|
inv->deleteList(listname);
|
||||||
reportInventoryChange(L, ref);
|
reportInventoryChange(L, ref);
|
||||||
return 0;
|
lua_pushboolean(L, true);
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
InventoryList *list = inv->getList(listname);
|
InventoryList *list = inv->getList(listname);
|
||||||
if(list){
|
if(list){
|
||||||
list->setSize(newsize);
|
list->setSize(newsize);
|
||||||
} else {
|
} else {
|
||||||
list = inv->addList(listname, newsize);
|
list = inv->addList(listname, newsize);
|
||||||
|
if (!list)
|
||||||
|
{
|
||||||
|
lua_pushboolean(L, false);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
reportInventoryChange(L, ref);
|
reportInventoryChange(L, ref);
|
||||||
return 0;
|
lua_pushboolean(L, true);
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// set_width(self, listname, size)
|
// set_width(self, listname, size)
|
||||||
|
Loading…
Reference in New Issue
Block a user