From 12e17224b37d7db52545c00fb75c0322e0e5afad Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sun, 29 Dec 2013 16:31:32 +0100 Subject: Added nullptr shecks to object.factory() Trying to fix #275 --- src/script/script.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/script/script.cpp b/src/script/script.cpp index fbf7276..0518479 100644 --- a/src/script/script.cpp +++ b/src/script/script.cpp @@ -680,10 +680,23 @@ bool CScript::rFactory(CBotVar* thisclass, CBotVar* var, CBotVar* result, int& e classVars = classVars->GetNext(); // "id" int rank = classVars->GetValInt(); CObject* factory = CObjectManager::GetInstancePointer()->SearchInstance(rank); - CAutoFactory* automat = static_cast(factory->GetAuto()); + if (factory == nullptr) { + exception = ERR_GENERIC; + result->SetValInt(ERR_GENERIC); + CLogger::GetInstancePointer()->Error("in object.factory() - factory is nullptr"); + return false; + } if ( thisType == OBJECT_FACTORY ) { + CAutoFactory* automat = static_cast(factory->GetAuto()); + if(automat == nullptr) { + exception = ERR_GENERIC; + result->SetValInt(ERR_GENERIC); + CLogger::GetInstancePointer()->Error("in object.factory() - automat is nullptr"); + return false; + } + bool bEnable = false; if ( type == OBJECT_MOBILEwa ) -- cgit v1.2.3-1-g7c22