From 1790033458674c40061da235c6d865d9f3985c9a Mon Sep 17 00:00:00 2001 From: Fyren Date: Mon, 6 Jun 2016 06:25:40 +0000 Subject: [PATCH] Fix UTIL_ReplaceAll not properly tracking length. --- core/logic/stringutil.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core/logic/stringutil.cpp b/core/logic/stringutil.cpp index 7d5050e2..3c966cb5 100644 --- a/core/logic/stringutil.cpp +++ b/core/logic/stringutil.cpp @@ -83,11 +83,13 @@ unsigned int UTIL_ReplaceAll(char *subject, size_t maxlength, const char *search size_t searchLen = strlen(search); size_t replaceLen = strlen(replace); - char *ptr = subject; + char *newptr, *ptr = subject; 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++; + maxlength -= newptr - ptr; + ptr = newptr; if (*ptr == '\0') { break;