Fix game freezing if Format arg contains '%1', '%2', etc. (bug 851)
authorWuzzy <Wuzzy@disroot.org>
Mon, 19 Jun 2023 14:09:37 +0200
changeset 15990 79b1129b4d03
parent 15989 723be7e392e5
child 15991 4ad8dd66d9d5
Fix game freezing if Format arg contains '%1', '%2', etc. (bug #851)
hedgewars/uLocale.pas
--- a/hedgewars/uLocale.pas	Fri Jun 16 21:06:46 2023 +0200
+++ b/hedgewars/uLocale.pas	Mon Jun 19 14:09:37 2023 +0200
@@ -164,6 +164,10 @@
             8: curArg:= arg9;
         end;
 
+        // Replace % sign in argument with ASCII ESC
+        // to prevent infinite loop below.
+        curArg:= StringReplace(curArg, '%', Char($1B), [rfReplaceAll]);
+
         repeat
         p:= Pos('%'+IntToStr(i+1), tempstr);
         if (p <> 0) then
@@ -173,6 +177,8 @@
             end;
         until (p = 0);
     end;
+
+tempstr:= StringReplace(tempstr, Char($1B), '%', [rfReplaceAll]);
 Format:= tempstr;
 end;
 
@@ -196,6 +202,10 @@
             8: curArg:= arg9;
         end;
 
+        // Replace % sign in argument with ASCII ESC
+        // to prevent infinite loop below.
+        curArg:= StringReplace(curArg, '%', Char($1B), [rfReplaceAll]);
+
         repeat
         p:= Pos('%'+IntToStr(i+1), tempstr);
         if (p <> 0) then
@@ -205,6 +215,8 @@
             end;
         until (p = 0);
     end;
+
+tempstr:= StringReplace(tempstr, Char($1B), '%', [rfReplaceAll]);
 FormatA:= tempstr;
 end;