Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 38 additions & 13 deletions amxmodx/trie_natives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,15 +200,30 @@ static cell AMX_NATIVE_CALL TrieGetString(AMX *amx, cell *params)

int len;
const char *key = get_amxstring(amx, params[2], 0, len);
cell *pSize = get_amxaddr(amx, params[5]);

cell *refSize {};
if (*params / sizeof(cell) >= 5)
{
refSize = get_amxaddr(amx, params[5]);
}

StringHashMap<Entry>::Result r = t->map.find(key);
if (!r.found() || !r->value.isString())
{
if (refSize)
{
*refSize = 0;
}

return 0;
}

*pSize = (cell)set_amxstring_utf8(amx, params[3], r->value.chars(), strlen(r->value.chars()), params[4]);
auto size = (cell)set_amxstring_utf8(amx, params[3], r->value.chars(), strlen(r->value.chars()), params[4]);

if (refSize)
{
*refSize = size;
}

return 1;
}
Expand All @@ -233,34 +248,44 @@ static cell AMX_NATIVE_CALL TrieGetArray(AMX *amx, cell *params)
int len;
const char *key = get_amxstring(amx, params[2], 0, len);
cell *pValue = get_amxaddr(amx, params[3]);
cell *pSize = get_amxaddr(amx, params[5]);

cell *refSize {};
if (*params / sizeof(cell) >= 5)
{
refSize = get_amxaddr(amx, params[5]);
}

StringHashMap<Entry>::Result r = t->map.find(key);
if (!r.found() || !r->value.isArray())
{
return 0;
}

if (!r->value.array())
if (!r->value.array() || !params[4])
{
*pSize = 0;
return 1;
}
if (refSize)
{
*refSize = 0;
}

if (!params[4])
{
return 1;
}

size_t length = r->value.arrayLength();
cell *base = r->value.array();

if (length > size_t(params[4]))
*pSize = params[4];
else
*pSize = length;
{
length = params[4];
}

if (refSize)
{
*refSize = length;
}

memcpy(pValue, base, sizeof(cell) * length);

memcpy(pValue, base, sizeof(cell) * pSize[0]);
return 1;
}

Expand Down