Merge pull request #374 from Arkshine/fix/util_replaceall

Fix UTIL_ReplaceAll not properly tracking length.
This commit is contained in:
Vincent Herbet 2016-06-10 15:29:33 +02:00 committed by GitHub
commit 294066ca61

View File

@ -459,11 +459,14 @@ unsigned int UTIL_ReplaceAll(char *subject, size_t maxlength, const char *search
size_t searchLen = strlen(search); size_t searchLen = strlen(search);
size_t replaceLen = strlen(replace); size_t replaceLen = strlen(replace);
char *ptr = subject; char *newptr, *ptr = subject;
unsigned int total = 0; unsigned int total = 0;
while ((ptr = UTIL_ReplaceEx(ptr, maxlength, search, searchLen, replace, replaceLen, caseSensitive)) != NULL) while ((newptr = UTIL_ReplaceEx(ptr, maxlength, search, searchLen, replace, replaceLen, caseSensitive)) != NULL)
{ {
total++; total++;
maxlength -= newptr - ptr;
ptr = newptr;
if (*ptr == '\0') if (*ptr == '\0')
{ {
break; break;