From 8b5b3d421f9e4a7ef72942c67fac05e367c03501 Mon Sep 17 00:00:00 2001 From: ydong10 Date: Tue, 8 Jan 2013 08:30:51 +0000 Subject: Allocate temp buffer instead of change the input string to avoid crush. Signed-off-by: Eric Dong Reviewed-by: Fu Siyuan git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@14040 6f19259b-4bc3-4df7-8a09-765794883524 --- MdePkg/Library/UefiLib/Console.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) (limited to 'MdePkg') diff --git a/MdePkg/Library/UefiLib/Console.c b/MdePkg/Library/UefiLib/Console.c index dd4d5c544b..73f9915327 100644 --- a/MdePkg/Library/UefiLib/Console.c +++ b/MdePkg/Library/UefiLib/Console.c @@ -1,7 +1,7 @@ /** @file This module provide help function for displaying unicode string. - Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.
+ Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.
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 @@ UefiLibGetStringWidth ( // // 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 @@ UefiLibGetStringWidth ( } if (LimitLen && Count > MaxWidth) { - *Offset = Index - 1; + *Offset = Index; break; } @@ -370,13 +371,6 @@ UefiLibGetStringWidth ( } } 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 @@ CreatePopUp ( 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 @@ CreatePopUp ( // 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--; } -- cgit v1.2.3