diff --git a/engine/inc/C4ValueList.h b/engine/inc/C4ValueList.h index c6c452454..a04b70be9 100644 --- a/engine/inc/C4ValueList.h +++ b/engine/inc/C4ValueList.h @@ -44,7 +44,15 @@ public: void Sort(class C4SortObject &rSort); - const C4Value &GetItem(int32_t iElem) const { return Inside(iElem, 0, iSize-1) ? pData[iElem] : C4VNull; } + const C4Value &GetItem(int32_t iElem) const + { + if (-iSize <= iElem && iElem < 0) + return pData[iSize + iElem]; + else if (0 <= iElem && iElem < iSize) + return pData[iElem]; + else + return C4VNull; + } C4Value &GetItem(int32_t iElem); C4Value operator[](int32_t iElem) const { return GetItem(iElem); } diff --git a/engine/src/C4ValueList.cpp b/engine/src/C4ValueList.cpp index 32160658b..82726fda4 100644 --- a/engine/src/C4ValueList.cpp +++ b/engine/src/C4ValueList.cpp @@ -106,8 +106,11 @@ void C4ValueList::Sort(class C4SortObject &rSort) C4Value &C4ValueList::GetItem(int32_t iElem) { - if(iElem < 0) iElem = 0; - if(iElem >= iSize && iElem < MaxSize) this->SetSize(iElem + 1); + if(iElem < -iSize) + throw new C4AulExecError(NULL,"invalid subscript"); + else if(iElem < 0) + iElem = iSize + iElem; + else if(iElem >= iSize && iElem < MaxSize) this->SetSize(iElem + 1); // out-of-memory? This might not be catched, but it's better than a segfault if(iElem >= iSize) throw new C4AulExecError(NULL,"out of memory");