From a2bc29c4b140dc59b42bf948c280edb6e204b0bd Mon Sep 17 00:00:00 2001 From: qhuang8 Date: Mon, 19 Jan 2009 05:18:23 +0000 Subject: [PATCH] Fix a bug that length might be a negative value for worker function BasePrintLibFillBuffer(). In view of this, it is better to reuse for loop to fill the buffer. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@7300 6f19259b-4bc3-4df7-8a09-765794883524 --- MdePkg/Library/BasePrintLib/BasePrintLib.inf | 1 - .../Library/BasePrintLib/PrintLibInternal.c | 21 ++++++++++--------- .../Library/BasePrintLib/PrintLibInternal.h | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/MdePkg/Library/BasePrintLib/BasePrintLib.inf b/MdePkg/Library/BasePrintLib/BasePrintLib.inf index 21d6c20a45..7ff42b1f66 100644 --- a/MdePkg/Library/BasePrintLib/BasePrintLib.inf +++ b/MdePkg/Library/BasePrintLib/BasePrintLib.inf @@ -40,4 +40,3 @@ [LibraryClasses] DebugLib BaseLib - BaseMemoryLib diff --git a/MdePkg/Library/BasePrintLib/PrintLibInternal.c b/MdePkg/Library/BasePrintLib/PrintLibInternal.c index 3e1d5484a7..1c42baecfc 100644 --- a/MdePkg/Library/BasePrintLib/PrintLibInternal.c +++ b/MdePkg/Library/BasePrintLib/PrintLibInternal.c @@ -61,6 +61,7 @@ GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 *mStatusString[] = { @param EndBuffer The end of the input Buffer. No characters will be placed after that. @param Length Count of character to be placed into Buffer. + (Negative value indicates no buffer fill.) @param Character Character to be placed into Buffer. @param Increment Character increment in Buffer. @@ -76,17 +77,17 @@ BasePrintLibFillBuffer ( IN INTN Increment ) { - UINTN FillBufferSize; - - if(Increment == 1) { - FillBufferSize = MIN (Length, (EndBuffer - Buffer)); - Buffer = SetMem (Buffer, FillBufferSize, (UINT8) Character); - } else { - FillBufferSize = MIN (Length << 1, (EndBuffer - Buffer)); - Buffer = SetMem16 (Buffer, FillBufferSize, (UINT16) Character); - } + INTN Index; - return Buffer + FillBufferSize; + for (Index = 0; Index < Length && Buffer < EndBuffer; Index++) { + *Buffer = (CHAR8) Character; + if (Increment != 1) { + *(Buffer + 1) = (CHAR8)(Character >> 8); + } + Buffer += Increment; + } + + return Buffer; } /** diff --git a/MdePkg/Library/BasePrintLib/PrintLibInternal.h b/MdePkg/Library/BasePrintLib/PrintLibInternal.h index 151ea61898..f18ef3961e 100644 --- a/MdePkg/Library/BasePrintLib/PrintLibInternal.h +++ b/MdePkg/Library/BasePrintLib/PrintLibInternal.h @@ -19,7 +19,6 @@ #include #include #include -#include // @@ -118,6 +117,7 @@ BasePrintLibSPrint ( @param EndBuffer The end of the input Buffer. No characters will be placed after that. @param Length Count of character to be placed into Buffer. + (Negative value indicates no buffer fill.) @param Character Character to be placed into Buffer. @param Increment Character increment in Buffer.