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:
parent
b609c4eb86
commit
445ecf961f
@ -1037,11 +1037,30 @@ char *UTIL_ReplaceEx(char *subject, size_t maxLen, const char *search, size_t se
|
|||||||
size_t textLen = strlen(subject);
|
size_t textLen = strlen(subject);
|
||||||
|
|
||||||
/* It's not possible to search or replace */
|
/* It's not possible to search or replace */
|
||||||
if (searchLen > textLen || maxLen <= 1)
|
if (searchLen > textLen)
|
||||||
{
|
{
|
||||||
return NULL;
|
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 */
|
/* Subtract one off the maxlength so we can include the null terminator */
|
||||||
maxLen--;
|
maxLen--;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user