Make GetStringTableData native binary-safe (#1232)
Replace StringToLocalUTF8 with LocalToString and memcpy to make this binary compatible and update the documentation.
This commit is contained in:
parent
1d98c3a782
commit
25462071df
@ -184,8 +184,7 @@ static cell_t GetStringTableData(IPluginContext *pContext, const cell_t *params)
|
|||||||
INetworkStringTable *pTable = netstringtables->GetTable(idx);
|
INetworkStringTable *pTable = netstringtables->GetTable(idx);
|
||||||
int stringidx;
|
int stringidx;
|
||||||
const char *userdata;
|
const char *userdata;
|
||||||
int datalen;
|
int datalen = 0;
|
||||||
size_t numBytes;
|
|
||||||
|
|
||||||
if (!pTable)
|
if (!pTable)
|
||||||
{
|
{
|
||||||
@ -199,12 +198,22 @@ static cell_t GetStringTableData(IPluginContext *pContext, const cell_t *params)
|
|||||||
}
|
}
|
||||||
|
|
||||||
userdata = (const char *)pTable->GetStringUserData(stringidx, &datalen);
|
userdata = (const char *)pTable->GetStringUserData(stringidx, &datalen);
|
||||||
if (!userdata)
|
|
||||||
{
|
|
||||||
userdata = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
pContext->StringToLocalUTF8(params[3], params[4], userdata, &numBytes);
|
char *addr;
|
||||||
|
pContext->LocalToString(params[3], &addr);
|
||||||
|
|
||||||
|
int maxBytes = params[4];
|
||||||
|
size_t numBytes = MIN(maxBytes, datalen);
|
||||||
|
|
||||||
|
if (userdata)
|
||||||
|
{
|
||||||
|
memcpy(addr, userdata, numBytes);
|
||||||
|
}
|
||||||
|
else if (maxBytes > 0)
|
||||||
|
{
|
||||||
|
addr[0] = '\0';
|
||||||
|
numBytes = 0;
|
||||||
|
}
|
||||||
|
|
||||||
return numBytes;
|
return numBytes;
|
||||||
}
|
}
|
||||||
|
@ -119,9 +119,9 @@ native int GetStringTableDataLength(int tableidx, int stringidx);
|
|||||||
*
|
*
|
||||||
* @param tableidx A string table index.
|
* @param tableidx A string table index.
|
||||||
* @param stringidx A string index.
|
* @param stringidx A string index.
|
||||||
* @param userdata Buffer to store the user data. This will be set to "" if there is no user data.
|
* @param userdata Buffer to store the user data. This will be set to "" if there is no user data
|
||||||
* @param maxlength Maximum length of string buffer.
|
* @param maxlength Maximum length of string buffer.
|
||||||
* @return Number of bytes written to the buffer (UTF-8 safe).
|
* @return Number of bytes written to the buffer (binary safe, includes the null terminator).
|
||||||
* @error Invalid string table index or string index.
|
* @error Invalid string table index or string index.
|
||||||
*/
|
*/
|
||||||
native int GetStringTableData(int tableidx, int stringidx, char[] userdata, int maxlength);
|
native int GetStringTableData(int tableidx, int stringidx, char[] userdata, int maxlength);
|
||||||
@ -133,10 +133,9 @@ native int GetStringTableData(int tableidx, int stringidx, char[] userdata, int
|
|||||||
* @param stringidx A string index.
|
* @param stringidx A string index.
|
||||||
* @param userdata User data string that will be set.
|
* @param userdata User data string that will be set.
|
||||||
* @param length Length of user data string. This should include the null terminator.
|
* @param length Length of user data string. This should include the null terminator.
|
||||||
* @return Number of bytes written to the buffer (UTF-8 safe).
|
|
||||||
* @error Invalid string table index or string index.
|
* @error Invalid string table index or string index.
|
||||||
*/
|
*/
|
||||||
native int SetStringTableData(int tableidx, int stringidx, const char[] userdata, int length);
|
native void SetStringTableData(int tableidx, int stringidx, const char[] userdata, int length);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a string to a given string table.
|
* Adds a string to a given string table.
|
||||||
|
Loading…
Reference in New Issue
Block a user