aboutsummaryrefslogtreecommitdiff
path: root/src/script
diff options
context:
space:
mode:
authorMetaDucky <metaducky AT gmail DOT com>2013-05-26 12:06:35 +0200
committerKahrl <kahrl@gmx.net>2013-06-01 14:45:43 +0200
commitc893958bb1a7b6ef08b15914e081ba3df5153693 (patch)
treef568c50b87cbee0552b378816780c264eaf0a348 /src/script
parentdb9c86d6c176d40d68caf5a6b5e3bbeac9132e97 (diff)
downloadminetest-c893958bb1a7b6ef08b15914e081ba3df5153693.tar.gz
minetest-c893958bb1a7b6ef08b15914e081ba3df5153693.tar.bz2
minetest-c893958bb1a7b6ef08b15914e081ba3df5153693.zip
Fix some nullptr exceptions when handling invalid node inventories
Diffstat (limited to 'src/script')
-rw-r--r--src/script/lua_api/l_inventory.cpp15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/script/lua_api/l_inventory.cpp b/src/script/lua_api/l_inventory.cpp
index 1404c3c8a..f57a4e8cd 100644
--- a/src/script/lua_api/l_inventory.cpp
+++ b/src/script/lua_api/l_inventory.cpp
@@ -121,6 +121,9 @@ int InvRef::l_set_size(lua_State *L)
const char *listname = luaL_checkstring(L, 2);
int newsize = luaL_checknumber(L, 3);
Inventory *inv = getinv(L, ref);
+ if(inv == NULL){
+ return 0;
+ }
if(newsize == 0){
inv->deleteList(listname);
reportInventoryChange(L, ref);
@@ -144,6 +147,9 @@ int InvRef::l_set_width(lua_State *L)
const char *listname = luaL_checkstring(L, 2);
int newwidth = luaL_checknumber(L, 3);
Inventory *inv = getinv(L, ref);
+ if(inv == NULL){
+ return 0;
+ }
InventoryList *list = inv->getList(listname);
if(list){
list->setWidth(newwidth);
@@ -195,7 +201,11 @@ int InvRef::l_get_list(lua_State *L)
InvRef *ref = checkobject(L, 1);
const char *listname = luaL_checkstring(L, 2);
Inventory *inv = getinv(L, ref);
- push_inventory_list(inv, listname, L);
+ if(inv){
+ push_inventory_list(inv, listname, L);
+ } else {
+ lua_pushnil(L);
+ }
return 1;
}
@@ -206,6 +216,9 @@ int InvRef::l_set_list(lua_State *L)
InvRef *ref = checkobject(L, 1);
const char *listname = luaL_checkstring(L, 2);
Inventory *inv = getinv(L, ref);
+ if(inv == NULL){
+ return 0;
+ }
InventoryList *list = inv->getList(listname);
if(list)
read_inventory_list(inv, listname, L, 3,