Fixed null pointer dereference errors found by cppcheck
authorJoshua Beck <jxb091000@utdallas.edu>
Sat, 24 Sep 2011 07:11:43 +0000 (02:11 -0500)
committerJoshua Beck <jxb091000@utdallas.edu>
Sat, 24 Sep 2011 07:11:43 +0000 (02:11 -0500)
src/environment.cpp
src/server.cpp

index 8103b7110436ddf3c7c4c8de7eb2678b9b5e3a59..07c535b70748cdf6a1ddae4f7281a1c5a1fc6e26 100644 (file)
@@ -1345,8 +1345,6 @@ void ServerEnvironment::deactivateFarObjects(bool force_delete)
                        i.atEnd()==false; i++)
        {
                ServerActiveObject* obj = i.getNode()->getValue();
-               u16 id = i.getNode()->getKey();
-               v3f objectpos = obj->getBasePosition();
 
                // This shouldn't happen but check it
                if(obj == NULL)
@@ -1357,9 +1355,12 @@ void ServerEnvironment::deactivateFarObjects(bool force_delete)
                        continue;
                }
 
+               u16 id = i.getNode()->getKey();         
+               v3f objectpos = obj->getBasePosition(); 
+
                // The block in which the object resides in
                v3s16 blockpos_o = getNodeBlockPos(floatToInt(objectpos, BS));
-               
+
                // If block is active, don't remove
                if(m_active_blocks.contains(blockpos_o))
                        continue;
index a04417074f9f5d3045e13a517c5cc6600def6095..ba0efe75f2522c6ee1f15a8f4114ab360bcbaaa1 100644 (file)
@@ -4109,7 +4109,7 @@ void Server::UpdateCrafting(u16 peer_id)
                InventoryList *clist = player->inventory.getList("craft");
                InventoryList *rlist = player->inventory.getList("craftresult");
 
-               if(rlist->getUsedSlots() == 0)
+               if(rlist && rlist->getUsedSlots() == 0)
                        player->craftresult_is_preview = true;
 
                if(rlist && player->craftresult_is_preview)