fixed amb1686 - ReplaceString or ReplaceStringEx with an empty search string would crash. it now throws an error instead.

--HG--
extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%402220
This commit is contained in:
David Anderson 2008-05-29 05:39:29 +00:00
parent 049f63e6fd
commit 1a86604d99

View File

@ -460,6 +460,10 @@ static cell_t ReplaceString(IPluginContext *pContext, const cell_t *params)
pContext->LocalToString(params[4], &replace);
maxlength = (size_t)params[2];
if (search[0] == '\0')
{
return pContext->ThrowNativeError("Cannot replace searches of empty strings");
}
return UTIL_ReplaceAll(text, maxlength, search, replace);
}
@ -477,6 +481,11 @@ static cell_t ReplaceStringEx(IPluginContext *pContext, const cell_t *params)
size_t searchLen = (params[5] == -1) ? strlen(search) : (size_t)params[5];
size_t replaceLen = (params[6] == -1) ? strlen(replace) : (size_t)params[6];
if (searchLen == 0)
{
return pContext->ThrowNativeError("Cannot replace searches of empty strings");
}
char *ptr = UTIL_ReplaceEx(text, maxlength, search, searchLen, replace, replaceLen);
if (ptr == NULL)