From nobody Thu May 2 10:59:27 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zoho.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1486611178536493.80948024212023; Wed, 8 Feb 2017 19:32:58 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 436C28210A; Wed, 8 Feb 2017 19:32:57 -0800 (PST) Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 61A4E82107 for ; Wed, 8 Feb 2017 19:32:55 -0800 (PST) Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga104.jf.intel.com with ESMTP; 08 Feb 2017 19:32:55 -0800 Received: from shwdeopenpsi014.ccr.corp.intel.com ([10.239.9.13]) by orsmga004.jf.intel.com with ESMTP; 08 Feb 2017 19:32:53 -0800 X-Original-To: edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.35,349,1484035200"; d="scan'208";a="56777738" From: Hao Wu To: edk2-devel@lists.01.org Date: Thu, 9 Feb 2017 11:32:39 +0800 Message-Id: <1486611161-37308-2-git-send-email-hao.a.wu@intel.com> X-Mailer: git-send-email 1.9.5.msysgit.0 In-Reply-To: <1486611161-37308-1-git-send-email-hao.a.wu@intel.com> References: <1486611161-37308-1-git-send-email-hao.a.wu@intel.com> Subject: [edk2] [PATCH v2 1/3] MdePkg/BasePrintLib: Refine the SPrint functions X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Hao Wu , Michael Kinney , Jiewen Yao , Liming Gao MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" For the following 12 APIs in MdePkg/BasePrintLib: UnicodeVSPrint UnicodeBSPrint UnicodeSPrint UnicodeVSPrintAsciiFormat UnicodeBSPrintAsciiFormat UnicodeSPrintAsciiFormat AsciiVSPrint AsciiBSPrint AsciiSPrint AsciiVSPrintUnicodeFormat AsciiBSPrintUnicodeFormat AsciiSPrintUnicodeFormat They will ASSERT when: 1) The input parameter 'StartOfBuffer' is NULL if 'BufferSize' indicates at least 1 Ascii/Unicode character can be held. 2) The input parameter 'FormatString' is NULL if 'BufferSize' indicates at least 1 Ascii/Unicode character can be held. 3) The input parameter 'FormatString' contains more than PcdMaximum[Ascii|Unicode]StringLength Ascii/Unicode characters. 4) The produced string contains more than PcdMaximum[Ascii|Unicode]StringLength Ascii/Unicode characters. This commits removes the ASSERT case 4) and add the following new ASSERT case: 4) The input parameter 'BufferSize' is greater than (PcdMaximumAsciiStringLength * sizeof (CHAR8)) for Ascii format string or (PcdMaximumUnicodeStringLength * sizeof (CHAR16) + 1) for Unicode format string. And for those ASSERT cases, 0 will be returned by those 12 APIs. For the following 2 APIs in MdePkg/BasePrintLib: SPrintLength SPrintLengthAsciiFormat They will ASSERT when: 1) The input parameter 'FormatString' is NULL. 2) The input parameter 'FormatString' contains more than PcdMaximum[Ascii|Unicode]StringLength Ascii/Unicode characters. And for those ASSERT cases, 0 will be returned by those 2 APIs. Cc: Jiewen Yao Cc: Liming Gao Cc: Michael Kinney Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Hao Wu Reviewed-by: Liming Gao --- MdePkg/Include/Library/PrintLib.h | 498 +++++++++++--------- MdePkg/Library/BasePrintLib/BasePrintLib.inf | 8 +- MdePkg/Library/BasePrintLib/PrintLib.c | 416 +++++++++------- MdePkg/Library/BasePrintLib/PrintLibInternal.c | 101 ++-- MdePkg/Library/BasePrintLib/PrintLibInternal.h | 3 +- 5 files changed, 598 insertions(+), 428 deletions(-) diff --git a/MdePkg/Include/Library/PrintLib.h b/MdePkg/Include/Library/Pri= ntLib.h index fcaacde..5f66323 100644 --- a/MdePkg/Include/Library/PrintLib.h +++ b/MdePkg/Include/Library/PrintLib.h @@ -2,7 +2,7 @@ Provides services to print a formatted string to a buffer. All combinati= ons of Unicode and ASCII strings are supported. =20 -Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.
+Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made availabl= e under=20 the terms and conditions of the BSD License that accompanies this distribu= tion. =20 The full text of the license may be found at @@ -204,36 +204,42 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EI= THER EXPRESS OR IMPLIED. #define RADIX_HEX 0x80 =20 /** - Produces a Null-terminated Unicode string in an output buffer based on=20 + Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated Unicode format string and a VA_LIST argument list. - =20 + + This function is similar as vsnprintf_s defined in C11. + Produces a Null-terminated Unicode string in the output buffer specified= by StartOfBuffer - and BufferSize. =20 - The Unicode string is produced by parsing the format string specified by= FormatString. =20 - Arguments are pulled from the variable argument list specified by Marker= based on the=20 - contents of the format string. =20 - The number of Unicode characters in the produced output buffer is return= ed, not including + and BufferSize. + The Unicode string is produced by parsing the format string specified by= FormatString. + Arguments are pulled from the variable argument list specified by Marker= based on the + contents of the format string. + The number of Unicode characters in the produced output buffer is return= ed not including the Null-terminator. - If BufferSize is 0 or 1, then no output buffer is produced and 0 is retu= rned. =20 - If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT(). - If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary,= then ASSERT(). - If BufferSize > 1 and FormatString is NULL, then ASSERT(). - If BufferSize > 1 and FormatString is not aligned on a 16-bit boundary, = then ASSERT(). - If PcdMaximumUnicodeStringLength is not zero, and FormatString contains = more than=20 - PcdMaximumUnicodeStringLength Unicode characters, not including the Null= -terminator, then - ASSERT(). - If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminat= ed Unicode string - contains more than PcdMaximumUnicodeStringLength Unicode characters, not= including the - Null-terminator, then ASSERT(). - - @param StartOfBuffer A pointer to the output buffer for the produced = Null-terminated=20 + If StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT(). + If FormatString is not aligned on a 16-bit boundary, then ASSERT(). + + If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT(). Also, the ou= tput buffer is + unmodified and 0 is returned. + If BufferSize > 1 and FormatString is NULL, then ASSERT(). Also, the out= put buffer is + unmodified and 0 is returned. + If PcdMaximumUnicodeStringLength is not zero, and BufferSize > + (PcdMaximumUnicodeStringLength * sizeof (CHAR16) + 1), then ASSERT(). Al= so, the output + buffer is unmodified and 0 is returned. + If PcdMaximumUnicodeStringLength is not zero, and FormatString contains = more than + PcdMaximumUnicodeStringLength Unicode characters not including the Null-= terminator, then + ASSERT(). Also, the output buffer is unmodified and 0 is returned. + + If BufferSize is 0 or 1, then the output buffer is unmodified and 0 is r= eturned. + + @param StartOfBuffer A pointer to the output buffer for the produced = Null-terminated Unicode string. @param BufferSize The size, in bytes, of the output buffer specifi= ed by StartOfBuffer. - @param FormatString Null-terminated Unicode format string. + @param FormatString A Null-terminated Unicode format string. @param Marker VA_LIST marker for the variable argument list. - =20 - @return The number of Unicode characters in the produced output buffer, = not including the + + @return The number of Unicode characters in the produced output buffer n= ot including the Null-terminator. =20 **/ @@ -247,36 +253,40 @@ UnicodeVSPrint ( ); =20 /** - Produces a Null-terminated Unicode string in an output buffer based on=20 + Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated Unicode format string and a BASE_LIST argument list. - =20 + Produces a Null-terminated Unicode string in the output buffer specified= by StartOfBuffer - and BufferSize. =20 - The Unicode string is produced by parsing the format string specified by= FormatString. =20 - Arguments are pulled from the variable argument list specified by Marker= based on the=20 - contents of the format string. =20 - The number of Unicode characters in the produced output buffer is return= ed, not including + and BufferSize. + The Unicode string is produced by parsing the format string specified by= FormatString. + Arguments are pulled from the variable argument list specified by Marker= based on the + contents of the format string. + The number of Unicode characters in the produced output buffer is return= ed not including the Null-terminator. - If BufferSize is 0 or 1, then no output buffer is produced and 0 is retu= rned. =20 - If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT(). - If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary,= then ASSERT(). - If BufferSize > 1 and FormatString is NULL, then ASSERT(). - If BufferSize > 1 and FormatString is not aligned on a 16-bit boundary, = then ASSERT(). - If PcdMaximumUnicodeStringLength is not zero, and FormatString contains = more than=20 - PcdMaximumUnicodeStringLength Unicode characters, not including the Null= -terminator, then - ASSERT(). - If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminat= ed Unicode string - contains more than PcdMaximumUnicodeStringLength Unicode characters, not= including the - Null-terminator, then ASSERT(). - - @param StartOfBuffer A pointer to the output buffer for the produced = Null-terminated=20 + If StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT(). + If FormatString is not aligned on a 16-bit boundary, then ASSERT(). + + If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT(). Also, the ou= tput buffer is + unmodified and 0 is returned. + If BufferSize > 1 and FormatString is NULL, then ASSERT(). Also, the out= put buffer is + unmodified and 0 is returned. + If PcdMaximumUnicodeStringLength is not zero, and BufferSize > + (PcdMaximumUnicodeStringLength * sizeof (CHAR16) + 1), then ASSERT(). Al= so, the output + buffer is unmodified and 0 is returned. + If PcdMaximumUnicodeStringLength is not zero, and FormatString contains = more than + PcdMaximumUnicodeStringLength Unicode characters not including the Null-= terminator, then + ASSERT(). Also, the output buffer is unmodified and 0 is returned. + + If BufferSize is 0 or 1, then the output buffer is unmodified and 0 is r= eturned. + + @param StartOfBuffer A pointer to the output buffer for the produced = Null-terminated Unicode string. @param BufferSize The size, in bytes, of the output buffer specifi= ed by StartOfBuffer. - @param FormatString Null-terminated Unicode format string. + @param FormatString A Null-terminated Unicode format string. @param Marker BASE_LIST marker for the variable argument list. - =20 - @return The number of Unicode characters in the produced output buffer, = not including the + + @return The number of Unicode characters in the produced output buffer n= ot including the Null-terminator. =20 **/ @@ -290,36 +300,42 @@ UnicodeBSPrint ( ); =20 /** - Produces a Null-terminated Unicode string in an output buffer based on a= Null-terminated=20 + Produces a Null-terminated Unicode string in an output buffer based on a= Null-terminated Unicode format string and variable argument list. - =20 + + This function is similar as snprintf_s defined in C11. + Produces a Null-terminated Unicode string in the output buffer specified= by StartOfBuffer and BufferSize. The Unicode string is produced by parsing the format string specified by= FormatString. Arguments are pulled from the variable argument list based on the conten= ts of the format string. - The number of Unicode characters in the produced output buffer is return= ed, not including + The number of Unicode characters in the produced output buffer is return= ed not including the Null-terminator. - If BufferSize is 0 or 1, then no output buffer is produced and 0 is retu= rned. =20 - If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT(). - If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary,= then ASSERT(). - If BufferSize > 1 and FormatString is NULL, then ASSERT(). - If BufferSize > 1 and FormatString is not aligned on a 16-bit boundary, = then ASSERT(). - If PcdMaximumUnicodeStringLength is not zero, and FormatString contains = more than=20 + If StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT(). + If FormatString is not aligned on a 16-bit boundary, then ASSERT(). + + If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT(). Also, the ou= tput buffer is + unmodified and 0 is returned. + If BufferSize > 1 and FormatString is NULL, then ASSERT(). Also, the out= put buffer is + unmodified and 0 is returned. + If PcdMaximumUnicodeStringLength is not zero, and BufferSize > + (PcdMaximumUnicodeStringLength * sizeof (CHAR16) + 1), then ASSERT(). Al= so, the output + buffer is unmodified and 0 is returned. + If PcdMaximumUnicodeStringLength is not zero, and FormatString contains = more than PcdMaximumUnicodeStringLength Unicode characters not including the Null-= terminator, then - ASSERT(). - If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminat= ed Unicode string - contains more than PcdMaximumUnicodeStringLength Unicode characters not = including the - Null-terminator, then ASSERT(). + ASSERT(). Also, the output buffer is unmodified and 0 is returned. + + If BufferSize is 0 or 1, then the output buffer is unmodified and 0 is r= eturned. =20 - @param StartOfBuffer A pointer to the output buffer for the produced = Null-terminated=20 + @param StartOfBuffer A pointer to the output buffer for the produced = Null-terminated Unicode string. @param BufferSize The size, in bytes, of the output buffer specifi= ed by StartOfBuffer. - @param FormatString A null-terminated Unicode format string. - @param ... The variable argument list whose contents are ac= cessed based on the=20 + @param FormatString A Null-terminated Unicode format string. + @param ... Variable argument list whose contents are access= ed based on the format string specified by FormatString. - =20 - @return The number of Unicode characters in the produced output buffer, = not including the + + @return The number of Unicode characters in the produced output buffer n= ot including the Null-terminator. =20 **/ @@ -334,33 +350,39 @@ UnicodeSPrint ( =20 /** Produces a Null-terminated Unicode string in an output buffer based on a= Null-terminated - ASCII format string and a VA_LIST argument list - =20 + ASCII format string and a VA_LIST argument list. + + This function is similar as vsnprintf_s defined in C11. + Produces a Null-terminated Unicode string in the output buffer specified= by StartOfBuffer and BufferSize. The Unicode string is produced by parsing the format string specified by= FormatString. - Arguments are pulled from the variable argument list specified by Marker= based on the=20 + Arguments are pulled from the variable argument list specified by Marker= based on the contents of the format string. - The number of Unicode characters in the produced output buffer is return= ed, not including + The number of Unicode characters in the produced output buffer is return= ed not including the Null-terminator. - If BufferSize is 0 or 1, then no output buffer is produced and 0 is retu= rned. =20 - If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT(). - If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary,= then ASSERT(). - If BufferSize > 1 and FormatString is NULL, then ASSERT(). + If StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT(). + + If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT(). Also, the ou= tput buffer is + unmodified and 0 is returned. + If BufferSize > 1 and FormatString is NULL, then ASSERT(). Also, the out= put buffer is + unmodified and 0 is returned. + If PcdMaximumUnicodeStringLength is not zero, and BufferSize > + (PcdMaximumUnicodeStringLength * sizeof (CHAR16) + 1), then ASSERT(). Al= so, the output + buffer is unmodified and 0 is returned. If PcdMaximumAsciiStringLength is not zero, and FormatString contains mo= re than - PcdMaximumAsciiStringLength ASCII characters, not including the Null-ter= minator, then - ASSERT(). - If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminat= ed Unicode string - contains more than PcdMaximumUnicodeStringLength Unicode characters, not= including the - Null-terminator, then ASSERT(). + PcdMaximumAsciiStringLength Ascii characters not including the Null-term= inator, then + ASSERT(). Also, the output buffer is unmodified and 0 is returned. =20 - @param StartOfBuffer A pointer to the output buffer for the produced = Null-terminated=20 + If BufferSize is 0 or 1, then no output buffer is produced and 0 is retu= rned. + + @param StartOfBuffer A pointer to the output buffer for the produced = Null-terminated Unicode string. @param BufferSize The size, in bytes, of the output buffer specifi= ed by StartOfBuffer. - @param FormatString A null-terminated ASCII format string. + @param FormatString A Null-terminated ASCII format string. @param Marker VA_LIST marker for the variable argument list. - =20 + @return The number of Unicode characters in the produced output buffer n= ot including the Null-terminator. =20 @@ -376,34 +398,38 @@ UnicodeVSPrintAsciiFormat ( =20 /** Produces a Null-terminated Unicode string in an output buffer based on a= Null-terminated - ASCII format string and a BASE_LIST argument list - =20 + ASCII format string and a BASE_LIST argument list. + Produces a Null-terminated Unicode string in the output buffer specified= by StartOfBuffer and BufferSize. The Unicode string is produced by parsing the format string specified by= FormatString. - Arguments are pulled from the variable argument list specified by Marker= based on the=20 + Arguments are pulled from the variable argument list specified by Marker= based on the contents of the format string. - The number of Unicode characters in the produced output buffer is return= ed, not including + The number of Unicode characters in the produced output buffer is return= ed not including the Null-terminator. - If BufferSize is 0 or 1, then no output buffer is produced and 0 is retu= rned. =20 - If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT(). - If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary,= then ASSERT(). - If BufferSize > 1 and FormatString is NULL, then ASSERT(). + If StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT(). + + If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT(). Also, the ou= tput buffer is + unmodified and 0 is returned. + If BufferSize > 1 and FormatString is NULL, then ASSERT(). Also, the out= put buffer is + unmodified and 0 is returned. + If PcdMaximumUnicodeStringLength is not zero, and BufferSize > + (PcdMaximumUnicodeStringLength * sizeof (CHAR16) + 1), then ASSERT(). Al= so, the output + buffer is unmodified and 0 is returned. If PcdMaximumAsciiStringLength is not zero, and FormatString contains mo= re than - PcdMaximumAsciiStringLength ASCII characters, not including the Null-ter= minator, then - ASSERT(). - If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminat= ed Unicode string - contains more than PcdMaximumUnicodeStringLength Unicode characters, not= including the - Null-terminator, then ASSERT(). + PcdMaximumAsciiStringLength Ascii characters not including the Null-term= inator, then + ASSERT(). Also, the output buffer is unmodified and 0 is returned. =20 - @param StartOfBuffer A pointer to the output buffer for the produced = Null-terminated=20 + If BufferSize is 0 or 1, then no output buffer is produced and 0 is retu= rned. + + @param StartOfBuffer A pointer to the output buffer for the produced = Null-terminated Unicode string. @param BufferSize The size, in bytes, of the output buffer specifi= ed by StartOfBuffer. - @param FormatString A null-terminated ASCII format string. - @param Marker A BASE_LIST marker for the variable argument lis= t. - =20 - @return The number of Unicode characters in the produced output buffer, = not including the + @param FormatString A Null-terminated ASCII format string. + @param Marker BASE_LIST marker for the variable argument list. + + @return The number of Unicode characters in the produced output buffer n= ot including the Null-terminator. =20 **/ @@ -417,36 +443,42 @@ UnicodeBSPrintAsciiFormat ( ); =20 /** - Produces a Null-terminated Unicode string in an output buffer based on a= Null-terminated=20 + Produces a Null-terminated Unicode string in an output buffer based on a= Null-terminated ASCII format string and variable argument list. - =20 + + This function is similar as snprintf_s defined in C11. + Produces a Null-terminated Unicode string in the output buffer specified= by StartOfBuffer and BufferSize. The Unicode string is produced by parsing the format string specified by= FormatString. - Arguments are pulled from the variable argument list based on the conten= ts of the=20 + Arguments are pulled from the variable argument list based on the conten= ts of the format string. - The number of Unicode characters in the produced output buffer is return= ed, not including + The number of Unicode characters in the produced output buffer is return= ed not including the Null-terminator. - If BufferSize is 0 or 1, then no output buffer is produced and 0 is retu= rned. =20 - If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT(). - If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary,= then ASSERT(). - If BufferSize > 1 and FormatString is NULL, then ASSERT(). + If StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT(). + + If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT(). Also, the ou= tput buffer is + unmodified and 0 is returned. + If BufferSize > 1 and FormatString is NULL, then ASSERT(). Also, the out= put buffer is + unmodified and 0 is returned. + If PcdMaximumUnicodeStringLength is not zero, and BufferSize > + (PcdMaximumUnicodeStringLength * sizeof (CHAR16) + 1), then ASSERT(). Al= so, the output + buffer is unmodified and 0 is returned. If PcdMaximumAsciiStringLength is not zero, and FormatString contains mo= re than - PcdMaximumAsciiStringLength ASCII characters, not including the Null-ter= minator, then - ASSERT(). - If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminat= ed Unicode string - contains more than PcdMaximumUnicodeStringLength Unicode characters, the - Null-terminator, then ASSERT(). + PcdMaximumAsciiStringLength Ascii characters not including the Null-term= inator, then + ASSERT(). Also, the output buffer is unmodified and 0 is returned. + + If BufferSize is 0 or 1, then no output buffer is produced and 0 is retu= rned. =20 - @param StartOfBuffer A pointer to the output buffer for the produced = Null-terminated=20 + @param StartOfBuffer A pointer to the output buffer for the produced = Null-terminated Unicode string. @param BufferSize The size, in bytes, of the output buffer specifi= ed by StartOfBuffer. - @param FormatString A null-terminated ASCII format string. - @param ... Variable argument list whose contents are access= ed based on the=20 + @param FormatString A Null-terminated ASCII format string. + @param ... Variable argument list whose contents are access= ed based on the format string specified by FormatString. - =20 - @return The number of Unicode characters in the produced output buffer, = not including the + + @return The number of Unicode characters in the produced output buffer n= ot including the Null-terminator. =20 **/ @@ -512,32 +544,37 @@ UnicodeValueToString ( /** Produces a Null-terminated ASCII string in an output buffer based on a N= ull-terminated ASCII format string and a VA_LIST argument list. - =20 + + This function is similar as vsnprintf_s defined in C11. + Produces a Null-terminated ASCII string in the output buffer specified b= y StartOfBuffer and BufferSize. The ASCII string is produced by parsing the format string specified by F= ormatString. - Arguments are pulled from the variable argument list specified by Marker= based on=20 + Arguments are pulled from the variable argument list specified by Marker= based on the contents of the format string. - The number of ASCII characters in the produced output buffer is returned= , not including + The number of ASCII characters in the produced output buffer is returned= not including the Null-terminator. - If BufferSize is 0, then no output buffer is produced and 0 is returned. =20 - If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT(). - If BufferSize > 0 and FormatString is NULL, then ASSERT(). + If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT(). Also, the ou= tput buffer is + unmodified and 0 is returned. + If BufferSize > 0 and FormatString is NULL, then ASSERT(). Also, the out= put buffer is + unmodified and 0 is returned. + If PcdMaximumAsciiStringLength is not zero, and BufferSize > + (PcdMaximumAsciiStringLength * sizeof (CHAR8)), then ASSERT(). Also, the= output buffer + is unmodified and 0 is returned. If PcdMaximumAsciiStringLength is not zero, and FormatString contains mo= re than - PcdMaximumAsciiStringLength ASCII characters, not including the Null-ter= minator, then - ASSERT(). - If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated= ASCII string - contains more than PcdMaximumAsciiStringLength ASCII characters, not inc= luding the - Null-terminator, then ASSERT(). + PcdMaximumAsciiStringLength Ascii characters not including the Null-term= inator, then + ASSERT(). Also, the output buffer is unmodified and 0 is returned. + + If BufferSize is 0, then no output buffer is produced and 0 is returned. =20 - @param StartOfBuffer A pointer to the output buffer for the produced = Null-terminated=20 + @param StartOfBuffer A pointer to the output buffer for the produced = Null-terminated ASCII string. @param BufferSize The size, in bytes, of the output buffer specifi= ed by StartOfBuffer. - @param FormatString A null-terminated ASCII format string. + @param FormatString A Null-terminated ASCII format string. @param Marker VA_LIST marker for the variable argument list. - =20 - @return The number of ASCII characters in the produced output buffer, no= t including the + + @return The number of ASCII characters in the produced output buffer not= including the Null-terminator. =20 **/ @@ -553,32 +590,35 @@ AsciiVSPrint ( /** Produces a Null-terminated ASCII string in an output buffer based on a N= ull-terminated ASCII format string and a BASE_LIST argument list. - =20 + Produces a Null-terminated ASCII string in the output buffer specified b= y StartOfBuffer and BufferSize. The ASCII string is produced by parsing the format string specified by F= ormatString. - Arguments are pulled from the variable argument list specified by Marker= based on=20 + Arguments are pulled from the variable argument list specified by Marker= based on the contents of the format string. - The number of ASCII characters in the produced output buffer is returned= , not including + The number of ASCII characters in the produced output buffer is returned= not including the Null-terminator. - If BufferSize is 0, then no output buffer is produced and 0 is returned. =20 - If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT(). - If BufferSize > 0 and FormatString is NULL, then ASSERT(). + If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT(). Also, the ou= tput buffer is + unmodified and 0 is returned. + If BufferSize > 0 and FormatString is NULL, then ASSERT(). Also, the out= put buffer is + unmodified and 0 is returned. + If PcdMaximumAsciiStringLength is not zero, and BufferSize > + (PcdMaximumAsciiStringLength * sizeof (CHAR8)), then ASSERT(). Also, the= output buffer + is unmodified and 0 is returned. If PcdMaximumAsciiStringLength is not zero, and FormatString contains mo= re than - PcdMaximumAsciiStringLength ASCII characters, not including the Null-ter= minator, then - ASSERT(). - If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated= ASCII string - contains more than PcdMaximumAsciiStringLength ASCII characters, not inc= luding the - Null-terminator, then ASSERT(). + PcdMaximumAsciiStringLength Ascii characters not including the Null-term= inator, then + ASSERT(). Also, the output buffer is unmodified and 0 is returned. + + If BufferSize is 0, then no output buffer is produced and 0 is returned. =20 - @param StartOfBuffer A pointer to the output buffer for the produced = Null-terminated=20 + @param StartOfBuffer A pointer to the output buffer for the produced = Null-terminated ASCII string. @param BufferSize The size, in bytes, of the output buffer specifi= ed by StartOfBuffer. - @param FormatString A null-terminated ASCII format string. + @param FormatString A Null-terminated ASCII format string. @param Marker BASE_LIST marker for the variable argument list. - =20 - @return The number of ASCII characters in the produced output buffer, no= t including the + + @return The number of ASCII characters in the produced output buffer not= including the Null-terminator. =20 **/ @@ -594,33 +634,38 @@ AsciiBSPrint ( /** Produces a Null-terminated ASCII string in an output buffer based on a N= ull-terminated ASCII format string and variable argument list. - =20 + + This function is similar as snprintf_s defined in C11. + Produces a Null-terminated ASCII string in the output buffer specified b= y StartOfBuffer and BufferSize. The ASCII string is produced by parsing the format string specified by F= ormatString. - Arguments are pulled from the variable argument list based on the conten= ts of the=20 + Arguments are pulled from the variable argument list based on the conten= ts of the format string. - The number of ASCII characters in the produced output buffer is returned= , not including + The number of ASCII characters in the produced output buffer is returned= not including the Null-terminator. - If BufferSize is 0, then no output buffer is produced and 0 is returned. =20 - If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT(). - If BufferSize > 0 and FormatString is NULL, then ASSERT(). + If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT(). Also, the ou= tput buffer is + unmodified and 0 is returned. + If BufferSize > 0 and FormatString is NULL, then ASSERT(). Also, the out= put buffer is + unmodified and 0 is returned. + If PcdMaximumAsciiStringLength is not zero, and BufferSize > + (PcdMaximumAsciiStringLength * sizeof (CHAR8)), then ASSERT(). Also, the= output buffer + is unmodified and 0 is returned. If PcdMaximumAsciiStringLength is not zero, and FormatString contains mo= re than - PcdMaximumAsciiStringLength ASCII characters, not including the Null-ter= minator, then - ASSERT(). - If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated= ASCII string - contains more than PcdMaximumAsciiStringLength ASCII characters, not inc= luding the - Null-terminator, then ASSERT(). + PcdMaximumAsciiStringLength Ascii characters not including the Null-term= inator, then + ASSERT(). Also, the output buffer is unmodified and 0 is returned. + + If BufferSize is 0, then no output buffer is produced and 0 is returned. =20 - @param StartOfBuffer A pointer to the output buffer for the produced = Null-terminated=20 + @param StartOfBuffer A pointer to the output buffer for the produced = Null-terminated ASCII string. @param BufferSize The size, in bytes, of the output buffer specifi= ed by StartOfBuffer. - @param FormatString A null-terminated ASCII format string. - @param ... The variable argument list whose contents are ac= cessed based on the=20 + @param FormatString A Null-terminated ASCII format string. + @param ... Variable argument list whose contents are access= ed based on the format string specified by FormatString. - =20 - @return The number of ASCII characters in the produced output buffer, no= t including the + + @return The number of ASCII characters in the produced output buffer not= including the Null-terminator. =20 **/ @@ -636,33 +681,39 @@ AsciiSPrint ( /** Produces a Null-terminated ASCII string in an output buffer based on a N= ull-terminated Unicode format string and a VA_LIST argument list. - =20 + + This function is similar as vsnprintf_s defined in C11. + Produces a Null-terminated ASCII string in the output buffer specified b= y StartOfBuffer and BufferSize. The ASCII string is produced by parsing the format string specified by F= ormatString. - Arguments are pulled from the variable argument list specified by Marker= based on=20 + Arguments are pulled from the variable argument list specified by Marker= based on the contents of the format string. - The number of ASCII characters in the produced output buffer is returned= , not including + The number of ASCII characters in the produced output buffer is returned= not including the Null-terminator. - If BufferSize is 0, then no output buffer is produced and 0 is returned. =20 - If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT(). - If BufferSize > 0 and FormatString is NULL, then ASSERT(). - If BufferSize > 0 and FormatString is not aligned on a 16-bit boundary, = then ASSERT(). + If FormatString is not aligned on a 16-bit boundary, then ASSERT(). + + If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT(). Also, the ou= tput buffer is + unmodified and 0 is returned. + If BufferSize > 0 and FormatString is NULL, then ASSERT(). Also, the out= put buffer is + unmodified and 0 is returned. + If PcdMaximumAsciiStringLength is not zero, and BufferSize > + (PcdMaximumAsciiStringLength * sizeof (CHAR8)), then ASSERT(). Also, the= output buffer + is unmodified and 0 is returned. If PcdMaximumUnicodeStringLength is not zero, and FormatString contains = more than - PcdMaximumUnicodeStringLength Unicode characters, not including the Null= -terminator, then - ASSERT(). - If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated= ASCII string - contains more than PcdMaximumAsciiStringLength ASCII characters, not inc= luding the - Null-terminator, then ASSERT(). + PcdMaximumUnicodeStringLength Unicode characters not including the Null-= terminator, then + ASSERT(). Also, the output buffer is unmodified and 0 is returned. + + If BufferSize is 0, then no output buffer is produced and 0 is returned. =20 - @param StartOfBuffer A pointer to the output buffer for the produced = Null-terminated=20 + @param StartOfBuffer A pointer to the output buffer for the produced = Null-terminated ASCII string. @param BufferSize The size, in bytes, of the output buffer specifi= ed by StartOfBuffer. - @param FormatString A null-terminated Unicode format string. + @param FormatString A Null-terminated Unicode format string. @param Marker VA_LIST marker for the variable argument list. - =20 - @return The number of ASCII characters in the produced output buffer, no= t including the + + @return The number of ASCII characters in the produced output buffer not= including the Null-terminator. =20 **/ @@ -678,33 +729,37 @@ AsciiVSPrintUnicodeFormat ( /** Produces a Null-terminated ASCII string in an output buffer based on a N= ull-terminated Unicode format string and a BASE_LIST argument list. - =20 + Produces a Null-terminated ASCII string in the output buffer specified b= y StartOfBuffer and BufferSize. The ASCII string is produced by parsing the format string specified by F= ormatString. - Arguments are pulled from the variable argument list specified by Marker= based on=20 + Arguments are pulled from the variable argument list specified by Marker= based on the contents of the format string. - The number of ASCII characters in the produced output buffer is returned= , not including + The number of ASCII characters in the produced output buffer is returned= not including the Null-terminator. - If BufferSize is 0, then no output buffer is produced and 0 is returned. =20 - If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT(). - If BufferSize > 0 and FormatString is NULL, then ASSERT(). - If BufferSize > 0 and FormatString is not aligned on a 16-bit boundary, = then ASSERT(). + If FormatString is not aligned on a 16-bit boundary, then ASSERT(). + + If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT(). Also, the ou= tput buffer is + unmodified and 0 is returned. + If BufferSize > 0 and FormatString is NULL, then ASSERT(). Also, the out= put buffer is + unmodified and 0 is returned. + If PcdMaximumAsciiStringLength is not zero, and BufferSize > + (PcdMaximumAsciiStringLength * sizeof (CHAR8)), then ASSERT(). Also, the= output buffer + is unmodified and 0 is returned. If PcdMaximumUnicodeStringLength is not zero, and FormatString contains = more than - PcdMaximumUnicodeStringLength Unicode characters, not including the Null= -terminator, then - ASSERT(). - If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated= ASCII string - contains more than PcdMaximumAsciiStringLength ASCII characters, not inc= luding the - Null-terminator, then ASSERT(). + PcdMaximumUnicodeStringLength Unicode characters not including the Null-= terminator, then + ASSERT(). Also, the output buffer is unmodified and 0 is returned. =20 - @param StartOfBuffer A pointer to the output buffer for the produced = Null-terminated=20 + If BufferSize is 0, then no output buffer is produced and 0 is returned. + + @param StartOfBuffer A pointer to the output buffer for the produced = Null-terminated ASCII string. @param BufferSize The size, in bytes, of the output buffer specifi= ed by StartOfBuffer. - @param FormatString A null-terminated Unicode format string. + @param FormatString A Null-terminated Unicode format string. @param Marker BASE_LIST marker for the variable argument list. - =20 - @return The number of ASCII characters in the produced output buffer, no= t including the + + @return The number of ASCII characters in the produced output buffer not= including the Null-terminator. =20 **/ @@ -720,34 +775,40 @@ AsciiBSPrintUnicodeFormat ( /** Produces a Null-terminated ASCII string in an output buffer based on a N= ull-terminated Unicode format string and variable argument list. - =20 + + This function is similar as snprintf_s defined in C11. + Produces a Null-terminated ASCII string in the output buffer specified b= y StartOfBuffer and BufferSize. The ASCII string is produced by parsing the format string specified by F= ormatString. - Arguments are pulled from the variable argument list based on the conten= ts of the=20 + Arguments are pulled from the variable argument list based on the conten= ts of the format string. - The number of ASCII characters in the produced output buffer is returned= , not including + The number of ASCII characters in the produced output buffer is returned= not including the Null-terminator. - If BufferSize is 0, then no output buffer is produced and 0 is returned. =20 - If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT(). - If BufferSize > 0 and FormatString is NULL, then ASSERT(). - If BufferSize > 0 and FormatString is not aligned on a 16-bit boundary, = then ASSERT(). + If FormatString is not aligned on a 16-bit boundary, then ASSERT(). + + If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT(). Also, the ou= tput buffer is + unmodified and 0 is returned. + If BufferSize > 0 and FormatString is NULL, then ASSERT(). Also, the out= put buffer is + unmodified and 0 is returned. + If PcdMaximumAsciiStringLength is not zero, and BufferSize > + (PcdMaximumAsciiStringLength * sizeof (CHAR8)), then ASSERT(). Also, the= output buffer + is unmodified and 0 is returned. If PcdMaximumUnicodeStringLength is not zero, and FormatString contains = more than - PcdMaximumUnicodeStringLength Unicode characters, not including the Null= -terminator, then - ASSERT(). - If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated= ASCII string - contains more than PcdMaximumAsciiStringLength ASCII characters, not inc= luding the - Null-terminator, then ASSERT(). + PcdMaximumUnicodeStringLength Unicode characters not including the Null-= terminator, then + ASSERT(). Also, the output buffer is unmodified and 0 is returned. + + If BufferSize is 0, then no output buffer is produced and 0 is returned. =20 - @param StartOfBuffer A pointer to the output buffer for the produced = Null-terminated=20 + @param StartOfBuffer A pointer to the output buffer for the produced = Null-terminated ASCII string. @param BufferSize The size, in bytes, of the output buffer specifi= ed by StartOfBuffer. - @param FormatString A null-terminated Unicode format string. - @param ... Variable argument list whose contents are access= ed based on the=20 + @param FormatString A Null-terminated Unicode format string. + @param ... Variable argument list whose contents are access= ed based on the format string specified by FormatString. - =20 - @return The number of ASCII characters in the produced output buffer, no= t including the + + @return The number of ASCII characters in the produced output buffer not= including the Null-terminator. =20 **/ @@ -813,8 +874,12 @@ AsciiValueToString ( Returns the number of characters that would be produced by if the format= ted=20 output were produced not including the Null-terminator. =20 - If Format is NULL, then ASSERT(). - If Format is not aligned on a 16-bit boundary, then ASSERT(). + If FormatString is not aligned on a 16-bit boundary, then ASSERT(). + + If FormatString is NULL, then ASSERT() and 0 is returned. + If PcdMaximumUnicodeStringLength is not zero, and FormatString contains = more + than PcdMaximumUnicodeStringLength Unicode characters not including the + Null-terminator, then ASSERT() and 0 is returned. =20 @param[in] FormatString A Null-terminated Unicode format string. @param[in] Marker VA_LIST marker for the variable argument lis= t. @@ -833,7 +898,10 @@ SPrintLength ( Returns the number of characters that would be produced by if the format= ted=20 output were produced not including the Null-terminator. =20 - If Format is NULL, then ASSERT(). + If FormatString is NULL, then ASSERT() and 0 is returned. + If PcdMaximumAsciiStringLength is not zero, and FormatString contains mo= re + than PcdMaximumAsciiStringLength Ascii characters not including the + Null-terminator, then ASSERT() and 0 is returned. =20 @param[in] FormatString A Null-terminated ASCII format string. @param[in] Marker VA_LIST marker for the variable argument lis= t. diff --git a/MdePkg/Library/BasePrintLib/BasePrintLib.inf b/MdePkg/Library/= BasePrintLib/BasePrintLib.inf index 5457276..069b80d 100644 --- a/MdePkg/Library/BasePrintLib/BasePrintLib.inf +++ b/MdePkg/Library/BasePrintLib/BasePrintLib.inf @@ -1,7 +1,7 @@ ## @file # Print Library implementation. # -# Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.
+# Copyright (c) 2007 - 2017, Intel Corporation. All rights reserved.
# # This program and the accompanying materials # are licensed and made available under the terms and conditions of the B= SD License @@ -41,4 +41,10 @@ [LibraryClasses] DebugLib BaseLib + PcdLib + + +[Pcd] + gEfiMdePkgTokenSpaceGuid.PcdMaximumAsciiStringLength ## SOMETIMES_CO= NSUMES + gEfiMdePkgTokenSpaceGuid.PcdMaximumUnicodeStringLength ## SOMETIMES_CO= NSUMES =20 diff --git a/MdePkg/Library/BasePrintLib/PrintLib.c b/MdePkg/Library/BasePr= intLib/PrintLib.c index 43b2b3c..bf8c7bf 100644 --- a/MdePkg/Library/BasePrintLib/PrintLib.c +++ b/MdePkg/Library/BasePrintLib/PrintLib.c @@ -1,7 +1,7 @@ /** @file Base Print Library instance implementation. =20 - Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.
+ Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.
Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BS= D License @@ -26,35 +26,41 @@ VA_LIST gNullVaList; #define ASSERT_UNICODE_BUFFER(Buffer) ASSERT ((((UINTN) (Buffer)) & 0x01) = =3D=3D 0) =20 /** - Produces a Null-terminated Unicode string in an output buffer based on=20 - a Null-terminated Unicode format string and a VA_LIST argument list - =20 + Produces a Null-terminated Unicode string in an output buffer based on + a Null-terminated Unicode format string and a VA_LIST argument list. + + This function is similar as vsnprintf_s defined in C11. + Produces a Null-terminated Unicode string in the output buffer specified= by StartOfBuffer - and BufferSize. =20 - The Unicode string is produced by parsing the format string specified by= FormatString. =20 - Arguments are pulled from the variable argument list specified by Marker= based on the=20 - contents of the format string. =20 + and BufferSize. + The Unicode string is produced by parsing the format string specified by= FormatString. + Arguments are pulled from the variable argument list specified by Marker= based on the + contents of the format string. The number of Unicode characters in the produced output buffer is return= ed not including the Null-terminator. - If BufferSize is 0 or 1, then no output buffer is produced and 0 is retu= rned. =20 - If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT(). - If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary,= then ASSERT(). - If BufferSize > 1 and FormatString is NULL, then ASSERT(). - If BufferSize > 1 and FormatString is not aligned on a 16-bit boundary, = then ASSERT(). - If PcdMaximumUnicodeStringLength is not zero, and FormatString contains = more than=20 + If StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT(). + If FormatString is not aligned on a 16-bit boundary, then ASSERT(). + + If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT(). Also, the ou= tput buffer is + unmodified and 0 is returned. + If BufferSize > 1 and FormatString is NULL, then ASSERT(). Also, the out= put buffer is + unmodified and 0 is returned. + If PcdMaximumUnicodeStringLength is not zero, and BufferSize > + (PcdMaximumUnicodeStringLength * sizeof (CHAR16) + 1), then ASSERT(). Al= so, the output + buffer is unmodified and 0 is returned. + If PcdMaximumUnicodeStringLength is not zero, and FormatString contains = more than PcdMaximumUnicodeStringLength Unicode characters not including the Null-= terminator, then - ASSERT(). - If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminat= ed Unicode string - contains more than PcdMaximumUnicodeStringLength Unicode characters not = including the - Null-terminator, then ASSERT(). + ASSERT(). Also, the output buffer is unmodified and 0 is returned. =20 - @param StartOfBuffer A pointer to the output buffer for the produced = Null-terminated=20 + If BufferSize is 0 or 1, then the output buffer is unmodified and 0 is r= eturned. + + @param StartOfBuffer A pointer to the output buffer for the produced = Null-terminated Unicode string. @param BufferSize The size, in bytes, of the output buffer specifi= ed by StartOfBuffer. @param FormatString A Null-terminated Unicode format string. @param Marker VA_LIST marker for the variable argument list. - =20 + @return The number of Unicode characters in the produced output buffer n= ot including the Null-terminator. =20 @@ -74,35 +80,39 @@ UnicodeVSPrint ( } =20 /** - Produces a Null-terminated Unicode string in an output buffer based on=20 - a Null-terminated Unicode format string and a BASE_LIST argument list - =20 + Produces a Null-terminated Unicode string in an output buffer based on + a Null-terminated Unicode format string and a BASE_LIST argument list. + Produces a Null-terminated Unicode string in the output buffer specified= by StartOfBuffer - and BufferSize. =20 - The Unicode string is produced by parsing the format string specified by= FormatString. =20 - Arguments are pulled from the variable argument list specified by Marker= based on the=20 - contents of the format string. =20 + and BufferSize. + The Unicode string is produced by parsing the format string specified by= FormatString. + Arguments are pulled from the variable argument list specified by Marker= based on the + contents of the format string. The number of Unicode characters in the produced output buffer is return= ed not including the Null-terminator. - If BufferSize is 0 or 1, then no output buffer is produced and 0 is retu= rned. =20 - If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT(). - If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary,= then ASSERT(). - If BufferSize > 1 and FormatString is NULL, then ASSERT(). - If BufferSize > 1 and FormatString is not aligned on a 16-bit boundary, = then ASSERT(). - If PcdMaximumUnicodeStringLength is not zero, and FormatString contains = more than=20 + If StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT(). + If FormatString is not aligned on a 16-bit boundary, then ASSERT(). + + If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT(). Also, the ou= tput buffer is + unmodified and 0 is returned. + If BufferSize > 1 and FormatString is NULL, then ASSERT(). Also, the out= put buffer is + unmodified and 0 is returned. + If PcdMaximumUnicodeStringLength is not zero, and BufferSize > + (PcdMaximumUnicodeStringLength * sizeof (CHAR16) + 1), then ASSERT(). Al= so, the output + buffer is unmodified and 0 is returned. + If PcdMaximumUnicodeStringLength is not zero, and FormatString contains = more than PcdMaximumUnicodeStringLength Unicode characters not including the Null-= terminator, then - ASSERT(). - If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminat= ed Unicode string - contains more than PcdMaximumUnicodeStringLength Unicode characters not = including the - Null-terminator, then ASSERT(). + ASSERT(). Also, the output buffer is unmodified and 0 is returned. + + If BufferSize is 0 or 1, then the output buffer is unmodified and 0 is r= eturned. =20 - @param StartOfBuffer A pointer to the output buffer for the produced = Null-terminated=20 + @param StartOfBuffer A pointer to the output buffer for the produced = Null-terminated Unicode string. @param BufferSize The size, in bytes, of the output buffer specifi= ed by StartOfBuffer. @param FormatString A Null-terminated Unicode format string. @param Marker BASE_LIST marker for the variable argument list. - =20 + @return The number of Unicode characters in the produced output buffer n= ot including the Null-terminator. =20 @@ -122,35 +132,41 @@ UnicodeBSPrint ( } =20 /** - Produces a Null-terminated Unicode string in an output buffer based on a= Null-terminated=20 + Produces a Null-terminated Unicode string in an output buffer based on a= Null-terminated Unicode format string and variable argument list. - =20 + + This function is similar as snprintf_s defined in C11. + Produces a Null-terminated Unicode string in the output buffer specified= by StartOfBuffer and BufferSize. The Unicode string is produced by parsing the format string specified by= FormatString. Arguments are pulled from the variable argument list based on the conten= ts of the format string. The number of Unicode characters in the produced output buffer is return= ed not including the Null-terminator. - If BufferSize is 0 or 1, then no output buffer is produced and 0 is retu= rned. =20 - If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT(). - If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary,= then ASSERT(). - If BufferSize > 1 and FormatString is NULL, then ASSERT(). - If BufferSize > 1 and FormatString is not aligned on a 16-bit boundary, = then ASSERT(). - If PcdMaximumUnicodeStringLength is not zero, and FormatString contains = more than=20 + If StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT(). + If FormatString is not aligned on a 16-bit boundary, then ASSERT(). + + If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT(). Also, the ou= tput buffer is + unmodified and 0 is returned. + If BufferSize > 1 and FormatString is NULL, then ASSERT(). Also, the out= put buffer is + unmodified and 0 is returned. + If PcdMaximumUnicodeStringLength is not zero, and BufferSize > + (PcdMaximumUnicodeStringLength * sizeof (CHAR16) + 1), then ASSERT(). Al= so, the output + buffer is unmodified and 0 is returned. + If PcdMaximumUnicodeStringLength is not zero, and FormatString contains = more than PcdMaximumUnicodeStringLength Unicode characters not including the Null-= terminator, then - ASSERT(). - If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminat= ed Unicode string - contains more than PcdMaximumUnicodeStringLength Unicode characters not = including the - Null-terminator, then ASSERT(). + ASSERT(). Also, the output buffer is unmodified and 0 is returned. + + If BufferSize is 0 or 1, then the output buffer is unmodified and 0 is r= eturned. =20 - @param StartOfBuffer A pointer to the output buffer for the produced = Null-terminated=20 + @param StartOfBuffer A pointer to the output buffer for the produced = Null-terminated Unicode string. @param BufferSize The size, in bytes, of the output buffer specifi= ed by StartOfBuffer. @param FormatString A Null-terminated Unicode format string. - @param ... Variable argument list whose contents are access= ed based on the=20 + @param ... Variable argument list whose contents are access= ed based on the format string specified by FormatString. - =20 + @return The number of Unicode characters in the produced output buffer n= ot including the Null-terminator. =20 @@ -175,33 +191,39 @@ UnicodeSPrint ( =20 /** Produces a Null-terminated Unicode string in an output buffer based on a= Null-terminated - ASCII format string and a VA_LIST argument list - =20 + ASCII format string and a VA_LIST argument list. + + This function is similar as vsnprintf_s defined in C11. + Produces a Null-terminated Unicode string in the output buffer specified= by StartOfBuffer and BufferSize. The Unicode string is produced by parsing the format string specified by= FormatString. - Arguments are pulled from the variable argument list specified by Marker= based on the=20 + Arguments are pulled from the variable argument list specified by Marker= based on the contents of the format string. The number of Unicode characters in the produced output buffer is return= ed not including the Null-terminator. - If BufferSize is 0 or 1, then no output buffer is produced and 0 is retu= rned. =20 - If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT(). - If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary,= then ASSERT(). - If BufferSize > 1 and FormatString is NULL, then ASSERT(). + If StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT(). + + If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT(). Also, the ou= tput buffer is + unmodified and 0 is returned. + If BufferSize > 1 and FormatString is NULL, then ASSERT(). Also, the out= put buffer is + unmodified and 0 is returned. + If PcdMaximumUnicodeStringLength is not zero, and BufferSize > + (PcdMaximumUnicodeStringLength * sizeof (CHAR16) + 1), then ASSERT(). Al= so, the output + buffer is unmodified and 0 is returned. If PcdMaximumAsciiStringLength is not zero, and FormatString contains mo= re than - PcdMaximumAsciiStringLength ASCII characters not including the Null-term= inator, then - ASSERT(). - If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminat= ed Unicode string - contains more than PcdMaximumUnicodeStringLength Unicode characters not = including the - Null-terminator, then ASSERT(). + PcdMaximumAsciiStringLength Ascii characters not including the Null-term= inator, then + ASSERT(). Also, the output buffer is unmodified and 0 is returned. =20 - @param StartOfBuffer A pointer to the output buffer for the produced = Null-terminated=20 + If BufferSize is 0 or 1, then no output buffer is produced and 0 is retu= rned. + + @param StartOfBuffer A pointer to the output buffer for the produced = Null-terminated Unicode string. @param BufferSize The size, in bytes, of the output buffer specifi= ed by StartOfBuffer. @param FormatString A Null-terminated ASCII format string. @param Marker VA_LIST marker for the variable argument list. - =20 + @return The number of Unicode characters in the produced output buffer n= ot including the Null-terminator. =20 @@ -221,33 +243,37 @@ UnicodeVSPrintAsciiFormat ( =20 /** Produces a Null-terminated Unicode string in an output buffer based on a= Null-terminated - ASCII format string and a BASE_LIST argument list - =20 + ASCII format string and a BASE_LIST argument list. + Produces a Null-terminated Unicode string in the output buffer specified= by StartOfBuffer and BufferSize. The Unicode string is produced by parsing the format string specified by= FormatString. - Arguments are pulled from the variable argument list specified by Marker= based on the=20 + Arguments are pulled from the variable argument list specified by Marker= based on the contents of the format string. The number of Unicode characters in the produced output buffer is return= ed not including the Null-terminator. - If BufferSize is 0 or 1, then no output buffer is produced and 0 is retu= rned. =20 - If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT(). - If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary,= then ASSERT(). - If BufferSize > 1 and FormatString is NULL, then ASSERT(). + If StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT(). + + If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT(). Also, the ou= tput buffer is + unmodified and 0 is returned. + If BufferSize > 1 and FormatString is NULL, then ASSERT(). Also, the out= put buffer is + unmodified and 0 is returned. + If PcdMaximumUnicodeStringLength is not zero, and BufferSize > + (PcdMaximumUnicodeStringLength * sizeof (CHAR16) + 1), then ASSERT(). Al= so, the output + buffer is unmodified and 0 is returned. If PcdMaximumAsciiStringLength is not zero, and FormatString contains mo= re than - PcdMaximumAsciiStringLength ASCII characters not including the Null-term= inator, then - ASSERT(). - If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminat= ed Unicode string - contains more than PcdMaximumUnicodeStringLength Unicode characters not = including the - Null-terminator, then ASSERT(). + PcdMaximumAsciiStringLength Ascii characters not including the Null-term= inator, then + ASSERT(). Also, the output buffer is unmodified and 0 is returned. + + If BufferSize is 0 or 1, then no output buffer is produced and 0 is retu= rned. =20 - @param StartOfBuffer A pointer to the output buffer for the produced = Null-terminated=20 + @param StartOfBuffer A pointer to the output buffer for the produced = Null-terminated Unicode string. @param BufferSize The size, in bytes, of the output buffer specifi= ed by StartOfBuffer. @param FormatString A Null-terminated ASCII format string. @param Marker BASE_LIST marker for the variable argument list. - =20 + @return The number of Unicode characters in the produced output buffer n= ot including the Null-terminator. =20 @@ -266,35 +292,41 @@ UnicodeBSPrintAsciiFormat ( } =20 /** - Produces a Null-terminated Unicode string in an output buffer based on a= Null-terminated=20 + Produces a Null-terminated Unicode string in an output buffer based on a= Null-terminated ASCII format string and variable argument list. - =20 + + This function is similar as snprintf_s defined in C11. + Produces a Null-terminated Unicode string in the output buffer specified= by StartOfBuffer and BufferSize. The Unicode string is produced by parsing the format string specified by= FormatString. - Arguments are pulled from the variable argument list based on the conten= ts of the=20 + Arguments are pulled from the variable argument list based on the conten= ts of the format string. The number of Unicode characters in the produced output buffer is return= ed not including the Null-terminator. - If BufferSize is 0 or 1, then no output buffer is produced and 0 is retu= rned. =20 - If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT(). - If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary,= then ASSERT(). - If BufferSize > 1 and FormatString is NULL, then ASSERT(). + If StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT(). + + If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT(). Also, the ou= tput buffer is + unmodified and 0 is returned. + If BufferSize > 1 and FormatString is NULL, then ASSERT(). Also, the out= put buffer is + unmodified and 0 is returned. + If PcdMaximumUnicodeStringLength is not zero, and BufferSize > + (PcdMaximumUnicodeStringLength * sizeof (CHAR16) + 1), then ASSERT(). Al= so, the output + buffer is unmodified and 0 is returned. If PcdMaximumAsciiStringLength is not zero, and FormatString contains mo= re than - PcdMaximumAsciiStringLength ASCII characters not including the Null-term= inator, then - ASSERT(). - If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminat= ed Unicode string - contains more than PcdMaximumUnicodeStringLength Unicode characters not = including the - Null-terminator, then ASSERT(). + PcdMaximumAsciiStringLength Ascii characters not including the Null-term= inator, then + ASSERT(). Also, the output buffer is unmodified and 0 is returned. + + If BufferSize is 0 or 1, then no output buffer is produced and 0 is retu= rned. =20 - @param StartOfBuffer A pointer to the output buffer for the produced = Null-terminated=20 + @param StartOfBuffer A pointer to the output buffer for the produced = Null-terminated Unicode string. @param BufferSize The size, in bytes, of the output buffer specifi= ed by StartOfBuffer. @param FormatString A Null-terminated ASCII format string. - @param ... Variable argument list whose contents are access= ed based on the=20 + @param ... Variable argument list whose contents are access= ed based on the format string specified by FormatString. - =20 + @return The number of Unicode characters in the produced output buffer n= ot including the Null-terminator. =20 @@ -374,31 +406,36 @@ UnicodeValueToString ( /** Produces a Null-terminated ASCII string in an output buffer based on a N= ull-terminated ASCII format string and a VA_LIST argument list. - =20 + + This function is similar as vsnprintf_s defined in C11. + Produces a Null-terminated ASCII string in the output buffer specified b= y StartOfBuffer and BufferSize. The ASCII string is produced by parsing the format string specified by F= ormatString. - Arguments are pulled from the variable argument list specified by Marker= based on=20 + Arguments are pulled from the variable argument list specified by Marker= based on the contents of the format string. The number of ASCII characters in the produced output buffer is returned= not including the Null-terminator. - If BufferSize is 0, then no output buffer is produced and 0 is returned. =20 - If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT(). - If BufferSize > 0 and FormatString is NULL, then ASSERT(). + If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT(). Also, the ou= tput buffer is + unmodified and 0 is returned. + If BufferSize > 0 and FormatString is NULL, then ASSERT(). Also, the out= put buffer is + unmodified and 0 is returned. + If PcdMaximumAsciiStringLength is not zero, and BufferSize > + (PcdMaximumAsciiStringLength * sizeof (CHAR8)), then ASSERT(). Also, the= output buffer + is unmodified and 0 is returned. If PcdMaximumAsciiStringLength is not zero, and FormatString contains mo= re than - PcdMaximumAsciiStringLength ASCII characters not including the Null-term= inator, then - ASSERT(). - If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated= ASCII string - contains more than PcdMaximumAsciiStringLength ASCII characters not incl= uding the - Null-terminator, then ASSERT(). + PcdMaximumAsciiStringLength Ascii characters not including the Null-term= inator, then + ASSERT(). Also, the output buffer is unmodified and 0 is returned. + + If BufferSize is 0, then no output buffer is produced and 0 is returned. =20 - @param StartOfBuffer A pointer to the output buffer for the produced = Null-terminated=20 + @param StartOfBuffer A pointer to the output buffer for the produced = Null-terminated ASCII string. @param BufferSize The size, in bytes, of the output buffer specifi= ed by StartOfBuffer. @param FormatString A Null-terminated ASCII format string. @param Marker VA_LIST marker for the variable argument list. - =20 + @return The number of ASCII characters in the produced output buffer not= including the Null-terminator. =20 @@ -418,31 +455,34 @@ AsciiVSPrint ( /** Produces a Null-terminated ASCII string in an output buffer based on a N= ull-terminated ASCII format string and a BASE_LIST argument list. - =20 + Produces a Null-terminated ASCII string in the output buffer specified b= y StartOfBuffer and BufferSize. The ASCII string is produced by parsing the format string specified by F= ormatString. - Arguments are pulled from the variable argument list specified by Marker= based on=20 + Arguments are pulled from the variable argument list specified by Marker= based on the contents of the format string. The number of ASCII characters in the produced output buffer is returned= not including the Null-terminator. - If BufferSize is 0, then no output buffer is produced and 0 is returned. =20 - If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT(). - If BufferSize > 0 and FormatString is NULL, then ASSERT(). + If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT(). Also, the ou= tput buffer is + unmodified and 0 is returned. + If BufferSize > 0 and FormatString is NULL, then ASSERT(). Also, the out= put buffer is + unmodified and 0 is returned. + If PcdMaximumAsciiStringLength is not zero, and BufferSize > + (PcdMaximumAsciiStringLength * sizeof (CHAR8)), then ASSERT(). Also, the= output buffer + is unmodified and 0 is returned. If PcdMaximumAsciiStringLength is not zero, and FormatString contains mo= re than - PcdMaximumAsciiStringLength ASCII characters not including the Null-term= inator, then - ASSERT(). - If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated= ASCII string - contains more than PcdMaximumAsciiStringLength ASCII characters not incl= uding the - Null-terminator, then ASSERT(). + PcdMaximumAsciiStringLength Ascii characters not including the Null-term= inator, then + ASSERT(). Also, the output buffer is unmodified and 0 is returned. + + If BufferSize is 0, then no output buffer is produced and 0 is returned. =20 - @param StartOfBuffer A pointer to the output buffer for the produced = Null-terminated=20 + @param StartOfBuffer A pointer to the output buffer for the produced = Null-terminated ASCII string. @param BufferSize The size, in bytes, of the output buffer specifi= ed by StartOfBuffer. @param FormatString A Null-terminated ASCII format string. @param Marker BASE_LIST marker for the variable argument list. - =20 + @return The number of ASCII characters in the produced output buffer not= including the Null-terminator. =20 @@ -462,32 +502,37 @@ AsciiBSPrint ( /** Produces a Null-terminated ASCII string in an output buffer based on a N= ull-terminated ASCII format string and variable argument list. - =20 + + This function is similar as snprintf_s defined in C11. + Produces a Null-terminated ASCII string in the output buffer specified b= y StartOfBuffer and BufferSize. The ASCII string is produced by parsing the format string specified by F= ormatString. - Arguments are pulled from the variable argument list based on the conten= ts of the=20 + Arguments are pulled from the variable argument list based on the conten= ts of the format string. The number of ASCII characters in the produced output buffer is returned= not including the Null-terminator. - If BufferSize is 0, then no output buffer is produced and 0 is returned. =20 - If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT(). - If BufferSize > 0 and FormatString is NULL, then ASSERT(). + If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT(). Also, the ou= tput buffer is + unmodified and 0 is returned. + If BufferSize > 0 and FormatString is NULL, then ASSERT(). Also, the out= put buffer is + unmodified and 0 is returned. + If PcdMaximumAsciiStringLength is not zero, and BufferSize > + (PcdMaximumAsciiStringLength * sizeof (CHAR8)), then ASSERT(). Also, the= output buffer + is unmodified and 0 is returned. If PcdMaximumAsciiStringLength is not zero, and FormatString contains mo= re than - PcdMaximumAsciiStringLength ASCII characters not including the Null-term= inator, then - ASSERT(). - If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated= ASCII string - contains more than PcdMaximumAsciiStringLength ASCII characters not incl= uding the - Null-terminator, then ASSERT(). + PcdMaximumAsciiStringLength Ascii characters not including the Null-term= inator, then + ASSERT(). Also, the output buffer is unmodified and 0 is returned. =20 - @param StartOfBuffer A pointer to the output buffer for the produced = Null-terminated=20 + If BufferSize is 0, then no output buffer is produced and 0 is returned. + + @param StartOfBuffer A pointer to the output buffer for the produced = Null-terminated ASCII string. @param BufferSize The size, in bytes, of the output buffer specifi= ed by StartOfBuffer. @param FormatString A Null-terminated ASCII format string. - @param ... Variable argument list whose contents are access= ed based on the=20 + @param ... Variable argument list whose contents are access= ed based on the format string specified by FormatString. - =20 + @return The number of ASCII characters in the produced output buffer not= including the Null-terminator. =20 @@ -513,32 +558,38 @@ AsciiSPrint ( /** Produces a Null-terminated ASCII string in an output buffer based on a N= ull-terminated Unicode format string and a VA_LIST argument list. - =20 + + This function is similar as vsnprintf_s defined in C11. + Produces a Null-terminated ASCII string in the output buffer specified b= y StartOfBuffer and BufferSize. The ASCII string is produced by parsing the format string specified by F= ormatString. - Arguments are pulled from the variable argument list specified by Marker= based on=20 + Arguments are pulled from the variable argument list specified by Marker= based on the contents of the format string. The number of ASCII characters in the produced output buffer is returned= not including the Null-terminator. - If BufferSize is 0, then no output buffer is produced and 0 is returned. =20 - If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT(). - If BufferSize > 0 and FormatString is NULL, then ASSERT(). - If BufferSize > 0 and FormatString is not aligned on a 16-bit boundary, = then ASSERT(). + If FormatString is not aligned on a 16-bit boundary, then ASSERT(). + + If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT(). Also, the ou= tput buffer is + unmodified and 0 is returned. + If BufferSize > 0 and FormatString is NULL, then ASSERT(). Also, the out= put buffer is + unmodified and 0 is returned. + If PcdMaximumAsciiStringLength is not zero, and BufferSize > + (PcdMaximumAsciiStringLength * sizeof (CHAR8)), then ASSERT(). Also, the= output buffer + is unmodified and 0 is returned. If PcdMaximumUnicodeStringLength is not zero, and FormatString contains = more than PcdMaximumUnicodeStringLength Unicode characters not including the Null-= terminator, then - ASSERT(). - If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated= ASCII string - contains more than PcdMaximumAsciiStringLength ASCII characters not incl= uding the - Null-terminator, then ASSERT(). + ASSERT(). Also, the output buffer is unmodified and 0 is returned. + + If BufferSize is 0, then no output buffer is produced and 0 is returned. =20 - @param StartOfBuffer A pointer to the output buffer for the produced = Null-terminated=20 + @param StartOfBuffer A pointer to the output buffer for the produced = Null-terminated ASCII string. @param BufferSize The size, in bytes, of the output buffer specifi= ed by StartOfBuffer. @param FormatString A Null-terminated Unicode format string. @param Marker VA_LIST marker for the variable argument list. - =20 + @return The number of ASCII characters in the produced output buffer not= including the Null-terminator. =20 @@ -559,32 +610,36 @@ AsciiVSPrintUnicodeFormat ( /** Produces a Null-terminated ASCII string in an output buffer based on a N= ull-terminated Unicode format string and a BASE_LIST argument list. - =20 + Produces a Null-terminated ASCII string in the output buffer specified b= y StartOfBuffer and BufferSize. The ASCII string is produced by parsing the format string specified by F= ormatString. - Arguments are pulled from the variable argument list specified by Marker= based on=20 + Arguments are pulled from the variable argument list specified by Marker= based on the contents of the format string. The number of ASCII characters in the produced output buffer is returned= not including the Null-terminator. - If BufferSize is 0, then no output buffer is produced and 0 is returned. =20 - If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT(). - If BufferSize > 0 and FormatString is NULL, then ASSERT(). - If BufferSize > 0 and FormatString is not aligned on a 16-bit boundary, = then ASSERT(). + If FormatString is not aligned on a 16-bit boundary, then ASSERT(). + + If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT(). Also, the ou= tput buffer is + unmodified and 0 is returned. + If BufferSize > 0 and FormatString is NULL, then ASSERT(). Also, the out= put buffer is + unmodified and 0 is returned. + If PcdMaximumAsciiStringLength is not zero, and BufferSize > + (PcdMaximumAsciiStringLength * sizeof (CHAR8)), then ASSERT(). Also, the= output buffer + is unmodified and 0 is returned. If PcdMaximumUnicodeStringLength is not zero, and FormatString contains = more than PcdMaximumUnicodeStringLength Unicode characters not including the Null-= terminator, then - ASSERT(). - If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated= ASCII string - contains more than PcdMaximumAsciiStringLength ASCII characters not incl= uding the - Null-terminator, then ASSERT(). + ASSERT(). Also, the output buffer is unmodified and 0 is returned. =20 - @param StartOfBuffer A pointer to the output buffer for the produced = Null-terminated=20 + If BufferSize is 0, then no output buffer is produced and 0 is returned. + + @param StartOfBuffer A pointer to the output buffer for the produced = Null-terminated ASCII string. @param BufferSize The size, in bytes, of the output buffer specifi= ed by StartOfBuffer. @param FormatString A Null-terminated Unicode format string. @param Marker BASE_LIST marker for the variable argument list. - =20 + @return The number of ASCII characters in the produced output buffer not= including the Null-terminator. =20 @@ -605,33 +660,39 @@ AsciiBSPrintUnicodeFormat ( /** Produces a Null-terminated ASCII string in an output buffer based on a N= ull-terminated Unicode format string and variable argument list. - =20 + + This function is similar as snprintf_s defined in C11. + Produces a Null-terminated ASCII string in the output buffer specified b= y StartOfBuffer and BufferSize. The ASCII string is produced by parsing the format string specified by F= ormatString. - Arguments are pulled from the variable argument list based on the conten= ts of the=20 + Arguments are pulled from the variable argument list based on the conten= ts of the format string. The number of ASCII characters in the produced output buffer is returned= not including the Null-terminator. - If BufferSize is 0, then no output buffer is produced and 0 is returned. =20 - If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT(). - If BufferSize > 0 and FormatString is NULL, then ASSERT(). - If BufferSize > 0 and FormatString is not aligned on a 16-bit boundary, = then ASSERT(). + If FormatString is not aligned on a 16-bit boundary, then ASSERT(). + + If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT(). Also, the ou= tput buffer is + unmodified and 0 is returned. + If BufferSize > 0 and FormatString is NULL, then ASSERT(). Also, the out= put buffer is + unmodified and 0 is returned. + If PcdMaximumAsciiStringLength is not zero, and BufferSize > + (PcdMaximumAsciiStringLength * sizeof (CHAR8)), then ASSERT(). Also, the= output buffer + is unmodified and 0 is returned. If PcdMaximumUnicodeStringLength is not zero, and FormatString contains = more than PcdMaximumUnicodeStringLength Unicode characters not including the Null-= terminator, then - ASSERT(). - If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated= ASCII string - contains more than PcdMaximumAsciiStringLength ASCII characters not incl= uding the - Null-terminator, then ASSERT(). + ASSERT(). Also, the output buffer is unmodified and 0 is returned. + + If BufferSize is 0, then no output buffer is produced and 0 is returned. =20 - @param StartOfBuffer A pointer to the output buffer for the produced = Null-terminated=20 + @param StartOfBuffer A pointer to the output buffer for the produced = Null-terminated ASCII string. @param BufferSize The size, in bytes, of the output buffer specifi= ed by StartOfBuffer. @param FormatString A Null-terminated Unicode format string. - @param ... Variable argument list whose contents are access= ed based on the=20 + @param ... Variable argument list whose contents are access= ed based on the format string specified by FormatString. - =20 + @return The number of ASCII characters in the produced output buffer not= including the Null-terminator. =20 @@ -711,9 +772,13 @@ AsciiValueToString ( Returns the number of characters that would be produced by if the format= ted=20 output were produced not including the Null-terminator. =20 - If FormatString is NULL, then ASSERT(). If FormatString is not aligned on a 16-bit boundary, then ASSERT(). =20 + If FormatString is NULL, then ASSERT() and 0 is returned. + If PcdMaximumUnicodeStringLength is not zero, and FormatString contains = more + than PcdMaximumUnicodeStringLength Unicode characters not including the + Null-terminator, then ASSERT() and 0 is returned. + @param[in] FormatString A Null-terminated Unicode format string. @param[in] Marker VA_LIST marker for the variable argument lis= t. =20 @@ -727,7 +792,6 @@ SPrintLength ( IN VA_LIST Marker ) { - ASSERT(FormatString !=3D NULL); ASSERT_UNICODE_BUFFER (FormatString); return BasePrintLibSPrintMarker (NULL, 0, FORMAT_UNICODE | OUTPUT_UNICOD= E | COUNT_ONLY_NO_PRINT, (CHAR8 *)FormatString, Marker, NULL); } @@ -736,7 +800,10 @@ SPrintLength ( Returns the number of characters that would be produced by if the format= ted=20 output were produced not including the Null-terminator. =20 - If FormatString is NULL, then ASSERT(). + If FormatString is NULL, then ASSERT() and 0 is returned. + If PcdMaximumAsciiStringLength is not zero, and FormatString contains mo= re + than PcdMaximumAsciiStringLength Ascii characters not including the + Null-terminator, then ASSERT() and 0 is returned. =20 @param[in] FormatString A Null-terminated ASCII format string. @param[in] Marker VA_LIST marker for the variable argument lis= t. @@ -751,6 +818,5 @@ SPrintLengthAsciiFormat ( IN VA_LIST Marker ) { - ASSERT(FormatString !=3D NULL); return BasePrintLibSPrintMarker (NULL, 0, OUTPUT_UNICODE | COUNT_ONLY_NO= _PRINT, (CHAR8 *)FormatString, Marker, NULL); } diff --git a/MdePkg/Library/BasePrintLib/PrintLibInternal.c b/MdePkg/Librar= y/BasePrintLib/PrintLibInternal.c index d73e1d6..155fe6a 100644 --- a/MdePkg/Library/BasePrintLib/PrintLibInternal.c +++ b/MdePkg/Library/BasePrintLib/PrintLibInternal.c @@ -1,7 +1,7 @@ /** @file Print Library internal worker functions. =20 - Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.
+ Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BS= D License which accompanies this distribution. The full text of the license may b= e found at @@ -17,6 +17,20 @@ #define WARNING_STATUS_NUMBER 5 #define ERROR_STATUS_NUMBER 33 =20 +// +// Safe print checks +// +#define RSIZE_MAX (PcdGet32 (PcdMaximumUnicodeStringLength)) +#define ASCII_RSIZE_MAX (PcdGet32 (PcdMaximumAsciiStringLength)) + +#define SAFE_PRINT_CONSTRAINT_CHECK(Expression, RetVal) \ + do { \ + ASSERT (Expression); \ + if (!(Expression)) { \ + return RetVal; \ + } \ + } while (FALSE) + GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 mHexStr[] =3D {'0','1','2','3','= 4','5','6','7','8','9','A','B','C','D','E','F'}; =20 GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 * CONST mStatusString[] =3D { @@ -352,6 +366,56 @@ BasePrintLibSPrintMarker ( // DxePrintLibPrint2Protocol (both PrintLib instances). // =20 + // + // 1. Buffer shall not be a null pointer when both BufferSize > 0 and + // COUNT_ONLY_NO_PRINT is not set in Flags. + // + if ((BufferSize > 0) && ((Flags & COUNT_ONLY_NO_PRINT) =3D=3D 0)) { + SAFE_PRINT_CONSTRAINT_CHECK ((Buffer !=3D NULL), 0); + } + + // + // 2. Format shall not be a null pointer when BufferSize > 0 or when + // COUNT_ONLY_NO_PRINT is set in Flags. + // + if ((BufferSize > 0) || ((Flags & COUNT_ONLY_NO_PRINT) !=3D 0)) { + SAFE_PRINT_CONSTRAINT_CHECK ((Format !=3D NULL), 0); + } + + // + // 3. BufferSize shall not be greater than RSIZE_MAX for Unicode output = or + // ASCII_RSIZE_MAX for Ascii output. + // + if ((Flags & OUTPUT_UNICODE) !=3D 0) { + if (RSIZE_MAX !=3D 0) { + SAFE_PRINT_CONSTRAINT_CHECK ((BufferSize <=3D RSIZE_MAX), 0); + } + BytesPerOutputCharacter =3D 2; + } else { + if (ASCII_RSIZE_MAX !=3D 0) { + SAFE_PRINT_CONSTRAINT_CHECK ((BufferSize <=3D ASCII_RSIZE_MAX), 0); + } + BytesPerOutputCharacter =3D 1; + } + + // + // 4. Format shall not contain more than RSIZE_MAX Unicode characters or + // ASCII_RSIZE_MAX Ascii characters. + // + if ((Flags & FORMAT_UNICODE) !=3D 0) { + if (RSIZE_MAX !=3D 0) { + SAFE_PRINT_CONSTRAINT_CHECK ((StrnLenS ((CHAR16 *)Format, RSIZE_MAX = + 1) <=3D RSIZE_MAX), 0); + } + BytesPerFormatCharacter =3D 2; + FormatMask =3D 0xffff; + } else { + if (ASCII_RSIZE_MAX !=3D 0) { + SAFE_PRINT_CONSTRAINT_CHECK ((AsciiStrnLenS (Format, ASCII_RSIZE_MAX= + 1) <=3D ASCII_RSIZE_MAX), 0); + } + BytesPerFormatCharacter =3D 1; + FormatMask =3D 0xff; + } + if ((Flags & COUNT_ONLY_NO_PRINT) !=3D 0) { if (BufferSize =3D=3D 0) { Buffer =3D NULL; @@ -363,13 +427,6 @@ BasePrintLibSPrintMarker ( if (BufferSize =3D=3D 0) { return 0; } - ASSERT (Buffer !=3D NULL); - } - - if ((Flags & OUTPUT_UNICODE) !=3D 0) { - BytesPerOutputCharacter =3D 2; - } else { - BytesPerOutputCharacter =3D 1; } =20 LengthToReturn =3D 0; @@ -389,24 +446,6 @@ BasePrintLibSPrintMarker ( EndBuffer =3D Buffer + BufferSize * BytesPerOutputCharacter; } =20 - if ((Flags & FORMAT_UNICODE) !=3D 0) { - // - // Make sure format string cannot contain more than PcdMaximumUnicodeS= tringLength - // Unicode characters if PcdMaximumUnicodeStringLength is not zero.=20 - // - ASSERT (StrSize ((CHAR16 *) Format) !=3D 0); - BytesPerFormatCharacter =3D 2; - FormatMask =3D 0xffff; - } else { - // - // Make sure format string cannot contain more than PcdMaximumAsciiStr= ingLength - // Ascii characters if PcdMaximumAsciiStringLength is not zero.=20 - // - ASSERT (AsciiStrSize (Format) !=3D 0); - BytesPerFormatCharacter =3D 1; - FormatMask =3D 0xff; - } - // // Get the first character from the format string // @@ -975,16 +1014,6 @@ BasePrintLibSPrintMarker ( // Null terminate the Unicode or ASCII string // BasePrintLibFillBuffer (Buffer, EndBuffer + BytesPerOutputCharacter, 1, = 0, BytesPerOutputCharacter); - // - // Make sure output buffer cannot contain more than PcdMaximumUnicodeStr= ingLength - // Unicode characters if PcdMaximumUnicodeStringLength is not zero.=20 - // - ASSERT ((((Flags & OUTPUT_UNICODE) =3D=3D 0)) || (StrSize ((CHAR16 *) Or= iginalBuffer) !=3D 0)); - // - // Make sure output buffer cannot contain more than PcdMaximumAsciiStrin= gLength - // ASCII characters if PcdMaximumAsciiStringLength is not zero.=20 - // - ASSERT ((((Flags & OUTPUT_UNICODE) !=3D 0)) || (AsciiStrSize (OriginalBu= ffer) !=3D 0)); =20 return ((Buffer - OriginalBuffer) / BytesPerOutputCharacter); } diff --git a/MdePkg/Library/BasePrintLib/PrintLibInternal.h b/MdePkg/Librar= y/BasePrintLib/PrintLibInternal.h index 05f2e1b..fccef9b 100644 --- a/MdePkg/Library/BasePrintLib/PrintLibInternal.h +++ b/MdePkg/Library/BasePrintLib/PrintLibInternal.h @@ -1,7 +1,7 @@ /** @file Base Print Library instance Internal Functions definition. =20 - Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.
+ Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BS= D License which accompanies this distribution. The full text of the license may b= e found at @@ -19,6 +19,7 @@ #include #include #include +#include =20 =20 // --=20 1.9.5.msysgit.0 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Thu May 2 10:59:27 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zoho.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1486611179980387.0550250606997; Wed, 8 Feb 2017 19:32:59 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 80D4F8211D; Wed, 8 Feb 2017 19:32:58 -0800 (PST) Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 2D174820CF for ; Wed, 8 Feb 2017 19:32:57 -0800 (PST) Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga104.jf.intel.com with ESMTP; 08 Feb 2017 19:32:57 -0800 Received: from shwdeopenpsi014.ccr.corp.intel.com ([10.239.9.13]) by orsmga004.jf.intel.com with ESMTP; 08 Feb 2017 19:32:55 -0800 X-Original-To: edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.35,349,1484035200"; d="scan'208";a="56777744" From: Hao Wu To: edk2-devel@lists.01.org Date: Thu, 9 Feb 2017 11:32:40 +0800 Message-Id: <1486611161-37308-3-git-send-email-hao.a.wu@intel.com> X-Mailer: git-send-email 1.9.5.msysgit.0 In-Reply-To: <1486611161-37308-1-git-send-email-hao.a.wu@intel.com> References: <1486611161-37308-1-git-send-email-hao.a.wu@intel.com> Subject: [edk2] [PATCH v2 2/3] MdeModulePkg/PrintLib: Refine the SPrint functions X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Hao Wu , Michael Kinney , Jiewen Yao , Liming Gao MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" For the following 12 APIs in MdeModulePkg/DxePrintLibPrint2Protocol: UnicodeVSPrint UnicodeBSPrint UnicodeSPrint UnicodeVSPrintAsciiFormat UnicodeBSPrintAsciiFormat UnicodeSPrintAsciiFormat AsciiVSPrint AsciiBSPrint AsciiSPrint AsciiVSPrintUnicodeFormat AsciiBSPrintUnicodeFormat AsciiSPrintUnicodeFormat They will ASSERT when: 1) The input parameter 'StartOfBuffer' is NULL if 'BufferSize' indicates at least 1 Ascii/Unicode character can be held. 2) The input parameter 'FormatString' is NULL if 'BufferSize' indicates at least 1 Ascii/Unicode character can be held. 3) The input parameter 'FormatString' contains more than PcdMaximum[Ascii|Unicode]StringLength Ascii/Unicode characters. 4) The produced string contains more than PcdMaximum[Ascii|Unicode]StringLength Ascii/Unicode characters. This commits removes the ASSERT case 4) and add the following new ASSERT case: 4) The input parameter 'BufferSize' is greater than (PcdMaximumAsciiStringLength * sizeof (CHAR8)) for Ascii format string or (PcdMaximumUnicodeStringLength * sizeof (CHAR16) + 1) for Unicode format string. And for those ASSERT cases, 0 will be returned by those 12 APIs. For the following 2 APIs in MdeModulePkg/DxePrintLibPrint2Protocol: SPrintLength SPrintLengthAsciiFormat They will ASSERT when: 1) The input parameter 'FormatString' is NULL. 2) The input parameter 'FormatString' contains more than PcdMaximum[Ascii|Unicode]StringLength Ascii/Unicode characters. And for those ASSERT cases, 0 will be returned by those 2 APIs. Now these APIs in the MdeModulePkg/DxePrintLibPrint2Protocol instance follow the same rules with MdePkg/BasePrintLib. Cc: Jiewen Yao Cc: Liming Gao Cc: Michael Kinney Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Hao Wu Reviewed-by: Liming Gao --- MdeModulePkg/Library/DxePrintLibPrint2Protocol/DxePrintLibPrint2Protocol.i= nf | 7 +- MdeModulePkg/Library/DxePrintLibPrint2Protocol/PrintLib.c = | 562 ++++++++++++-------- 2 files changed, 344 insertions(+), 225 deletions(-) diff --git a/MdeModulePkg/Library/DxePrintLibPrint2Protocol/DxePrintLibPrin= t2Protocol.inf b/MdeModulePkg/Library/DxePrintLibPrint2Protocol/DxePrintLib= Print2Protocol.inf index 3d09b4b..55ee940 100644 --- a/MdeModulePkg/Library/DxePrintLibPrint2Protocol/DxePrintLibPrint2Proto= col.inf +++ b/MdeModulePkg/Library/DxePrintLibPrint2Protocol/DxePrintLibPrint2Proto= col.inf @@ -1,7 +1,7 @@ ## @file # Library instance that implements Print Library class based on protocol = gEfiPrint2ProtocolGuid. # -# Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.
+# Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.
# # This program and the accompanying materials # are licensed and made available under the terms and conditions of the B= SD License @@ -33,9 +33,14 @@ [LibraryClasses] BaseLib DebugLib + PcdLib =20 [Protocols] gEfiPrint2ProtocolGuid ## CONSUMES =20 +[Pcd] + gEfiMdePkgTokenSpaceGuid.PcdMaximumAsciiStringLength ## SOMETIMES_CO= NSUMES + gEfiMdePkgTokenSpaceGuid.PcdMaximumUnicodeStringLength ## SOMETIMES_CO= NSUMES + [Depex.common.DXE_DRIVER, Depex.common.DXE_RUNTIME_DRIVER, Depex.common.DX= E_SAL_DRIVER, Depex.common.DXE_SMM_DRIVER] gEfiPrint2ProtocolGuid diff --git a/MdeModulePkg/Library/DxePrintLibPrint2Protocol/PrintLib.c b/Md= eModulePkg/Library/DxePrintLibPrint2Protocol/PrintLib.c index 0137868..438ac9e 100644 --- a/MdeModulePkg/Library/DxePrintLibPrint2Protocol/PrintLib.c +++ b/MdeModulePkg/Library/DxePrintLibPrint2Protocol/PrintLib.c @@ -25,6 +25,23 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHE= R EXPRESS OR IMPLIED. =20 #include #include +#include + +#define ASSERT_UNICODE_BUFFER(Buffer) ASSERT ((((UINTN) (Buffer)) & 0x01) = =3D=3D 0) + +// +// Safe print checks +// +#define RSIZE_MAX (PcdGet32 (PcdMaximumUnicodeStringLength)) +#define ASCII_RSIZE_MAX (PcdGet32 (PcdMaximumAsciiStringLength)) + +#define SAFE_PRINT_CONSTRAINT_CHECK(Expression, RetVal) \ + do { \ + ASSERT (Expression); \ + if (!(Expression)) { \ + return RetVal; \ + } \ + } while (FALSE) =20 EFI_PRINT2_PROTOCOL *mPrint2Protocol =3D NULL; =20 @@ -91,17 +108,21 @@ DxePrintLibPrint2ProtocolVaListToBaseList ( BOOLEAN Long; BOOLEAN Done; =20 - ASSERT (Format !=3D NULL); ASSERT (BaseListMarker !=3D NULL); + SAFE_PRINT_CONSTRAINT_CHECK ((Format !=3D NULL), FALSE); =20 BaseListStart =3D BaseListMarker; =20 if (AsciiFormat) { - ASSERT (AsciiStrSize (Format) !=3D 0); + if (ASCII_RSIZE_MAX !=3D 0) { + SAFE_PRINT_CONSTRAINT_CHECK ((AsciiStrnLenS (Format, ASCII_RSIZE_MAX= + 1) <=3D ASCII_RSIZE_MAX), FALSE); + } BytesPerFormatCharacter =3D 1; FormatMask =3D 0xff; } else { - ASSERT (StrSize ((CHAR16 *) Format) !=3D 0); + if (RSIZE_MAX !=3D 0) { + SAFE_PRINT_CONSTRAINT_CHECK ((StrnLenS ((CHAR16 *)Format, RSIZE_MAX = + 1) <=3D RSIZE_MAX), FALSE); + } BytesPerFormatCharacter =3D 2; FormatMask =3D 0xffff; } @@ -224,35 +245,41 @@ DxePrintLibPrint2ProtocolVaListToBaseList ( } =20 /** - Produces a Null-terminated Unicode string in an output buffer based on=20 - a Null-terminated Unicode format string and a VA_LIST argument list - =20 + Produces a Null-terminated Unicode string in an output buffer based on + a Null-terminated Unicode format string and a VA_LIST argument list. + + This function is similar as vsnprintf_s defined in C11. + Produces a Null-terminated Unicode string in the output buffer specified= by StartOfBuffer - and BufferSize. =20 - The Unicode string is produced by parsing the format string specified by= FormatString. =20 - Arguments are pulled from the variable argument list specified by Marker= based on the=20 - contents of the format string. =20 + and BufferSize. + The Unicode string is produced by parsing the format string specified by= FormatString. + Arguments are pulled from the variable argument list specified by Marker= based on the + contents of the format string. The number of Unicode characters in the produced output buffer is return= ed not including the Null-terminator. - If BufferSize is 0 or 1, then no output buffer is produced and 0 is retu= rned. =20 - If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT(). - If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary,= then ASSERT(). - If BufferSize > 1 and FormatString is NULL, then ASSERT(). - If BufferSize > 1 and FormatString is not aligned on a 16-bit boundary, = then ASSERT(). - If PcdMaximumUnicodeStringLength is not zero, and FormatString contains = more than=20 + If StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT(). + If FormatString is not aligned on a 16-bit boundary, then ASSERT(). + + If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT(). Also, the ou= tput buffer is + unmodified and 0 is returned. + If BufferSize > 1 and FormatString is NULL, then ASSERT(). Also, the out= put buffer is + unmodified and 0 is returned. + If PcdMaximumUnicodeStringLength is not zero, and BufferSize > + (PcdMaximumUnicodeStringLength * sizeof (CHAR16) + 1), then ASSERT(). Al= so, the output + buffer is unmodified and 0 is returned. + If PcdMaximumUnicodeStringLength is not zero, and FormatString contains = more than PcdMaximumUnicodeStringLength Unicode characters not including the Null-= terminator, then - ASSERT(). - If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminat= ed Unicode string - contains more than PcdMaximumUnicodeStringLength Unicode characters not = including the - Null-terminator, then ASSERT(). + ASSERT(). Also, the output buffer is unmodified and 0 is returned. + + If BufferSize is 0 or 1, then the output buffer is unmodified and 0 is r= eturned. =20 - @param StartOfBuffer A pointer to the output buffer for the produced = Null-terminated=20 + @param StartOfBuffer A pointer to the output buffer for the produced = Null-terminated Unicode string. @param BufferSize The size, in bytes, of the output buffer specifi= ed by StartOfBuffer. - @param FormatString Null-terminated Unicode format string. + @param FormatString A Null-terminated Unicode format string. @param Marker VA_LIST marker for the variable argument list. - =20 + @return The number of Unicode characters in the produced output buffer n= ot including the Null-terminator. =20 @@ -269,6 +296,9 @@ UnicodeVSPrint ( UINT64 BaseListMarker[256 / sizeof (UINT64)]; BOOLEAN Converted; =20 + ASSERT_UNICODE_BUFFER (StartOfBuffer); + ASSERT_UNICODE_BUFFER (FormatString); + Converted =3D DxePrintLibPrint2ProtocolVaListToBaseList ( FALSE, (CHAR8 *)FormatString, @@ -284,35 +314,39 @@ UnicodeVSPrint ( } =20 /** - Produces a Null-terminated Unicode string in an output buffer based on=20 - a Null-terminated Unicode format string and a BASE_LIST argument list - =20 + Produces a Null-terminated Unicode string in an output buffer based on + a Null-terminated Unicode format string and a BASE_LIST argument list. + Produces a Null-terminated Unicode string in the output buffer specified= by StartOfBuffer - and BufferSize. =20 - The Unicode string is produced by parsing the format string specified by= FormatString. =20 - Arguments are pulled from the variable argument list specified by Marker= based on the=20 - contents of the format string. =20 + and BufferSize. + The Unicode string is produced by parsing the format string specified by= FormatString. + Arguments are pulled from the variable argument list specified by Marker= based on the + contents of the format string. The number of Unicode characters in the produced output buffer is return= ed not including the Null-terminator. - If BufferSize is 0 or 1, then no output buffer is produced and 0 is retu= rned. =20 - If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT(). - If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary,= then ASSERT(). - If BufferSize > 1 and FormatString is NULL, then ASSERT(). - If BufferSize > 1 and FormatString is not aligned on a 16-bit boundary, = then ASSERT(). - If PcdMaximumUnicodeStringLength is not zero, and FormatString contains = more than=20 + If StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT(). + If FormatString is not aligned on a 16-bit boundary, then ASSERT(). + + If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT(). Also, the ou= tput buffer is + unmodified and 0 is returned. + If BufferSize > 1 and FormatString is NULL, then ASSERT(). Also, the out= put buffer is + unmodified and 0 is returned. + If PcdMaximumUnicodeStringLength is not zero, and BufferSize > + (PcdMaximumUnicodeStringLength * sizeof (CHAR16) + 1), then ASSERT(). Al= so, the output + buffer is unmodified and 0 is returned. + If PcdMaximumUnicodeStringLength is not zero, and FormatString contains = more than PcdMaximumUnicodeStringLength Unicode characters not including the Null-= terminator, then - ASSERT(). - If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminat= ed Unicode string - contains more than PcdMaximumUnicodeStringLength Unicode characters not = including the - Null-terminator, then ASSERT(). + ASSERT(). Also, the output buffer is unmodified and 0 is returned. + + If BufferSize is 0 or 1, then the output buffer is unmodified and 0 is r= eturned. =20 - @param StartOfBuffer A pointer to the output buffer for the produced = Null-terminated=20 + @param StartOfBuffer A pointer to the output buffer for the produced = Null-terminated Unicode string. @param BufferSize The size, in bytes, of the output buffer specifi= ed by StartOfBuffer. - @param FormatString Null-terminated Unicode format string. + @param FormatString A Null-terminated Unicode format string. @param Marker BASE_LIST marker for the variable argument list. - =20 + @return The number of Unicode characters in the produced output buffer n= ot including the Null-terminator. =20 @@ -326,37 +360,45 @@ UnicodeBSPrint ( IN BASE_LIST Marker ) { + ASSERT_UNICODE_BUFFER (StartOfBuffer); + ASSERT_UNICODE_BUFFER (FormatString); return mPrint2Protocol->UnicodeBSPrint (StartOfBuffer, BufferSize, Forma= tString, Marker); } =20 /** - Produces a Null-terminated Unicode string in an output buffer based on a= Null-terminated=20 + Produces a Null-terminated Unicode string in an output buffer based on a= Null-terminated Unicode format string and variable argument list. - =20 + + This function is similar as snprintf_s defined in C11. + Produces a Null-terminated Unicode string in the output buffer specified= by StartOfBuffer and BufferSize. The Unicode string is produced by parsing the format string specified by= FormatString. Arguments are pulled from the variable argument list based on the conten= ts of the format string. The number of Unicode characters in the produced output buffer is return= ed not including the Null-terminator. - If BufferSize is 0 or 1, then no output buffer is produced and 0 is retu= rned. =20 - If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT(). - If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary,= then ASSERT(). - If BufferSize > 1 and FormatString is NULL, then ASSERT(). - If BufferSize > 1 and FormatString is not aligned on a 16-bit boundary, = then ASSERT(). - If PcdMaximumUnicodeStringLength is not zero, and FormatString contains = more than=20 + If StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT(). + If FormatString is not aligned on a 16-bit boundary, then ASSERT(). + + If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT(). Also, the ou= tput buffer is + unmodified and 0 is returned. + If BufferSize > 1 and FormatString is NULL, then ASSERT(). Also, the out= put buffer is + unmodified and 0 is returned. + If PcdMaximumUnicodeStringLength is not zero, and BufferSize > + (PcdMaximumUnicodeStringLength * sizeof (CHAR16) + 1), then ASSERT(). Al= so, the output + buffer is unmodified and 0 is returned. + If PcdMaximumUnicodeStringLength is not zero, and FormatString contains = more than PcdMaximumUnicodeStringLength Unicode characters not including the Null-= terminator, then - ASSERT(). - If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminat= ed Unicode string - contains more than PcdMaximumUnicodeStringLength Unicode characters not = including the - Null-terminator, then ASSERT(). + ASSERT(). Also, the output buffer is unmodified and 0 is returned. + + If BufferSize is 0 or 1, then the output buffer is unmodified and 0 is r= eturned. =20 - @param StartOfBuffer A pointer to the output buffer for the produced = Null-terminated=20 + @param StartOfBuffer A pointer to the output buffer for the produced = Null-terminated Unicode string. @param BufferSize The size, in bytes, of the output buffer specifi= ed by StartOfBuffer. - @param FormatString Null-terminated Unicode format string. - @param ... Variable argument list whose contents are access= ed based on the=20 + @param FormatString A Null-terminated Unicode format string. + @param ... Variable argument list whose contents are access= ed based on the format string specified by FormatString. =20 @return The number of Unicode characters in the produced output buffer n= ot including the @@ -383,33 +425,39 @@ UnicodeSPrint ( =20 /** Produces a Null-terminated Unicode string in an output buffer based on a= Null-terminated - ASCII format string and a VA_LIST argument list - =20 + ASCII format string and a VA_LIST argument list. + + This function is similar as vsnprintf_s defined in C11. + Produces a Null-terminated Unicode string in the output buffer specified= by StartOfBuffer and BufferSize. The Unicode string is produced by parsing the format string specified by= FormatString. - Arguments are pulled from the variable argument list specified by Marker= based on the=20 + Arguments are pulled from the variable argument list specified by Marker= based on the contents of the format string. The number of Unicode characters in the produced output buffer is return= ed not including the Null-terminator. - If BufferSize is 0 or 1, then no output buffer is produced and 0 is retu= rned. =20 - If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT(). - If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary,= then ASSERT(). - If BufferSize > 1 and FormatString is NULL, then ASSERT(). + If StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT(). + + If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT(). Also, the ou= tput buffer is + unmodified and 0 is returned. + If BufferSize > 1 and FormatString is NULL, then ASSERT(). Also, the out= put buffer is + unmodified and 0 is returned. + If PcdMaximumUnicodeStringLength is not zero, and BufferSize > + (PcdMaximumUnicodeStringLength * sizeof (CHAR16) + 1), then ASSERT(). Al= so, the output + buffer is unmodified and 0 is returned. If PcdMaximumAsciiStringLength is not zero, and FormatString contains mo= re than - PcdMaximumAsciiStringLength ASCII characters not including the Null-term= inator, then - ASSERT(). - If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminat= ed Unicode string - contains more than PcdMaximumUnicodeStringLength Unicode characters not = including the - Null-terminator, then ASSERT(). + PcdMaximumAsciiStringLength Ascii characters not including the Null-term= inator, then + ASSERT(). Also, the output buffer is unmodified and 0 is returned. =20 - @param StartOfBuffer A pointer to the output buffer for the produced = Null-terminated=20 + If BufferSize is 0 or 1, then no output buffer is produced and 0 is retu= rned. + + @param StartOfBuffer A pointer to the output buffer for the produced = Null-terminated Unicode string. @param BufferSize The size, in bytes, of the output buffer specifi= ed by StartOfBuffer. - @param FormatString Null-terminated Unicode format string. + @param FormatString A Null-terminated ASCII format string. @param Marker VA_LIST marker for the variable argument list. - =20 + @return The number of Unicode characters in the produced output buffer n= ot including the Null-terminator. =20 @@ -426,6 +474,8 @@ UnicodeVSPrintAsciiFormat ( UINT64 BaseListMarker[256 / sizeof (UINT64)]; BOOLEAN Converted; =20 + ASSERT_UNICODE_BUFFER (StartOfBuffer); + Converted =3D DxePrintLibPrint2ProtocolVaListToBaseList ( TRUE, FormatString, @@ -442,33 +492,37 @@ UnicodeVSPrintAsciiFormat ( =20 /** Produces a Null-terminated Unicode string in an output buffer based on a= Null-terminated - ASCII format string and a BASE_LIST argument list - =20 + ASCII format string and a BASE_LIST argument list. + Produces a Null-terminated Unicode string in the output buffer specified= by StartOfBuffer and BufferSize. The Unicode string is produced by parsing the format string specified by= FormatString. - Arguments are pulled from the variable argument list specified by Marker= based on the=20 + Arguments are pulled from the variable argument list specified by Marker= based on the contents of the format string. The number of Unicode characters in the produced output buffer is return= ed not including the Null-terminator. - If BufferSize is 0 or 1, then no output buffer is produced and 0 is retu= rned. =20 - If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT(). - If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary,= then ASSERT(). - If BufferSize > 1 and FormatString is NULL, then ASSERT(). + If StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT(). + + If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT(). Also, the ou= tput buffer is + unmodified and 0 is returned. + If BufferSize > 1 and FormatString is NULL, then ASSERT(). Also, the out= put buffer is + unmodified and 0 is returned. + If PcdMaximumUnicodeStringLength is not zero, and BufferSize > + (PcdMaximumUnicodeStringLength * sizeof (CHAR16) + 1), then ASSERT(). Al= so, the output + buffer is unmodified and 0 is returned. If PcdMaximumAsciiStringLength is not zero, and FormatString contains mo= re than - PcdMaximumAsciiStringLength ASCII characters not including the Null-term= inator, then - ASSERT(). - If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminat= ed Unicode string - contains more than PcdMaximumUnicodeStringLength Unicode characters not = including the - Null-terminator, then ASSERT(). + PcdMaximumAsciiStringLength Ascii characters not including the Null-term= inator, then + ASSERT(). Also, the output buffer is unmodified and 0 is returned. + + If BufferSize is 0 or 1, then no output buffer is produced and 0 is retu= rned. =20 - @param StartOfBuffer A pointer to the output buffer for the produced = Null-terminated=20 + @param StartOfBuffer A pointer to the output buffer for the produced = Null-terminated Unicode string. @param BufferSize The size, in bytes, of the output buffer specifi= ed by StartOfBuffer. - @param FormatString Null-terminated Unicode format string. + @param FormatString A Null-terminated ASCII format string. @param Marker BASE_LIST marker for the variable argument list. - =20 + @return The number of Unicode characters in the produced output buffer n= ot including the Null-terminator. =20 @@ -482,39 +536,46 @@ UnicodeBSPrintAsciiFormat ( IN BASE_LIST Marker ) { + ASSERT_UNICODE_BUFFER (StartOfBuffer); return mPrint2Protocol->UnicodeBSPrintAsciiFormat (StartOfBuffer, Buffer= Size, FormatString, Marker); } =20 /** - Produces a Null-terminated Unicode string in an output buffer based on a= Null-terminated=20 + Produces a Null-terminated Unicode string in an output buffer based on a= Null-terminated ASCII format string and variable argument list. - =20 + + This function is similar as snprintf_s defined in C11. + Produces a Null-terminated Unicode string in the output buffer specified= by StartOfBuffer and BufferSize. The Unicode string is produced by parsing the format string specified by= FormatString. - Arguments are pulled from the variable argument list based on the conten= ts of the=20 + Arguments are pulled from the variable argument list based on the conten= ts of the format string. The number of Unicode characters in the produced output buffer is return= ed not including the Null-terminator. - If BufferSize is 0 or 1, then no output buffer is produced and 0 is retu= rned. =20 - If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT(). - If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary,= then ASSERT(). - If BufferSize > 1 and FormatString is NULL, then ASSERT(). + If StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT(). + + If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT(). Also, the ou= tput buffer is + unmodified and 0 is returned. + If BufferSize > 1 and FormatString is NULL, then ASSERT(). Also, the out= put buffer is + unmodified and 0 is returned. + If PcdMaximumUnicodeStringLength is not zero, and BufferSize > + (PcdMaximumUnicodeStringLength * sizeof (CHAR16) + 1), then ASSERT(). Al= so, the output + buffer is unmodified and 0 is returned. If PcdMaximumAsciiStringLength is not zero, and FormatString contains mo= re than - PcdMaximumAsciiStringLength ASCII characters not including the Null-term= inator, then - ASSERT(). - If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminat= ed Unicode string - contains more than PcdMaximumUnicodeStringLength Unicode characters not = including the - Null-terminator, then ASSERT(). + PcdMaximumAsciiStringLength Ascii characters not including the Null-term= inator, then + ASSERT(). Also, the output buffer is unmodified and 0 is returned. + + If BufferSize is 0 or 1, then no output buffer is produced and 0 is retu= rned. =20 - @param StartOfBuffer A pointer to the output buffer for the produced = Null-terminated=20 + @param StartOfBuffer A pointer to the output buffer for the produced = Null-terminated Unicode string. @param BufferSize The size, in bytes, of the output buffer specifi= ed by StartOfBuffer. - @param FormatString Null-terminated Unicode format string. - @param ... Variable argument list whose contents are access= ed based on the=20 + @param FormatString A Null-terminated ASCII format string. + @param ... Variable argument list whose contents are access= ed based on the format string specified by FormatString. - =20 + @return The number of Unicode characters in the produced output buffer n= ot including the Null-terminator. =20 @@ -593,31 +654,36 @@ UnicodeValueToString ( /** Produces a Null-terminated ASCII string in an output buffer based on a N= ull-terminated ASCII format string and a VA_LIST argument list. - =20 + + This function is similar as vsnprintf_s defined in C11. + Produces a Null-terminated ASCII string in the output buffer specified b= y StartOfBuffer and BufferSize. The ASCII string is produced by parsing the format string specified by F= ormatString. - Arguments are pulled from the variable argument list specified by Marker= based on=20 + Arguments are pulled from the variable argument list specified by Marker= based on the contents of the format string. The number of ASCII characters in the produced output buffer is returned= not including the Null-terminator. - If BufferSize is 0, then no output buffer is produced and 0 is returned. =20 - If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT(). - If BufferSize > 0 and FormatString is NULL, then ASSERT(). + If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT(). Also, the ou= tput buffer is + unmodified and 0 is returned. + If BufferSize > 0 and FormatString is NULL, then ASSERT(). Also, the out= put buffer is + unmodified and 0 is returned. + If PcdMaximumAsciiStringLength is not zero, and BufferSize > + (PcdMaximumAsciiStringLength * sizeof (CHAR8)), then ASSERT(). Also, the= output buffer + is unmodified and 0 is returned. If PcdMaximumAsciiStringLength is not zero, and FormatString contains mo= re than - PcdMaximumAsciiStringLength ASCII characters not including the Null-term= inator, then - ASSERT(). - If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated= ASCII string - contains more than PcdMaximumAsciiStringLength ASCII characters not incl= uding the - Null-terminator, then ASSERT(). + PcdMaximumAsciiStringLength Ascii characters not including the Null-term= inator, then + ASSERT(). Also, the output buffer is unmodified and 0 is returned. + + If BufferSize is 0, then no output buffer is produced and 0 is returned. =20 - @param StartOfBuffer A pointer to the output buffer for the produced = Null-terminated=20 + @param StartOfBuffer A pointer to the output buffer for the produced = Null-terminated ASCII string. @param BufferSize The size, in bytes, of the output buffer specifi= ed by StartOfBuffer. - @param FormatString Null-terminated Unicode format string. + @param FormatString A Null-terminated ASCII format string. @param Marker VA_LIST marker for the variable argument list. - =20 + @return The number of ASCII characters in the produced output buffer not= including the Null-terminator. =20 @@ -651,31 +717,34 @@ AsciiVSPrint ( /** Produces a Null-terminated ASCII string in an output buffer based on a N= ull-terminated ASCII format string and a BASE_LIST argument list. - =20 + Produces a Null-terminated ASCII string in the output buffer specified b= y StartOfBuffer and BufferSize. The ASCII string is produced by parsing the format string specified by F= ormatString. - Arguments are pulled from the variable argument list specified by Marker= based on=20 + Arguments are pulled from the variable argument list specified by Marker= based on the contents of the format string. The number of ASCII characters in the produced output buffer is returned= not including the Null-terminator. - If BufferSize is 0, then no output buffer is produced and 0 is returned. =20 - If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT(). - If BufferSize > 0 and FormatString is NULL, then ASSERT(). + If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT(). Also, the ou= tput buffer is + unmodified and 0 is returned. + If BufferSize > 0 and FormatString is NULL, then ASSERT(). Also, the out= put buffer is + unmodified and 0 is returned. + If PcdMaximumAsciiStringLength is not zero, and BufferSize > + (PcdMaximumAsciiStringLength * sizeof (CHAR8)), then ASSERT(). Also, the= output buffer + is unmodified and 0 is returned. If PcdMaximumAsciiStringLength is not zero, and FormatString contains mo= re than - PcdMaximumAsciiStringLength ASCII characters not including the Null-term= inator, then - ASSERT(). - If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated= ASCII string - contains more than PcdMaximumAsciiStringLength ASCII characters not incl= uding the - Null-terminator, then ASSERT(). + PcdMaximumAsciiStringLength Ascii characters not including the Null-term= inator, then + ASSERT(). Also, the output buffer is unmodified and 0 is returned. =20 - @param StartOfBuffer A pointer to the output buffer for the produced = Null-terminated=20 + If BufferSize is 0, then no output buffer is produced and 0 is returned. + + @param StartOfBuffer A pointer to the output buffer for the produced = Null-terminated ASCII string. @param BufferSize The size, in bytes, of the output buffer specifi= ed by StartOfBuffer. - @param FormatString Null-terminated Unicode format string. + @param FormatString A Null-terminated ASCII format string. @param Marker BASE_LIST marker for the variable argument list. - =20 + @return The number of ASCII characters in the produced output buffer not= including the Null-terminator. =20 @@ -695,30 +764,35 @@ AsciiBSPrint ( /** Produces a Null-terminated ASCII string in an output buffer based on a N= ull-terminated ASCII format string and variable argument list. - =20 + + This function is similar as snprintf_s defined in C11. + Produces a Null-terminated ASCII string in the output buffer specified b= y StartOfBuffer and BufferSize. The ASCII string is produced by parsing the format string specified by F= ormatString. - Arguments are pulled from the variable argument list based on the conten= ts of the=20 + Arguments are pulled from the variable argument list based on the conten= ts of the format string. The number of ASCII characters in the produced output buffer is returned= not including the Null-terminator. - If BufferSize is 0, then no output buffer is produced and 0 is returned. =20 - If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT(). - If BufferSize > 0 and FormatString is NULL, then ASSERT(). + If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT(). Also, the ou= tput buffer is + unmodified and 0 is returned. + If BufferSize > 0 and FormatString is NULL, then ASSERT(). Also, the out= put buffer is + unmodified and 0 is returned. + If PcdMaximumAsciiStringLength is not zero, and BufferSize > + (PcdMaximumAsciiStringLength * sizeof (CHAR8)), then ASSERT(). Also, the= output buffer + is unmodified and 0 is returned. If PcdMaximumAsciiStringLength is not zero, and FormatString contains mo= re than - PcdMaximumAsciiStringLength ASCII characters not including the Null-term= inator, then - ASSERT(). - If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated= ASCII string - contains more than PcdMaximumAsciiStringLength ASCII characters not incl= uding the - Null-terminator, then ASSERT(). + PcdMaximumAsciiStringLength Ascii characters not including the Null-term= inator, then + ASSERT(). Also, the output buffer is unmodified and 0 is returned. + + If BufferSize is 0, then no output buffer is produced and 0 is returned. =20 - @param StartOfBuffer A pointer to the output buffer for the produced = Null-terminated=20 + @param StartOfBuffer A pointer to the output buffer for the produced = Null-terminated ASCII string. @param BufferSize The size, in bytes, of the output buffer specifi= ed by StartOfBuffer. - @param FormatString Null-terminated Unicode format string. - @param ... Variable argument list whose contents are access= ed based on the=20 + @param FormatString A Null-terminated ASCII format string. + @param ... Variable argument list whose contents are access= ed based on the format string specified by FormatString. =20 @return The number of ASCII characters in the produced output buffer not= including the @@ -745,33 +819,39 @@ AsciiSPrint ( =20 /** Produces a Null-terminated ASCII string in an output buffer based on a N= ull-terminated - ASCII format string and a VA_LIST argument list. - =20 + Unicode format string and a VA_LIST argument list. + + This function is similar as vsnprintf_s defined in C11. + Produces a Null-terminated ASCII string in the output buffer specified b= y StartOfBuffer and BufferSize. The ASCII string is produced by parsing the format string specified by F= ormatString. - Arguments are pulled from the variable argument list specified by Marker= based on=20 + Arguments are pulled from the variable argument list specified by Marker= based on the contents of the format string. The number of ASCII characters in the produced output buffer is returned= not including the Null-terminator. - If BufferSize is 0, then no output buffer is produced and 0 is returned. =20 - If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT(). - If BufferSize > 0 and FormatString is NULL, then ASSERT(). - If BufferSize > 0 and FormatString is not aligned on a 16-bit boundary, = then ASSERT(). + If FormatString is not aligned on a 16-bit boundary, then ASSERT(). + + If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT(). Also, the ou= tput buffer is + unmodified and 0 is returned. + If BufferSize > 0 and FormatString is NULL, then ASSERT(). Also, the out= put buffer is + unmodified and 0 is returned. + If PcdMaximumAsciiStringLength is not zero, and BufferSize > + (PcdMaximumAsciiStringLength * sizeof (CHAR8)), then ASSERT(). Also, the= output buffer + is unmodified and 0 is returned. If PcdMaximumUnicodeStringLength is not zero, and FormatString contains = more than PcdMaximumUnicodeStringLength Unicode characters not including the Null-= terminator, then - ASSERT(). - If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated= ASCII string - contains more than PcdMaximumAsciiStringLength ASCII characters not incl= uding the - Null-terminator, then ASSERT(). + ASSERT(). Also, the output buffer is unmodified and 0 is returned. =20 - @param StartOfBuffer A pointer to the output buffer for the produced = Null-terminated=20 + If BufferSize is 0, then no output buffer is produced and 0 is returned. + + @param StartOfBuffer A pointer to the output buffer for the produced = Null-terminated ASCII string. @param BufferSize The size, in bytes, of the output buffer specifi= ed by StartOfBuffer. - @param FormatString Null-terminated Unicode format string. + @param FormatString A Null-terminated Unicode format string. @param Marker VA_LIST marker for the variable argument list. - =20 + @return The number of ASCII characters in the produced output buffer not= including the Null-terminator. =20 @@ -788,6 +868,8 @@ AsciiVSPrintUnicodeFormat ( UINT64 BaseListMarker[256 / sizeof (UINT64)]; BOOLEAN Converted; =20 + ASSERT_UNICODE_BUFFER (FormatString); + Converted =3D DxePrintLibPrint2ProtocolVaListToBaseList ( FALSE, (CHAR8 *)FormatString, @@ -804,33 +886,37 @@ AsciiVSPrintUnicodeFormat ( =20 /** Produces a Null-terminated ASCII string in an output buffer based on a N= ull-terminated - ASCII format string and a BASE_LIST argument list. - =20 + Unicode format string and a BASE_LIST argument list. + Produces a Null-terminated ASCII string in the output buffer specified b= y StartOfBuffer and BufferSize. The ASCII string is produced by parsing the format string specified by F= ormatString. - Arguments are pulled from the variable argument list specified by Marker= based on=20 + Arguments are pulled from the variable argument list specified by Marker= based on the contents of the format string. The number of ASCII characters in the produced output buffer is returned= not including the Null-terminator. - If BufferSize is 0, then no output buffer is produced and 0 is returned. =20 - If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT(). - If BufferSize > 0 and FormatString is NULL, then ASSERT(). - If BufferSize > 0 and FormatString is not aligned on a 16-bit boundary, = then ASSERT(). + If FormatString is not aligned on a 16-bit boundary, then ASSERT(). + + If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT(). Also, the ou= tput buffer is + unmodified and 0 is returned. + If BufferSize > 0 and FormatString is NULL, then ASSERT(). Also, the out= put buffer is + unmodified and 0 is returned. + If PcdMaximumAsciiStringLength is not zero, and BufferSize > + (PcdMaximumAsciiStringLength * sizeof (CHAR8)), then ASSERT(). Also, the= output buffer + is unmodified and 0 is returned. If PcdMaximumUnicodeStringLength is not zero, and FormatString contains = more than PcdMaximumUnicodeStringLength Unicode characters not including the Null-= terminator, then - ASSERT(). - If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated= ASCII string - contains more than PcdMaximumAsciiStringLength ASCII characters not incl= uding the - Null-terminator, then ASSERT(). + ASSERT(). Also, the output buffer is unmodified and 0 is returned. =20 - @param StartOfBuffer A pointer to the output buffer for the produced = Null-terminated=20 + If BufferSize is 0, then no output buffer is produced and 0 is returned. + + @param StartOfBuffer A pointer to the output buffer for the produced = Null-terminated ASCII string. @param BufferSize The size, in bytes, of the output buffer specifi= ed by StartOfBuffer. - @param FormatString Null-terminated Unicode format string. + @param FormatString A Null-terminated Unicode format string. @param Marker BASE_LIST marker for the variable argument list. - =20 + @return The number of ASCII characters in the produced output buffer not= including the Null-terminator. =20 @@ -844,37 +930,44 @@ AsciiBSPrintUnicodeFormat ( IN BASE_LIST Marker ) { + ASSERT_UNICODE_BUFFER (FormatString); return mPrint2Protocol->AsciiBSPrintUnicodeFormat (StartOfBuffer, Buffer= Size, FormatString, Marker); } =20 /** Produces a Null-terminated ASCII string in an output buffer based on a N= ull-terminated - ASCII format string and variable argument list. - =20 + Unicode format string and variable argument list. + + This function is similar as snprintf_s defined in C11. + Produces a Null-terminated ASCII string in the output buffer specified b= y StartOfBuffer and BufferSize. The ASCII string is produced by parsing the format string specified by F= ormatString. - Arguments are pulled from the variable argument list based on the conten= ts of the=20 + Arguments are pulled from the variable argument list based on the conten= ts of the format string. The number of ASCII characters in the produced output buffer is returned= not including the Null-terminator. - If BufferSize is 0, then no output buffer is produced and 0 is returned. =20 - If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT(). - If BufferSize > 0 and FormatString is NULL, then ASSERT(). - If BufferSize > 0 and FormatString is not aligned on a 16-bit boundary, = then ASSERT(). + If FormatString is not aligned on a 16-bit boundary, then ASSERT(). + + If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT(). Also, the ou= tput buffer is + unmodified and 0 is returned. + If BufferSize > 0 and FormatString is NULL, then ASSERT(). Also, the out= put buffer is + unmodified and 0 is returned. + If PcdMaximumAsciiStringLength is not zero, and BufferSize > + (PcdMaximumAsciiStringLength * sizeof (CHAR8)), then ASSERT(). Also, the= output buffer + is unmodified and 0 is returned. If PcdMaximumUnicodeStringLength is not zero, and FormatString contains = more than PcdMaximumUnicodeStringLength Unicode characters not including the Null-= terminator, then - ASSERT(). - If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated= ASCII string - contains more than PcdMaximumAsciiStringLength ASCII characters not incl= uding the - Null-terminator, then ASSERT(). + ASSERT(). Also, the output buffer is unmodified and 0 is returned. =20 - @param StartOfBuffer A pointer to the output buffer for the produced = Null-terminated=20 + If BufferSize is 0, then no output buffer is produced and 0 is returned. + + @param StartOfBuffer A pointer to the output buffer for the produced = Null-terminated ASCII string. @param BufferSize The size, in bytes, of the output buffer specifi= ed by StartOfBuffer. - @param FormatString Null-terminated Unicode format string. - @param ... Variable argument list whose contents are access= ed based on the=20 + @param FormatString A Null-terminated Unicode format string. + @param ... Variable argument list whose contents are access= ed based on the format string specified by FormatString. =20 @return The number of ASCII characters in the produced output buffer not= including the @@ -1254,6 +1347,56 @@ InternalPrintLibSPrintMarker ( // DxePrintLibPrint2Protocol (both PrintLib instances). // =20 + // + // 1. Buffer shall not be a null pointer when both BufferSize > 0 and + // COUNT_ONLY_NO_PRINT is not set in Flags. + // + if ((BufferSize > 0) && ((Flags & COUNT_ONLY_NO_PRINT) =3D=3D 0)) { + SAFE_PRINT_CONSTRAINT_CHECK ((Buffer !=3D NULL), 0); + } + + // + // 2. Format shall not be a null pointer when BufferSize > 0 or when + // COUNT_ONLY_NO_PRINT is set in Flags. + // + if ((BufferSize > 0) || ((Flags & COUNT_ONLY_NO_PRINT) !=3D 0)) { + SAFE_PRINT_CONSTRAINT_CHECK ((Format !=3D NULL), 0); + } + + // + // 3. BufferSize shall not be greater than RSIZE_MAX for Unicode output = or + // ASCII_RSIZE_MAX for Ascii output. + // + if ((Flags & OUTPUT_UNICODE) !=3D 0) { + if (RSIZE_MAX !=3D 0) { + SAFE_PRINT_CONSTRAINT_CHECK ((BufferSize <=3D RSIZE_MAX), 0); + } + BytesPerOutputCharacter =3D 2; + } else { + if (ASCII_RSIZE_MAX !=3D 0) { + SAFE_PRINT_CONSTRAINT_CHECK ((BufferSize <=3D ASCII_RSIZE_MAX), 0); + } + BytesPerOutputCharacter =3D 1; + } + + // + // 4. Format shall not contain more than RSIZE_MAX Unicode characters or + // ASCII_RSIZE_MAX Ascii characters. + // + if ((Flags & FORMAT_UNICODE) !=3D 0) { + if (RSIZE_MAX !=3D 0) { + SAFE_PRINT_CONSTRAINT_CHECK ((StrnLenS ((CHAR16 *)Format, RSIZE_MAX = + 1) <=3D RSIZE_MAX), 0); + } + BytesPerFormatCharacter =3D 2; + FormatMask =3D 0xffff; + } else { + if (ASCII_RSIZE_MAX !=3D 0) { + SAFE_PRINT_CONSTRAINT_CHECK ((AsciiStrnLenS (Format, ASCII_RSIZE_MAX= + 1) <=3D ASCII_RSIZE_MAX), 0); + } + BytesPerFormatCharacter =3D 1; + FormatMask =3D 0xff; + } + if ((Flags & COUNT_ONLY_NO_PRINT) !=3D 0) { if (BufferSize =3D=3D 0) { Buffer =3D NULL; @@ -1265,13 +1408,6 @@ InternalPrintLibSPrintMarker ( if (BufferSize =3D=3D 0) { return 0; } - ASSERT (Buffer !=3D NULL); - } - - if ((Flags & OUTPUT_UNICODE) !=3D 0) { - BytesPerOutputCharacter =3D 2; - } else { - BytesPerOutputCharacter =3D 1; } =20 LengthToReturn =3D 0; @@ -1291,24 +1427,6 @@ InternalPrintLibSPrintMarker ( EndBuffer =3D Buffer + BufferSize * BytesPerOutputCharacter; } =20 - if ((Flags & FORMAT_UNICODE) !=3D 0) { - // - // Make sure format string cannot contain more than PcdMaximumUnicodeS= tringLength - // Unicode characters if PcdMaximumUnicodeStringLength is not zero.=20 - // - ASSERT (StrSize ((CHAR16 *) Format) !=3D 0); - BytesPerFormatCharacter =3D 2; - FormatMask =3D 0xffff; - } else { - // - // Make sure format string cannot contain more than PcdMaximumAsciiStr= ingLength - // Ascii characters if PcdMaximumAsciiStringLength is not zero.=20 - // - ASSERT (AsciiStrSize (Format) !=3D 0); - BytesPerFormatCharacter =3D 1; - FormatMask =3D 0xff; - } - // // Get the first character from the format string // @@ -1877,16 +1995,6 @@ InternalPrintLibSPrintMarker ( // Null terminate the Unicode or ASCII string // InternalPrintLibFillBuffer (Buffer, EndBuffer + BytesPerOutputCharacter,= 1, 0, BytesPerOutputCharacter); - // - // Make sure output buffer cannot contain more than PcdMaximumUnicodeStr= ingLength - // Unicode characters if PcdMaximumUnicodeStringLength is not zero.=20 - // - ASSERT ((((Flags & OUTPUT_UNICODE) =3D=3D 0)) || (StrSize ((CHAR16 *) Or= iginalBuffer) !=3D 0)); - // - // Make sure output buffer cannot contain more than PcdMaximumAsciiStrin= gLength - // ASCII characters if PcdMaximumAsciiStringLength is not zero.=20 - // - ASSERT ((((Flags & OUTPUT_UNICODE) !=3D 0)) || (AsciiStrSize (OriginalBu= ffer) !=3D 0)); =20 return ((Buffer - OriginalBuffer) / BytesPerOutputCharacter); } @@ -1895,9 +2003,13 @@ InternalPrintLibSPrintMarker ( Returns the number of characters that would be produced by if the format= ted=20 output were produced not including the Null-terminator. =20 - If FormatString is NULL, then ASSERT(). If FormatString is not aligned on a 16-bit boundary, then ASSERT(). =20 + If FormatString is NULL, then ASSERT() and 0 is returned. + If PcdMaximumUnicodeStringLength is not zero, and FormatString contains = more + than PcdMaximumUnicodeStringLength Unicode characters not including the + Null-terminator, then ASSERT() and 0 is returned. + @param[in] FormatString A Null-terminated Unicode format string. @param[in] Marker VA_LIST marker for the variable argument lis= t. =20 @@ -1911,7 +2023,7 @@ SPrintLength ( IN VA_LIST Marker ) { - ASSERT(FormatString !=3D NULL); + ASSERT_UNICODE_BUFFER (FormatString); return InternalPrintLibSPrintMarker (NULL, 0, FORMAT_UNICODE | OUTPUT_UN= ICODE | COUNT_ONLY_NO_PRINT, (CHAR8 *)FormatString, Marker, NULL); } =20 @@ -1919,7 +2031,10 @@ SPrintLength ( Returns the number of characters that would be produced by if the format= ted=20 output were produced not including the Null-terminator. =20 - If FormatString is NULL, then ASSERT(). + If FormatString is NULL, then ASSERT() and 0 is returned. + If PcdMaximumAsciiStringLength is not zero, and FormatString contains mo= re + than PcdMaximumAsciiStringLength Ascii characters not including the + Null-terminator, then ASSERT() and 0 is returned. =20 @param[in] FormatString A Null-terminated ASCII format string. @param[in] Marker VA_LIST marker for the variable argument lis= t. @@ -1934,6 +2049,5 @@ SPrintLengthAsciiFormat ( IN VA_LIST Marker ) { - ASSERT(FormatString !=3D NULL); return InternalPrintLibSPrintMarker (NULL, 0, OUTPUT_UNICODE | COUNT_ONL= Y_NO_PRINT, (CHAR8 *)FormatString, Marker, NULL); } --=20 1.9.5.msysgit.0 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Thu May 2 10:59:27 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zoho.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 148661118301129.064953758840147; Wed, 8 Feb 2017 19:33:03 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id C393C82134; Wed, 8 Feb 2017 19:32:59 -0800 (PST) Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id CC68882134 for ; Wed, 8 Feb 2017 19:32:58 -0800 (PST) Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga104.jf.intel.com with ESMTP; 08 Feb 2017 19:32:58 -0800 Received: from shwdeopenpsi014.ccr.corp.intel.com ([10.239.9.13]) by orsmga004.jf.intel.com with ESMTP; 08 Feb 2017 19:32:57 -0800 X-Original-To: edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.35,349,1484035200"; d="scan'208";a="56777749" From: Hao Wu To: edk2-devel@lists.01.org Date: Thu, 9 Feb 2017 11:32:41 +0800 Message-Id: <1486611161-37308-4-git-send-email-hao.a.wu@intel.com> X-Mailer: git-send-email 1.9.5.msysgit.0 In-Reply-To: <1486611161-37308-1-git-send-email-hao.a.wu@intel.com> References: <1486611161-37308-1-git-send-email-hao.a.wu@intel.com> Subject: [edk2] [PATCH v2 3/3] MdeModulePkg: Refine the services comments in EFI_PRINT2_PROTOCOL X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Hao Wu , Michael Kinney , Jiewen Yao , Liming Gao MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" For the following 8 services in EFI_PRINT2_PROTOCOL: UNICODE_BS_PRINT UNICODE_S_PRINT UNICODE_BS_PRINT_ASCII_FORMAT UNICODE_S_PRINT_ASCII_FORMAT ASCII_BS_PRINT ASCII_S_PRINT ASCII_BS_PRINT_UNICODE_FORMAT ASCII_S_PRINT_UNICODE_FORMAT They will ASSERT when: 1) The input parameter 'StartOfBuffer' is NULL if 'BufferSize' indicates at least 1 Ascii/Unicode character can be held. 2) The input parameter 'FormatString' is NULL if 'BufferSize' indicates at least 1 Ascii/Unicode character can be held. 3) The input parameter 'FormatString' contains more than PcdMaximum[Ascii|Unicode]StringLength Ascii/Unicode characters. 4) The produced string contains more than PcdMaximum[Ascii|Unicode]StringLength Ascii/Unicode characters. This commits removes the ASSERT case 4) and add the following new ASSERT case: 4) The input parameter 'BufferSize' is greater than (PcdMaximumAsciiStringLength * sizeof (CHAR8)) for Ascii format string or (PcdMaximumUnicodeStringLength * sizeof (CHAR16) + 1) for Unicode format string. And for those ASSERT cases, 0 will be returned by those services. Cc: Jiewen Yao Cc: Liming Gao Cc: Michael Kinney Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Hao Wu Reviewed-by: Liming Gao --- MdeModulePkg/Include/Protocol/Print2.h | 361 +++++++++++--------- 1 file changed, 205 insertions(+), 156 deletions(-) diff --git a/MdeModulePkg/Include/Protocol/Print2.h b/MdeModulePkg/Include/= Protocol/Print2.h index 1c127d5..8cad6fd 100644 --- a/MdeModulePkg/Include/Protocol/Print2.h +++ b/MdeModulePkg/Include/Protocol/Print2.h @@ -3,7 +3,7 @@ This print protocol defines six basic print functions to=20 print the format unicode and ascii string. =20 -Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.
+Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made availabl= e under=20 the terms and conditions of the BSD License that accompanies this distribu= tion. =20 The full text of the license may be found at @@ -26,35 +26,40 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITH= ER EXPRESS OR IMPLIED. typedef struct _EFI_PRINT2_PROTOCOL EFI_PRINT2_PROTOCOL; =20 /** - Produces a Null-terminated Unicode string in an output buffer, based on=20 - a Null-terminated Unicode format string and a BASE_LIST argument list - =20 - Produces a Null-terminated Unicode string in the output buffer=20 - specified by StartOfBuffer and BufferSize. =20 - The Unicode string is produced by parsing the format string specified by= FormatString. =20 - Arguments are pulled from the variable argument list specified by Marker. - Marker is constructed based on the contents of the format string. =20 - This function returns the number of Unicode characters in the produced o= utput buffer,=20 - not including the Null-terminator. - If BufferSize is 0 or 1, then no output buffer is produced and 0 is retu= rned. + Produces a Null-terminated Unicode string in an output buffer based on + a Null-terminated Unicode format string and a BASE_LIST argument list. + + Produces a Null-terminated Unicode string in the output buffer specified= by StartOfBuffer + and BufferSize. + The Unicode string is produced by parsing the format string specified by= FormatString. + Arguments are pulled from the variable argument list specified by Marker= based on the + contents of the format string. + The number of Unicode characters in the produced output buffer is return= ed not including + the Null-terminator. =20 - If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT(). - If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary,= then ASSERT(). - If BufferSize > 1 and FormatString is NULL, then ASSERT(). - If BufferSize > 1 and FormatString is not aligned on a 16-bit boundary, = then ASSERT(). - If PcdMaximumUnicodeStringLength is not zero, and FormatString contains = more than=20 - PcdMaximumUnicodeStringLength Unicode characters not including the Null-= terminator, then ASSERT(). - If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminat= ed Unicode string - contains more than PcdMaximumUnicodeStringLength Unicode characters not = including the - Null-terminator, then ASSERT(). - - @param StartOfBuffer A pointer to the output buffer for the produced = Null-terminated=20 + If StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT(). + If FormatString is not aligned on a 16-bit boundary, then ASSERT(). + + If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT(). Also, the ou= tput buffer is + unmodified and 0 is returned. + If BufferSize > 1 and FormatString is NULL, then ASSERT(). Also, the out= put buffer is + unmodified and 0 is returned. + If PcdMaximumUnicodeStringLength is not zero, and BufferSize > + (PcdMaximumUnicodeStringLength * sizeof (CHAR16) + 1), then ASSERT(). Al= so, the output + buffer is unmodified and 0 is returned. + If PcdMaximumUnicodeStringLength is not zero, and FormatString contains = more than + PcdMaximumUnicodeStringLength Unicode characters not including the Null-= terminator, then + ASSERT(). Also, the output buffer is unmodified and 0 is returned. + + If BufferSize is 0 or 1, then the output buffer is unmodified and 0 is r= eturned. + + @param StartOfBuffer A pointer to the output buffer for the produced = Null-terminated Unicode string. @param BufferSize The size, in bytes, of the output buffer specifi= ed by StartOfBuffer. - @param FormatString Null-terminated Unicode format string. + @param FormatString A Null-terminated Unicode format string. @param Marker BASE_LIST marker for the variable argument list. - =20 - @return The number of Unicode characters in the produced output buffer, = not including the + + @return The number of Unicode characters in the produced output buffer n= ot including the Null-terminator. =20 **/ @@ -68,34 +73,41 @@ UINTN ); =20 /** - Produces a Null-terminated Unicode string in an output buffer based on a= Null-terminated=20 + Produces a Null-terminated Unicode string in an output buffer based on a= Null-terminated Unicode format string and variable argument list. - =20 - Produces a Null-terminated Unicode string in the output buffer=20 - specified by StartOfBuffer and BufferSize. + + This function is similar as snprintf_s defined in C11. + + Produces a Null-terminated Unicode string in the output buffer specified= by StartOfBuffer + and BufferSize. The Unicode string is produced by parsing the format string specified by= FormatString. Arguments are pulled from the variable argument list based on the conten= ts of the format string. - This function returns the number of Unicode characters in the produced o= utput buffer,=20 - not including the Null-terminator. - If BufferSize is 0 or 1, then no output buffer is produced and 0 is retu= rned. + The number of Unicode characters in the produced output buffer is return= ed not including + the Null-terminator. + + If StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT(). + If FormatString is not aligned on a 16-bit boundary, then ASSERT(). + + If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT(). Also, the ou= tput buffer is + unmodified and 0 is returned. + If BufferSize > 1 and FormatString is NULL, then ASSERT(). Also, the out= put buffer is + unmodified and 0 is returned. + If PcdMaximumUnicodeStringLength is not zero, and BufferSize > + (PcdMaximumUnicodeStringLength * sizeof (CHAR16) + 1), then ASSERT(). Al= so, the output + buffer is unmodified and 0 is returned. + If PcdMaximumUnicodeStringLength is not zero, and FormatString contains = more than + PcdMaximumUnicodeStringLength Unicode characters not including the Null-= terminator, then + ASSERT(). Also, the output buffer is unmodified and 0 is returned. =20 - If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT(). - If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary,= then ASSERT(). - If BufferSize > 1 and FormatString is NULL, then ASSERT(). - If BufferSize > 1 and FormatString is not aligned on a 16-bit boundary, = then ASSERT(). - If PcdMaximumUnicodeStringLength is not zero, and FormatString contains = more than=20 - PcdMaximumUnicodeStringLength Unicode characters not including the Null-= terminator, then ASSERT(). - If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminat= ed Unicode string - contains more than PcdMaximumUnicodeStringLength Unicode characters not = including the - Null-terminator, then ASSERT(). - - @param StartOfBuffer A pointer to the output buffer for the produced = Null-terminated=20 + If BufferSize is 0 or 1, then the output buffer is unmodified and 0 is r= eturned. + + @param StartOfBuffer A pointer to the output buffer for the produced = Null-terminated Unicode string. @param BufferSize The size, in bytes, of the output buffer specifi= ed by StartOfBuffer. - @param FormatString Null-terminated Unicode format string. - @param ... Variable argument list whose contents are access= ed based on the=20 + @param FormatString A Null-terminated Unicode format string. + @param ... Variable argument list whose contents are access= ed based on the format string specified by FormatString. - =20 + @return The number of Unicode characters in the produced output buffer n= ot including the Null-terminator. =20 @@ -110,33 +122,38 @@ UINTN ); =20 /** - Produces a Null-terminated Unicode string in an output buffer, based on = a Null-terminated - ASCII format string and a BASE_LIST argument list - =20 - Produces a Null-terminated Unicode string in the output buffer=20 - specified by StartOfBuffer and BufferSize. + Produces a Null-terminated Unicode string in an output buffer based on a= Null-terminated + ASCII format string and a BASE_LIST argument list. + + Produces a Null-terminated Unicode string in the output buffer specified= by StartOfBuffer + and BufferSize. The Unicode string is produced by parsing the format string specified by= FormatString. - Arguments are pulled from the variable argument list specified by Marker= based on the=20 + Arguments are pulled from the variable argument list specified by Marker= based on the contents of the format string. - This function returns the number of Unicode characters in the produced o= utput buffer,=20 - not including the Null-terminator. - If BufferSize is 0 or 1, then no output buffer is produced and 0 is retu= rned. + The number of Unicode characters in the produced output buffer is return= ed not including + the Null-terminator. + + If StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT(). =20 - If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT(). - If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary,= then ASSERT(). - If BufferSize > 1 and FormatString is NULL, then ASSERT(). + If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT(). Also, the ou= tput buffer is + unmodified and 0 is returned. + If BufferSize > 1 and FormatString is NULL, then ASSERT(). Also, the out= put buffer is + unmodified and 0 is returned. + If PcdMaximumUnicodeStringLength is not zero, and BufferSize > + (PcdMaximumUnicodeStringLength * sizeof (CHAR16) + 1), then ASSERT(). Al= so, the output + buffer is unmodified and 0 is returned. If PcdMaximumAsciiStringLength is not zero, and FormatString contains mo= re than - PcdMaximumAsciiStringLength ASCII characters not including the Null-term= inator, then ASSERT(). - If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminat= ed Unicode string - contains more than PcdMaximumUnicodeStringLength Unicode characters not = including the - Null-terminator, then ASSERT(). + PcdMaximumAsciiStringLength Ascii characters not including the Null-term= inator, then + ASSERT(). Also, the output buffer is unmodified and 0 is returned. + + If BufferSize is 0 or 1, then no output buffer is produced and 0 is retu= rned. =20 - @param StartOfBuffer A pointer to the output buffer for the produced = Null-terminated=20 + @param StartOfBuffer A pointer to the output buffer for the produced = Null-terminated Unicode string. @param BufferSize The size, in bytes, of the output buffer specifi= ed by StartOfBuffer. - @param FormatString Null-terminated ASCII format string. + @param FormatString A Null-terminated ASCII format string. @param Marker BASE_LIST marker for the variable argument list. - =20 + @return The number of Unicode characters in the produced output buffer n= ot including the Null-terminator. =20 @@ -151,33 +168,41 @@ UINTN ); =20 /** - Produces a Null-terminated Unicode string in an output buffer based on a= Null-terminated=20 - ASCII format string and a variable argument list. - =20 - Produces a Null-terminated Unicode string in the output buffer=20 - specified by StartOfBuffer and BufferSize. + Produces a Null-terminated Unicode string in an output buffer based on a= Null-terminated + ASCII format string and variable argument list. + + This function is similar as snprintf_s defined in C11. + + Produces a Null-terminated Unicode string in the output buffer specified= by StartOfBuffer + and BufferSize. The Unicode string is produced by parsing the format string specified by= FormatString. - Arguments are pulled from the variable argument list based on the conten= ts of the format string. - This function returns the number of Unicode characters in the produced o= utput buffer,=20 - not including the Null-terminator. - If BufferSize is 0 or 1, then no output buffer is produced and 0 is retu= rned. + Arguments are pulled from the variable argument list based on the conten= ts of the + format string. + The number of Unicode characters in the produced output buffer is return= ed not including + the Null-terminator. =20 - If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT(). - If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary,= then ASSERT(). - If BufferSize > 1 and FormatString is NULL, then ASSERT(). + If StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT(). + + If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT(). Also, the ou= tput buffer is + unmodified and 0 is returned. + If BufferSize > 1 and FormatString is NULL, then ASSERT(). Also, the out= put buffer is + unmodified and 0 is returned. + If PcdMaximumUnicodeStringLength is not zero, and BufferSize > + (PcdMaximumUnicodeStringLength * sizeof (CHAR16) + 1), then ASSERT(). Al= so, the output + buffer is unmodified and 0 is returned. If PcdMaximumAsciiStringLength is not zero, and FormatString contains mo= re than - PcdMaximumAsciiStringLength ASCII characters not including the Null-term= inator, then ASSERT(). - If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminat= ed Unicode string - contains more than PcdMaximumUnicodeStringLength Unicode characters not = including the - Null-terminator, then ASSERT(). + PcdMaximumAsciiStringLength Ascii characters not including the Null-term= inator, then + ASSERT(). Also, the output buffer is unmodified and 0 is returned. =20 - @param StartOfBuffer A pointer to the output buffer for the produced = Null-terminated=20 + If BufferSize is 0 or 1, then no output buffer is produced and 0 is retu= rned. + + @param StartOfBuffer A pointer to the output buffer for the produced = Null-terminated Unicode string. @param BufferSize The size, in bytes, of the output buffer specifi= ed by StartOfBuffer. - @param FormatString Null-terminated ASCII format string. - @param ... Variable argument list whose contents are access= ed based on the=20 + @param FormatString A Null-terminated ASCII format string. + @param ... Variable argument list whose contents are access= ed based on the format string specified by FormatString. - =20 + @return The number of Unicode characters in the produced output buffer n= ot including the Null-terminator. =20 @@ -244,30 +269,34 @@ UINTN /** Produces a Null-terminated ASCII string in an output buffer based on a N= ull-terminated ASCII format string and a BASE_LIST argument list. - =20 - Produces a Null-terminated ASCII string in the output buffer=20 - pecified by StartOfBuffer and BufferSize. + + Produces a Null-terminated ASCII string in the output buffer specified b= y StartOfBuffer + and BufferSize. The ASCII string is produced by parsing the format string specified by F= ormatString. - Arguments are pulled from the variable argument list specified by Marker= based on=20 + Arguments are pulled from the variable argument list specified by Marker= based on the contents of the format string. - This function returns the number of ASCII characters in the output buffe= r,=20 - not including the Null-terminator. - If BufferSize is 0, then no output buffer is produced and 0 is returned. + The number of ASCII characters in the produced output buffer is returned= not including + the Null-terminator. =20 - If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT(). - If BufferSize > 0 and FormatString is NULL, then ASSERT(). + If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT(). Also, the ou= tput buffer is + unmodified and 0 is returned. + If BufferSize > 0 and FormatString is NULL, then ASSERT(). Also, the out= put buffer is + unmodified and 0 is returned. + If PcdMaximumAsciiStringLength is not zero, and BufferSize > + (PcdMaximumAsciiStringLength * sizeof (CHAR8)), then ASSERT(). Also, the= output buffer + is unmodified and 0 is returned. If PcdMaximumAsciiStringLength is not zero, and FormatString contains mo= re than - PcdMaximumAsciiStringLength ASCII characters not including the Null-term= inator, then ASSERT(). - If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated= ASCII string - contains more than PcdMaximumAsciiStringLength ASCII characters not incl= uding the - Null-terminator, then ASSERT(). + PcdMaximumAsciiStringLength Ascii characters not including the Null-term= inator, then + ASSERT(). Also, the output buffer is unmodified and 0 is returned. + + If BufferSize is 0, then no output buffer is produced and 0 is returned. =20 - @param StartOfBuffer A pointer to the output buffer for the produced = Null-terminated=20 + @param StartOfBuffer A pointer to the output buffer for the produced = Null-terminated ASCII string. @param BufferSize The size, in bytes, of the output buffer specifi= ed by StartOfBuffer. - @param FormatString Null-terminated ASCII format string. + @param FormatString A Null-terminated ASCII format string. @param Marker BASE_LIST marker for the variable argument list. - =20 + @return The number of ASCII characters in the produced output buffer not= including the Null-terminator. =20 @@ -283,31 +312,38 @@ UINTN =20 /** Produces a Null-terminated ASCII string in an output buffer based on a N= ull-terminated - ASCII format string and variable argument list. - =20 - Produces a Null-terminated ASCII string in the output buffer=20 - specified by StartOfBuffer and BufferSize. + ASCII format string and variable argument list. + + This function is similar as snprintf_s defined in C11. + + Produces a Null-terminated ASCII string in the output buffer specified b= y StartOfBuffer + and BufferSize. The ASCII string is produced by parsing the format string specified by F= ormatString. - Arguments are pulled from the variable argument list based on the conten= ts of the format string. - This function returns the number of ASCII characters in the output buffe= r,=20 - not including the Null-terminator. - If BufferSize is 0, then no output buffer is produced and 0 is returned. + Arguments are pulled from the variable argument list based on the conten= ts of the + format string. + The number of ASCII characters in the produced output buffer is returned= not including + the Null-terminator. =20 - If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT(). - If BufferSize > 0 and FormatString is NULL, then ASSERT(). + If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT(). Also, the ou= tput buffer is + unmodified and 0 is returned. + If BufferSize > 0 and FormatString is NULL, then ASSERT(). Also, the out= put buffer is + unmodified and 0 is returned. + If PcdMaximumAsciiStringLength is not zero, and BufferSize > + (PcdMaximumAsciiStringLength * sizeof (CHAR8)), then ASSERT(). Also, the= output buffer + is unmodified and 0 is returned. If PcdMaximumAsciiStringLength is not zero, and FormatString contains mo= re than - PcdMaximumAsciiStringLength ASCII characters not including the Null-term= inator, then ASSERT(). - If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated= ASCII string - contains more than PcdMaximumAsciiStringLength ASCII characters not incl= uding the - Null-terminator, then ASSERT(). + PcdMaximumAsciiStringLength Ascii characters not including the Null-term= inator, then + ASSERT(). Also, the output buffer is unmodified and 0 is returned. + + If BufferSize is 0, then no output buffer is produced and 0 is returned. =20 - @param StartOfBuffer A pointer to the output buffer for the produced = Null-terminated=20 + @param StartOfBuffer A pointer to the output buffer for the produced = Null-terminated ASCII string. @param BufferSize The size, in bytes, of the output buffer specifi= ed by StartOfBuffer. - @param FormatString Null-terminated ASCII format string. - @param ... Variable argument list whose contents are access= ed based on the=20 + @param FormatString A Null-terminated ASCII format string. + @param ... Variable argument list whose contents are access= ed based on the format string specified by FormatString. - =20 + @return The number of ASCII characters in the produced output buffer not= including the Null-terminator. =20 @@ -324,31 +360,36 @@ UINTN /** Produces a Null-terminated ASCII string in an output buffer based on a N= ull-terminated Unicode format string and a BASE_LIST argument list. - =20 - Produces a Null-terminated ASCII string in the output buffer=20 - specified by StartOfBuffer and BufferSize. + + Produces a Null-terminated ASCII string in the output buffer specified b= y StartOfBuffer + and BufferSize. The ASCII string is produced by parsing the format string specified by F= ormatString. - Arguments are pulled from the variable argument list specified by Marker= based on=20 + Arguments are pulled from the variable argument list specified by Marker= based on the contents of the format string. - This function returns the number of ASCII characters in the output buffe= r,=20 - not including the Null-terminator. - If BufferSize is 0, then no output buffer is produced and 0 is returned. + The number of ASCII characters in the produced output buffer is returned= not including + the Null-terminator. =20 - If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT(). - If BufferSize > 0 and FormatString is NULL, then ASSERT(). - If BufferSize > 0 and FormatString is not aligned on a 16-bit boundary, = then ASSERT(). + If FormatString is not aligned on a 16-bit boundary, then ASSERT(). + + If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT(). Also, the ou= tput buffer is + unmodified and 0 is returned. + If BufferSize > 0 and FormatString is NULL, then ASSERT(). Also, the out= put buffer is + unmodified and 0 is returned. + If PcdMaximumAsciiStringLength is not zero, and BufferSize > + (PcdMaximumAsciiStringLength * sizeof (CHAR8)), then ASSERT(). Also, the= output buffer + is unmodified and 0 is returned. If PcdMaximumUnicodeStringLength is not zero, and FormatString contains = more than - PcdMaximumUnicodeStringLength Unicode characters not including the Null-= terminator, then ASSERT(). - If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated= ASCII string - contains more than PcdMaximumAsciiStringLength ASCII characters not incl= uding the - Null-terminator, then ASSERT(). + PcdMaximumUnicodeStringLength Unicode characters not including the Null-= terminator, then + ASSERT(). Also, the output buffer is unmodified and 0 is returned. + + If BufferSize is 0, then no output buffer is produced and 0 is returned. =20 - @param StartOfBuffer A pointer to the output buffer for the produced = Null-terminated=20 + @param StartOfBuffer A pointer to the output buffer for the produced = Null-terminated ASCII string. @param BufferSize The size, in bytes, of the output buffer specifi= ed by StartOfBuffer. - @param FormatString Null-terminated Unicode format string. + @param FormatString A Null-terminated Unicode format string. @param Marker BASE_LIST marker for the variable argument list. - =20 + @return The number of ASCII characters in the produced output buffer not= including the Null-terminator. =20 @@ -365,31 +406,39 @@ UINTN /** Produces a Null-terminated ASCII string in an output buffer based on a N= ull-terminated Unicode format string and variable argument list. - =20 - Produces a Null-terminated ASCII string in the output buffer=20 - specified by StartOfBuffer and BufferSize. + + This function is similar as snprintf_s defined in C11. + + Produces a Null-terminated ASCII string in the output buffer specified b= y StartOfBuffer + and BufferSize. The ASCII string is produced by parsing the format string specified by F= ormatString. - Arguments are pulled from the variable argument list based on the conten= ts of the format string. - This function returns the number of ASCII characters in the output buffe= r,=20 - not including the Null-terminator. - If BufferSize is 0, then no output buffer is produced and 0 is returned. + Arguments are pulled from the variable argument list based on the conten= ts of the + format string. + The number of ASCII characters in the produced output buffer is returned= not including + the Null-terminator. + + If FormatString is not aligned on a 16-bit boundary, then ASSERT(). =20 - If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT(). - If BufferSize > 0 and FormatString is NULL, then ASSERT(). - If BufferSize > 0 and FormatString is not aligned on a 16-bit boundary, = then ASSERT(). - If PcdMaximumUnicodeStringLength is not zero, and FormatString contains = more than=20 - PcdMaximumUnicodeStringLength Unicode characters not including the Null-= terminator, then ASSERT(). - If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated= ASCII string - contains more than PcdMaximumAsciiStringLength ASCII characters not incl= uding the - Null-terminator, then ASSERT(). + If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT(). Also, the ou= tput buffer is + unmodified and 0 is returned. + If BufferSize > 0 and FormatString is NULL, then ASSERT(). Also, the out= put buffer is + unmodified and 0 is returned. + If PcdMaximumAsciiStringLength is not zero, and BufferSize > + (PcdMaximumAsciiStringLength * sizeof (CHAR8)), then ASSERT(). Also, the= output buffer + is unmodified and 0 is returned. + If PcdMaximumUnicodeStringLength is not zero, and FormatString contains = more than + PcdMaximumUnicodeStringLength Unicode characters not including the Null-= terminator, then + ASSERT(). Also, the output buffer is unmodified and 0 is returned. + + If BufferSize is 0, then no output buffer is produced and 0 is returned. =20 - @param StartOfBuffer A pointer to the output buffer for the produced = Null-terminated=20 + @param StartOfBuffer A pointer to the output buffer for the produced = Null-terminated ASCII string. @param BufferSize The size, in bytes, of the output buffer specifi= ed by StartOfBuffer. - @param FormatString Null-terminated Unicode format string. - @param ... Variable argument list whose contents are access= ed based on the=20 + @param FormatString A Null-terminated Unicode format string. + @param ... Variable argument list whose contents are access= ed based on the format string specified by FormatString. - =20 + @return The number of ASCII characters in the produced output buffer not= including the Null-terminator. =20 --=20 1.9.5.msysgit.0 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel