From aa4e60ae27d6499231279175a496ce79a446452a Mon Sep 17 00:00:00 2001 From: Arkshine Date: Thu, 7 Aug 2014 20:40:07 +0200 Subject: [PATCH 1/2] Fix a compatibility issue with the "reserved" parameter. --- amxmodx/datastructs.cpp | 15 ++------------- amxmodx/datastructs.h | 5 +++-- 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/amxmodx/datastructs.cpp b/amxmodx/datastructs.cpp index 420ca221..f4765976 100644 --- a/amxmodx/datastructs.cpp +++ b/amxmodx/datastructs.cpp @@ -41,25 +41,14 @@ static cell AMX_NATIVE_CALL ArrayCreate(AMX* amx, cell* params) { if (VectorHolder[i]==NULL) { - VectorHolder[i] = new CellArray(cellsize); - - if (reserved > 0) - { - VectorHolder[i]->resize(reserved); - } - + VectorHolder[i] = new CellArray(cellsize, reserved); return i + 1; } } // None are NULL, create a new vector - CellArray* NewVector = new CellArray(cellsize); + CellArray* NewVector = new CellArray(cellsize, reserved); - if (reserved > 0) - { - NewVector->resize(reserved); - } - VectorHolder.append(NewVector); return VectorHolder.length(); diff --git a/amxmodx/datastructs.h b/amxmodx/datastructs.h index d72bb147..90ce018d 100644 --- a/amxmodx/datastructs.h +++ b/amxmodx/datastructs.h @@ -15,7 +15,7 @@ class CellArray { public: - CellArray(size_t blocksize) : m_Data(NULL), m_BlockSize(blocksize), m_AllocSize(0), m_Size(0) + CellArray(size_t blocksize, size_t basesize = 0) : m_Data(NULL), m_BlockSize(blocksize), m_AllocSize(0), m_BaseSize(basesize > 0 ? basesize : 8), m_Size(0) { } @@ -160,7 +160,7 @@ private: /* Set a base allocation size of 8 items */ if (!m_AllocSize) { - m_AllocSize = 8; + m_AllocSize = m_BaseSize; } /* If it's not enough, keep doubling */ while (m_Size + count > m_AllocSize) @@ -181,6 +181,7 @@ private: cell *m_Data; size_t m_BlockSize; size_t m_AllocSize; + size_t m_BaseSize; size_t m_Size; }; From 72b514cddeaa9794ddc30e1a6e7451f18ddbb644 Mon Sep 17 00:00:00 2001 From: Arkshine Date: Thu, 7 Aug 2014 21:31:53 +0200 Subject: [PATCH 2/2] Make sure reserved parameter is a not a negative value. --- amxmodx/datastructs.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/amxmodx/datastructs.cpp b/amxmodx/datastructs.cpp index f4765976..b7ba95a4 100644 --- a/amxmodx/datastructs.cpp +++ b/amxmodx/datastructs.cpp @@ -35,6 +35,11 @@ static cell AMX_NATIVE_CALL ArrayCreate(AMX* amx, cell* params) return -1; } + if (reserved < 0) + { + reserved = 0; + } + // Scan through the vector list to see if any are NULL. // NULL means the vector was previously destroyed. for (unsigned int i=0; i < VectorHolder.length(); ++i)