fixed a bug where UTIL_ReplaceAll() did not work on a buffer size of 1 even if the other inputs were valid

--HG--
extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401511
This commit is contained in:
David Anderson 2007-09-30 02:16:37 +00:00
parent b609c4eb86
commit 445ecf961f

View File

@ -1037,11 +1037,30 @@ char *UTIL_ReplaceEx(char *subject, size_t maxLen, const char *search, size_t se
size_t textLen = strlen(subject);
/* It's not possible to search or replace */
if (searchLen > textLen || maxLen <= 1)
if (searchLen > textLen)
{
return NULL;
}
/* Handle the case of one byte replacement.
* It's only valid in one case.
*/
if (maxLen == 1)
{
/* If the search matches and the replace length is 0,
* we can just terminate the string and be done.
*/
if (strcmp(subject, search) == 0 && replaceLen == 0)
{
*subject = '\0';
return subject;
}
else
{
return NULL;
}
}
/* Subtract one off the maxlength so we can include the null terminator */
maxLen--;