From 4d99a62d372e8dc99f7203dea07f6a739392e2fe Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sun, 13 Mar 2016 19:26:11 +0100 Subject: [PATCH] Fixed crash with array initialization syntax going out of range (#698) --- src/CBot/CBotInstr/CBotListArray.cpp | 6 ++++++ src/CBot/CBotVar/CBotVar.h | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/CBot/CBotInstr/CBotListArray.cpp b/src/CBot/CBotInstr/CBotListArray.cpp index 87a9aa08..20a34e6e 100644 --- a/src/CBot/CBotInstr/CBotListArray.cpp +++ b/src/CBot/CBotInstr/CBotListArray.cpp @@ -152,6 +152,12 @@ bool CBotListArray::Execute(CBotStack* &pj, CBotVar* pVar) pVar2 = pVar->GetItem(n, true); + if (pVar2 == nullptr) + { + pj->SetError(CBotErrOutArray, p->GetToken()); + return false; + } + if (!p->Execute(pile1, pVar2)) return false; // evaluate expression pile1->IncState(); diff --git a/src/CBot/CBotVar/CBotVar.h b/src/CBot/CBotVar/CBotVar.h index 2b697874..a4563b4b 100644 --- a/src/CBot/CBotVar/CBotVar.h +++ b/src/CBot/CBotVar/CBotVar.h @@ -415,7 +415,7 @@ public: * * \param index Index of the element to get * \param grow true to grow the array automatically if the index is out of range - * \return CBotVar representing the array element + * \return CBotVar representing the array element, or nullptr on error (for example going out of range) */ virtual CBotVar* GetItem(int index, bool grow = false);