Revision: 14040
          http://edk2.svn.sourceforge.net/edk2/?rev=14040&view=rev
Author:   ydong10
Date:     2013-01-08 08:30:51 +0000 (Tue, 08 Jan 2013)
Log Message:
-----------
Allocate temp buffer instead of change the input string to avoid crush.

Signed-off-by: Eric Dong <[email protected]>
Reviewed-by: Fu Siyuan <[email protected]>

Modified Paths:
--------------
    trunk/edk2/MdePkg/Library/UefiLib/Console.c

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

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Master SQL Server Development, Administration, T-SQL, SSAS, SSIS, SSRS
and more. Get SQL Server skills now (including 2012) with LearnDevNow -
200+ hours of step-by-step video tutorials by Microsoft MVPs and experts.
SALE $99.99 this month only - learn more at:
http://p.sf.net/sfu/learnmore_122512
_______________________________________________
edk2-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-commits

Reply via email to