]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Allocate temp buffer instead of change the input string to avoid crush.
authorydong10 <ydong10@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 8 Jan 2013 08:30:51 +0000 (08:30 +0000)
committerydong10 <ydong10@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 8 Jan 2013 08:30:51 +0000 (08:30 +0000)
Signed-off-by: Eric Dong <eric.dong@intel.com>
Reviewed-by: Fu Siyuan <siyuan.fu@intel.com>
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@14040 6f19259b-4bc3-4df7-8a09-765794883524

MdePkg/Library/UefiLib/Console.c

index dd4d5c544bf85aa83189d0d43c3b4b5d8c1f20d9..73f991532795bd899ff3bf635d3e1c022dcbf91f 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   This module provide help function for displaying unicode string.\r
 \r
-  Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials                          \r
   are licensed and made available under the terms and conditions of the BSD License         \r
   which accompanies this distribution.  The full text of the license may be found at        \r
@@ -332,8 +332,9 @@ UefiLibGetStringWidth (
     //\r
     // Advance to the null-terminator or to the first width directive\r
     //\r
-    for (;(String[Index] != NARROW_CHAR) && (String[Index] != WIDE_CHAR) && (String[Index] != 0);\r
-         Index++, Count = Count + IncrementValue) {\r
+    for (;(String[Index] != NARROW_CHAR) && (String[Index] != WIDE_CHAR) && (String[Index] != 0); Index++) {\r
+      Count = Count + IncrementValue;\r
+\r
       if (LimitLen && Count > MaxWidth) {\r
         break;\r
       }\r
@@ -347,7 +348,7 @@ UefiLibGetStringWidth (
     }\r
 \r
     if (LimitLen && Count > MaxWidth) {\r
-      *Offset = Index - 1;\r
+      *Offset = Index;\r
       break;\r
     }\r
 \r
@@ -370,13 +371,6 @@ UefiLibGetStringWidth (
     }\r
   } while (String[Index] != 0);\r
 \r
-  //\r
-  // Increment by one to include the null-terminator in the size\r
-  //\r
-  if (!LimitLen) {\r
-    Count++;\r
-  }\r
-\r
   return Count * sizeof (CHAR16);\r
 }\r
 \r
@@ -420,6 +414,7 @@ CreatePopUp (
   UINTN                            Length;\r
   CHAR16                           *Line;\r
   UINTN                            EventIndex;\r
+  CHAR16                           *TmpString;\r
 \r
   //\r
   // Determine the length of the longest line in the popup and the the total \r
@@ -520,10 +515,14 @@ CreatePopUp (
       // Length > MaxLength\r
       //\r
       UefiLibGetStringWidth (String, TRUE, MaxLength, &Length);\r
-      String[Length] = L'\0';\r
+      TmpString = AllocateZeroPool ((Length + 1) * sizeof (CHAR16));\r
+      ASSERT (TmpString != NULL);\r
+      StrnCpy(TmpString, String, Length - 3);\r
+      StrCat (TmpString, L"...");\r
 \r
       ConOut->SetCursorPosition (ConOut, Column + 1, Row++);\r
-      ConOut->OutputString (ConOut, String);\r
+      ConOut->OutputString (ConOut, TmpString);\r
+      FreePool (TmpString);\r
     }\r
     NumberOfLines--;\r
   }\r