summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorydong10 <ydong10@6f19259b-4bc3-4df7-8a09-765794883524>2013-01-08 08:30:51 +0000
committerydong10 <ydong10@6f19259b-4bc3-4df7-8a09-765794883524>2013-01-08 08:30:51 +0000
commit8b5b3d421f9e4a7ef72942c67fac05e367c03501 (patch)
tree91c9d9f5fc0530019f228b66f1f180c2cfead824
parent685e44a546ac3744d04cdce12d27d07f96831e7c (diff)
downloadedk2-platforms-8b5b3d421f9e4a7ef72942c67fac05e367c03501.tar.xz
Allocate temp buffer instead of change the input string to avoid crush.
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
-rw-r--r--MdePkg/Library/UefiLib/Console.c25
1 files changed, 12 insertions, 13 deletions
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.<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 @@ 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--;
}