From 2099a88ddfeefea6f4db5a5f15599df521820064 Mon Sep 17 00:00:00 2001 From: Arkshine Date: Mon, 6 Jun 2016 12:09:42 +0200 Subject: [PATCH] Fix UTIL_ReplaceAll not properly tracking length. --- amxmodx/util.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/amxmodx/util.cpp b/amxmodx/util.cpp index 7ca7bc81..e1c76025 100755 --- a/amxmodx/util.cpp +++ b/amxmodx/util.cpp @@ -459,11 +459,14 @@ 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;