Add native StringToI64 (#2449)
* Add native StringToInt64Ex * Delete useless test code * Rename native StringToInt64Ex to StringToI64 * Add documentation for out-of-bounds situations.
This commit is contained in:
@@ -156,6 +156,25 @@ static cell_t StringToInt64(IPluginContext *pCtx, const cell_t *params)
|
||||
return dummy - str;
|
||||
}
|
||||
|
||||
static cell_t StringToI64(IPluginContext *pCtx, const cell_t *params)
|
||||
{
|
||||
cell_t* out;
|
||||
if (int err = pCtx->LocalToPhysAddr(params[1], &out); err != SP_ERROR_NONE)
|
||||
return pCtx->ThrowNativeErrorEx(err, "Could not read argument (error %d)", err);
|
||||
|
||||
char *str, *dummy = nullptr;
|
||||
if (int err = pCtx->LocalToString(params[2], &str); err != SP_ERROR_NONE)
|
||||
return pCtx->ThrowNativeErrorEx(err, "Invalid str (error %d)", err);
|
||||
|
||||
cell_t *consumed;
|
||||
if (int err = pCtx->LocalToPhysAddr(params[4], &consumed); err != SP_ERROR_NONE)
|
||||
return pCtx->ThrowNativeErrorEx(err, "Invalid nConsumed (error %d)", err);
|
||||
|
||||
*reinterpret_cast<int64_t*>(out) = strtoll(str, &dummy, params[3]);
|
||||
*consumed = dummy - str;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static cell_t sm_numtostr(IPluginContext *pCtx, const cell_t *params)
|
||||
{
|
||||
char *str;
|
||||
@@ -640,6 +659,7 @@ REGISTER_NATIVES(basicStrings)
|
||||
{"StringToInt", sm_strconvint},
|
||||
{"StringToIntEx", StringToIntEx},
|
||||
{"StringToInt64", StringToInt64},
|
||||
{"StringToI64", StringToI64},
|
||||
{"StringToFloat", sm_strtofloat},
|
||||
{"StringToFloatEx", StringToFloatEx},
|
||||
{"StripQuotes", StripQuotes},
|
||||
|
||||
Reference in New Issue
Block a user