diff --git a/amxmodx/amxmodx.h b/amxmodx/amxmodx.h index 326a640e..b720a617 100755 --- a/amxmodx/amxmodx.h +++ b/amxmodx/amxmodx.h @@ -147,8 +147,8 @@ void UTIL_ShowMenu(edict_t* pEntity, int slots, int time, char *menu, int mlen); void UTIL_ClientSayText(edict_t *pEntity, int sender, char *msg); void UTIL_TeamInfo(edict_t *pEntity, int playerIndex, const char *pszTeamName); -template int UTIL_CheckValidChar(D *c); -template unsigned int strncopy(D *dest, const char *src, size_t count); +template int UTIL_CheckValidChar(D *c); +template unsigned int strncopy(D *dest, const S *src, size_t count); unsigned int UTIL_GetUTF8CharBytes(const char *stream); unsigned int UTIL_ReplaceAll(char *subject, size_t maxlength, const char *search, const char *replace, bool caseSensitive); char *UTIL_ReplaceEx(char *subject, size_t maxLen, const char *search, size_t searchLen, const char *replace, size_t replaceLen, bool caseSensitive); diff --git a/amxmodx/datastructs.cpp b/amxmodx/datastructs.cpp index 97595734..84981908 100644 --- a/amxmodx/datastructs.cpp +++ b/amxmodx/datastructs.cpp @@ -48,7 +48,6 @@ static cell AMX_NATIVE_CALL ArrayCreate(AMX* amx, cell* params) // params[2] (reserved) is how many elements to allocate // immediately when the list is created. - // this MUST be greater than 0! int reserved = params[2]; if (cellsize <= 0) @@ -56,11 +55,6 @@ static cell AMX_NATIVE_CALL ArrayCreate(AMX* amx, cell* params) LogError(amx, AMX_ERR_NATIVE, "Invalid array size (%d)", cellsize); return -1; } - if (reserved <= 0) - { - LogError(amx, AMX_ERR_NATIVE, "Invalid reserved size (%d)", reserved); - return -1; - } // Scan through the vector list to see if any are NULL. // NULL means the vector was previously destroyed. @@ -69,14 +63,23 @@ static cell AMX_NATIVE_CALL ArrayCreate(AMX* amx, cell* params) if (VectorHolder[i]==NULL) { VectorHolder[i] = new CellArray(cellsize); - //VectorHolder[i]->resize(reserved); + + if (reserved > 0) + { + VectorHolder[i]->resize(reserved); + } + return i + 1; } } // None are NULL, create a new vector CellArray* NewVector = new CellArray(cellsize); - //NewVector->resize(reserved); + + if (reserved > 0) + { + NewVector->resize(reserved); + } VectorHolder.append(NewVector); @@ -188,7 +191,7 @@ static cell AMX_NATIVE_CALL ArrayGetArray(AMX* amx, cell* params) memcpy(addr, blk, sizeof(cell) * indexes); - return 1; + return indexes; } // native any:ArrayGetCell(Array:which, item, block = 0, bool:asChar = false); @@ -288,7 +291,7 @@ static cell AMX_NATIVE_CALL ArraySetArray(AMX* amx, cell* params) memcpy(blk, addr, sizeof(cell) * indexes); - return 1; + return indexes; } // native ArraySetCell(Array:which, item, any:input, block = 0, bool:asChar = false); @@ -425,15 +428,13 @@ static cell AMX_NATIVE_CALL ArrayPushString(AMX* amx, cell* params) } cell *blk = vec->push(); - cell *start = blk; if (!blk) { LogError(amx, AMX_ERR_NATIVE, "Failed to grow array"); return 0; } - memcpy(blk, get_amxaddr(amx, params[2]), sizeof(cell) * vec->blocksize()); - blk[vec->blocksize() - 1]= '\0'; + strncopy(blk, get_amxaddr(amx, params[2]), vec->blocksize()); return static_cast((vec->size() - 1)); } @@ -634,7 +635,7 @@ static cell AMX_NATIVE_CALL ArraySwap(AMX* amx, cell* params) return 0; } - vec->swap(params[2], params[3]); + vec->swap(idx1, idx2); return 1; } diff --git a/amxmodx/util.cpp b/amxmodx/util.cpp index 4986926d..6cf45ecc 100755 --- a/amxmodx/util.cpp +++ b/amxmodx/util.cpp @@ -514,11 +514,12 @@ unsigned int UTIL_ReplaceAll(char *subject, size_t maxlength, const char *search return total; } -template unsigned int strncopy(char *, const char *src, size_t count); -template unsigned int strncopy(cell *, const char *src, size_t count); +template unsigned int strncopy(char *, const char *src, size_t count); +template unsigned int strncopy(cell *, const char *src, size_t count); +template unsigned int strncopy(cell *, const cell *src, size_t count); -template -unsigned int strncopy(D *dest, const char *src, size_t count) +template +unsigned int strncopy(D *dest, const S *src, size_t count) { if (!count) { diff --git a/plugins/include/cellarray.inc b/plugins/include/cellarray.inc index 54b47c7d..53466aab 100644 --- a/plugins/include/cellarray.inc +++ b/plugins/include/cellarray.inc @@ -39,15 +39,13 @@ stock ByteCountToCells(size) * It is very important that the cellsize you provide matches up with the buffer sizes * that you pass with subsequent Array{Get,Set,Push} calls. * - * @note As per AMX Mod X 1.8.3, reserved parameter has no effect. - * * @param cellsize How many cells each entry in the array is. * @param reserved How many blank entries are created immediately when the array is created. * These entries are not valid to read from until called with ArraySet. * * @return Handle to the array. */ -native Array:ArrayCreate(cellsize = 1, reserved = 32); +native Array:ArrayCreate(cellsize = 1, reserved = 0); /** * Clones an array, returning a new handle with the same size and data. @@ -98,9 +96,9 @@ native bool:ArrayResize(Array:which, newsize); * * @param which The array to retrieve the item from. * @param item The item to retrieve (zero-based). + * @param output The output buffer to write. * @param size If not set, assumes the buffer size is equal to the * cellsize. Otherwise, the size passed is used. - * @param output The output buffer to write. * * @return Number of cells copied. * @error Invalid handle or invalid index. @@ -109,7 +107,6 @@ native ArrayGetArray(Array:which, item, any:output[], size = -1); /** * Returns a single cell of data from an array. - * Use this only with arrays that were created with a cellsize of 1! * * @param which The array to retrieve the item from. * @param item The item to retrieve (zero-based).