MdePkg BaseLib: Fix a corner case of Source and Destination overlap.

The overlap may happen when the address of Destination in
UnicodeStrToAsciiStr() or Source in AsciiStrToUnicodeStr()
is not two bytes aligned.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Star Zeng <star.zeng@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>

git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15665 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
Star Zeng 2014-07-21 03:05:20 +00:00 committed by lzeng14
parent dfa51bb619
commit d52b9d864e
1 changed files with 4 additions and 4 deletions

View File

@ -1,7 +1,7 @@
/** @file
Unicode and ASCII string primatives.
Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2006 - 2014, 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
@ -1040,7 +1040,7 @@ UnicodeStrToAsciiStr (
//
// Source and Destination should not overlap
//
ASSERT ((UINTN) ((CHAR16 *) Destination - Source) > StrLen (Source));
ASSERT ((UINTN) (Destination - (CHAR8 *) Source) >= StrSize (Source));
ASSERT ((UINTN) ((CHAR8 *) Source - Destination) > StrLen (Source));
@ -2008,9 +2008,9 @@ AsciiStrToUnicodeStr (
// Source and Destination should not overlap
//
ASSERT ((UINTN) ((CHAR8 *) Destination - Source) > AsciiStrLen (Source));
ASSERT ((UINTN) (Source - (CHAR8 *) Destination) > (AsciiStrLen (Source) * sizeof (CHAR16)));
ASSERT ((UINTN) (Source - (CHAR8 *) Destination) >= (AsciiStrSize (Source) * sizeof (CHAR16)));
ReturnValue = Destination;
while (*Source != '\0') {
*(Destination++) = (CHAR16) *(Source++);