From 67997af67fbf7c95e78574f810aa322275b3eb66 Mon Sep 17 00:00:00 2001 From: =?utf8?q?B=C5=99etislav=20=C5=A0tec?= Date: Sat, 1 Aug 2015 14:07:12 +0200 Subject: [PATCH] src/environment.cpp: Fix NULL pointer dereference --- src/environment.cpp | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/environment.cpp b/src/environment.cpp index cf0ebacfd..5bed11476 100644 --- a/src/environment.cpp +++ b/src/environment.cpp @@ -1820,27 +1820,29 @@ void ServerEnvironment::deactivateFarObjects(bool force_delete) bool stays_in_same_block = false; bool data_changed = true; - if(obj->m_static_exists){ - if(obj->m_static_block == blockpos_o) + if (obj->m_static_exists) { + if (obj->m_static_block == blockpos_o) stays_in_same_block = true; MapBlock *block = m_map->emergeBlock(obj->m_static_block, false); - std::map::iterator n = + if (block) { + std::map::iterator n = block->m_static_objects.m_active.find(id); - if(n != block->m_static_objects.m_active.end()){ - StaticObject static_old = n->second; + if (n != block->m_static_objects.m_active.end()) { + StaticObject static_old = n->second; - float save_movem = obj->getMinimumSavedMovement(); + float save_movem = obj->getMinimumSavedMovement(); - if(static_old.data == staticdata_new && - (static_old.pos - objectpos).getLength() < save_movem) - data_changed = false; - } else { - errorstream<<"ServerEnvironment::deactivateFarObjects(): " + if (static_old.data == staticdata_new && + (static_old.pos - objectpos).getLength() < save_movem) + data_changed = false; + } else { + errorstream<<"ServerEnvironment::deactivateFarObjects(): " <<"id="<m_static_block)<