From 8960cdebac8c75f13f1cb6afa932f0ae323a138b Mon Sep 17 00:00:00 2001 From: qhuang8 Date: Tue, 13 Jun 2006 06:31:11 +0000 Subject: =?UTF-8?q?=09BaseMemoryLib=20(BaseMemoryLibRepStr):=20=09Fix=20a?= =?UTF-8?q?=20logic=20error=20in=20SetMem64=20();=20The=20correct=20stride?= =?UTF-8?q?=20should=20be=208=20instead=20of=204.=20=09BasePrintLib:=20=09?= =?UTF-8?q?Fix=20Printf(=E2=80=9C%\n=E2=80=9D)=20passer=20error.=20=09Fix?= =?UTF-8?q?=20BufferSize=20=3D=200,=201=20issue=20=09Fix=20some=20missing?= =?UTF-8?q?=20ASSERT=20()s=20=09Move=20MAXIMUM=5FVALUE=5FCHARACTERS=20from?= =?UTF-8?q?=20PrintLibInternal.h=20to=20PrintLib.h=20=09ReportStatusCodeLi?= =?UTF-8?q?b:=20=09Add=20CONST=20modifier=20to=20some=20interfaces=20=09Mo?= =?UTF-8?q?dify=20=09DebugLib:=20=09Replace=20some=20Unicode=20in=20commen?= =?UTF-8?q?ts.=20=09PeiServicesTablePointerLib=20=09Add=20ASSERT()s=20=09P?= =?UTF-8?q?ciLib:=20=09Remove=20unnecessary=20ASSERT()s=20in=20PciRead/Wri?= =?UTF-8?q?teBuffer()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@496 6f19259b-4bc3-4df7-8a09-765794883524 --- MdePkg/Library/BasePrintLib/PrintLib.c | 20 +++++++++++--------- MdePkg/Library/BasePrintLib/PrintLibInternal.c | 9 ++++++++- MdePkg/Library/BasePrintLib/PrintLibInternal.h | 10 ---------- 3 files changed, 19 insertions(+), 20 deletions(-) (limited to 'MdePkg/Library/BasePrintLib') diff --git a/MdePkg/Library/BasePrintLib/PrintLib.c b/MdePkg/Library/BasePrintLib/PrintLib.c index 24e0175545..e940bedb34 100644 --- a/MdePkg/Library/BasePrintLib/PrintLib.c +++ b/MdePkg/Library/BasePrintLib/PrintLib.c @@ -66,7 +66,6 @@ static CONST STATUS_LOOKUP_TABLE_ENTRY StatusString[] = { @param Buffer Character buffer to print the results of the parsing of Format into. @param BufferSize Maximum number of characters to put into buffer. - Zero means no limit. @param Flags Intial flags value. Can only have FORMAT_UNICODE and OUTPUT_UNICODE set @param Format Null-terminated format string. @@ -110,6 +109,9 @@ BasePrintLibVSPrint ( UINTN Radix; RETURN_STATUS Status; + if (BufferSize == 0) { + return 0; + } ASSERT (Buffer != NULL); ASSERT (Format != NULL); @@ -130,7 +132,6 @@ BasePrintLibVSPrint ( // // Reserve space for the Null terminator. - // If BufferSize is 0, this will set BufferSize to the max unsigned value // BufferSize--; @@ -338,7 +339,7 @@ BasePrintLibVSPrint ( } else { BasePrintLibSPrint ( ValueBuffer, - 0, + MAXIMUM_VALUE_CHARACTERS, 0, "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x", TmpGuid->Data1, @@ -364,7 +365,7 @@ BasePrintLibVSPrint ( } else { BasePrintLibSPrint ( ValueBuffer, - 0, + MAXIMUM_VALUE_CHARACTERS, 0, "%02d/%02d/%04d %02d:%02d", TmpTime->Month, @@ -386,10 +387,14 @@ BasePrintLibVSPrint ( } } if (ArgumentString == ValueBuffer) { - BasePrintLibSPrint ((CHAR8 *) ValueBuffer, 0, 0, "%08X", Status); + BasePrintLibSPrint ((CHAR8 *) ValueBuffer, MAXIMUM_VALUE_CHARACTERS, 0, "%08X", Status); } break; + case '\n': + ArgumentString = "\r\n"; + break; + case '%': default: // @@ -400,9 +405,6 @@ BasePrintLibVSPrint ( break; } break; - case '\n': - ArgumentString = "\r\n"; - break; default: ArgumentString = (CHAR8 *)&FormatCharacter; Flags |= ARGUMENT_UNICODE; @@ -717,7 +719,7 @@ UnicodeSPrintAsciiFormat ( VA_LIST Marker; VA_START (Marker, FormatString); - return UnicodeVSPrintAsciiFormat (StartOfBuffer, BufferSize >> 1, FormatString, Marker); + return UnicodeVSPrintAsciiFormat (StartOfBuffer, BufferSize, FormatString, Marker); } /** diff --git a/MdePkg/Library/BasePrintLib/PrintLibInternal.c b/MdePkg/Library/BasePrintLib/PrintLibInternal.c index 89d18b09a2..06c220692e 100644 --- a/MdePkg/Library/BasePrintLib/PrintLibInternal.c +++ b/MdePkg/Library/BasePrintLib/PrintLibInternal.c @@ -138,13 +138,20 @@ BasePrintLibConvertValueToString ( UINTN Digits; UINTN Index; + ASSERT (Buffer != NULL); + ASSERT (Width < MAXIMUM_VALUE_CHARACTERS); + // + // Make sure Flags can only contain supported bits. + // + ASSERT ((Flags & ~(LEFT_JUSTIFY | COMMA_TYPE | PREFIX_ZERO)) == 0); + OriginalBuffer = Buffer; if (Width == 0 || (Flags & COMMA_TYPE) != 0) { Flags &= (~PREFIX_ZERO); } - if (Width == 0 || Width > (MAXIMUM_VALUE_CHARACTERS - 1)) { + if (Width == 0) { Width = MAXIMUM_VALUE_CHARACTERS - 1; } diff --git a/MdePkg/Library/BasePrintLib/PrintLibInternal.h b/MdePkg/Library/BasePrintLib/PrintLibInternal.h index 0f7bebff45..f395bb7956 100644 --- a/MdePkg/Library/BasePrintLib/PrintLibInternal.h +++ b/MdePkg/Library/BasePrintLib/PrintLibInternal.h @@ -31,16 +31,6 @@ #define PRECISION 0x800 #define ARGUMENT_REVERSED 0x1000 -/// -/// Define the maximum number of characters that are required to encode -/// a decimal, hexidecimal, GUID, or TIME value with a Nll terminator. -/// Maximum Length Decimal String = 28 "-9,223,372,036,854,775,808" -/// Maximum Length Hexidecimal String = 17 "FFFFFFFFFFFFFFFF" -/// Maximum Length GUID = 37 "00000000-0000-0000-0000-000000000000" -/// Maximum Length TIME = 18 "12/12/2006 12:12" -/// -#define MAXIMUM_VALUE_CHARACTERS 38 - // // Record date and time information // -- cgit v1.2.3