]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Library/UefiShellLib/UefiShellLib.c
Fix always allocate memory issue.
[mirror_edk2.git] / ShellPkg / Library / UefiShellLib / UefiShellLib.c
index 1929349b2038aa2a7f4f197eb532ef442d7459b7..222bd98acd078b9cf4a980aedfea2f3ea34aa659 100644 (file)
@@ -3142,11 +3142,13 @@ StrnCatGrow (
   //\r
   if (CurrentSize != NULL) {\r
     NewSize = *CurrentSize;\r
-    while (NewSize < (DestinationStartSize + (Count*sizeof(CHAR16)))) {\r
-      NewSize += 2 * Count * sizeof(CHAR16);\r
+    if (NewSize < DestinationStartSize + (Count * sizeof(CHAR16))) {\r
+      while (NewSize < (DestinationStartSize + (Count*sizeof(CHAR16)))) {\r
+        NewSize += 2 * Count * sizeof(CHAR16);\r
+      }\r
+      *Destination = ReallocatePool(*CurrentSize, NewSize, *Destination);\r
+      *CurrentSize = NewSize;\r
     }\r
-    *Destination = ReallocatePool(*CurrentSize, NewSize, *Destination);\r
-    *CurrentSize = NewSize;\r
   } else {\r
     *Destination = AllocateZeroPool((Count+1)*sizeof(CHAR16));\r
   }\r