From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) (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 03EBC817B2 for ; Sun, 8 Jan 2017 18:03:10 -0800 (PST) Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga103.fm.intel.com with ESMTP; 08 Jan 2017 18:03:10 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.33,338,1477983600"; d="scan'208";a="211068875" Received: from fmsmsx106.amr.corp.intel.com ([10.18.124.204]) by fmsmga004.fm.intel.com with ESMTP; 08 Jan 2017 18:03:10 -0800 Received: from fmsmsx157.amr.corp.intel.com (10.18.116.73) by FMSMSX106.amr.corp.intel.com (10.18.124.204) with Microsoft SMTP Server (TLS) id 14.3.248.2; Sun, 8 Jan 2017 18:03:10 -0800 Received: from shsmsx101.ccr.corp.intel.com (10.239.4.153) by FMSMSX157.amr.corp.intel.com (10.18.116.73) with Microsoft SMTP Server (TLS) id 14.3.248.2; Sun, 8 Jan 2017 18:03:09 -0800 Received: from shsmsx102.ccr.corp.intel.com ([169.254.2.88]) by SHSMSX101.ccr.corp.intel.com ([169.254.1.177]) with mapi id 14.03.0248.002; Mon, 9 Jan 2017 10:03:07 +0800 From: "Yao, Jiewen" To: "Wu, Hao A" , "edk2-devel@lists.01.org" CC: "Wu, Jiaxin" , "Gao, Liming" , "Kinney, Michael D" Thread-Topic: [PATCH 3/4] MdePkg/BaseLib: Enhance the return value for string to uint functions Thread-Index: AQHSZnz54SOqZGmYc0KR9xPxiwy6IKEvbAaA Date: Mon, 9 Jan 2017 02:03:06 +0000 Message-ID: <74D8A39837DF1E4DA445A8C0B3885C503A8DCE92@shsmsx102.ccr.corp.intel.com> References: <1483528957-28340-1-git-send-email-hao.a.wu@intel.com> <1483528957-28340-4-git-send-email-hao.a.wu@intel.com> In-Reply-To: <1483528957-28340-4-git-send-email-hao.a.wu@intel.com> Accept-Language: zh-CN, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [PATCH 3/4] MdePkg/BaseLib: Enhance the return value for string to uint 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: , X-List-Received-Date: Mon, 09 Jan 2017 02:03:11 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Jiewen.yao@Intel.com > -----Original Message----- > From: Wu, Hao A > Sent: Wednesday, January 4, 2017 7:23 PM > To: edk2-devel@lists.01.org > Cc: Wu, Hao A ; Yao, Jiewen ; W= u, > Jiaxin ; Gao, Liming ; Kinney, > Michael D > Subject: [PATCH 3/4] MdePkg/BaseLib: Enhance the return value for string = to uint > functions >=20 > For the following 8 APIs in MdePkg/BaseLib: > [Ascii]StrDecimalToUintn > [Ascii]StrDecimalToUint64 > [Ascii]StrHexToUintn > [Ascii]StrHexToUint64 >=20 > They will ASSERT for DEBUG build when the input string exceeds the range > of UINTN/UINT64. However, for RELEASE build, incorrect value will be > returned. >=20 > This commit refines those APIs to direcly call their enhanced counterpart= s > (with trailing 'S' in API names) so as to remove those exceed-range ASSER= T > checks and to make those APIs to return MAX_UINTN/MAX_UINT64 instead. >=20 > Cc: Jiewen Yao > Cc: Jiaxin Wu > Cc: Liming Gao > Cc: Michael Kinney > Contributed-under: TianoCore Contribution Agreement 1.0 > Signed-off-by: Hao Wu > --- > MdePkg/Include/Library/BaseLib.h | 16 +- > MdePkg/Library/BaseLib/String.c | 334 ++-------------------------------= ------ > 2 files changed, 25 insertions(+), 325 deletions(-) >=20 > diff --git a/MdePkg/Include/Library/BaseLib.h > b/MdePkg/Include/Library/BaseLib.h > index 52011ee..abea7b6 100644 > --- a/MdePkg/Include/Library/BaseLib.h > +++ b/MdePkg/Include/Library/BaseLib.h > @@ -1395,7 +1395,7 @@ StrStr ( > If String has no pad spaces or valid decimal digits, > then 0 is returned. > If the number represented by String overflows according > - to the range defined by UINTN, then ASSERT(). > + to the range defined by UINTN, then MAX_UINTN is returned. >=20 > If PcdMaximumUnicodeStringLength is not zero, and String contains > more than PcdMaximumUnicodeStringLength Unicode characters not > including > @@ -1435,7 +1435,7 @@ StrDecimalToUintn ( > If String has no pad spaces or valid decimal digits, > then 0 is returned. > If the number represented by String overflows according > - to the range defined by UINT64, then ASSERT(). > + to the range defined by UINT64, then MAX_UINT64 is returned. >=20 > If PcdMaximumUnicodeStringLength is not zero, and String contains > more than PcdMaximumUnicodeStringLength Unicode characters not > including > @@ -1477,7 +1477,7 @@ StrDecimalToUint64 ( > If String has no leading pad spaces, leading zeros or valid hexadecima= l digits, > then zero is returned. > If the number represented by String overflows according to the range > defined by > - UINTN, then ASSERT(). > + UINTN, then MAX_UINTN is returned. >=20 > If PcdMaximumUnicodeStringLength is not zero, and String contains more > than > PcdMaximumUnicodeStringLength Unicode characters not including the > Null-terminator, > @@ -1519,7 +1519,7 @@ StrHexToUintn ( > If String has no leading pad spaces, leading zeros or valid hexadecima= l digits, > then zero is returned. > If the number represented by String overflows according to the range > defined by > - UINT64, then ASSERT(). > + UINT64, then MAX_UINT64 is returned. >=20 > If PcdMaximumUnicodeStringLength is not zero, and String contains more > than > PcdMaximumUnicodeStringLength Unicode characters not including the > Null-terminator, > @@ -1997,7 +1997,7 @@ AsciiStrStr ( > If String has only pad spaces, then 0 is returned. > If String has no pad spaces or valid decimal digits, then 0 is returne= d. > If the number represented by String overflows according to the range > defined by > - UINTN, then ASSERT(). > + UINTN, then MAX_UINTN is returned. > If String is NULL, then ASSERT(). > If PcdMaximumAsciiStringLength is not zero, and String contains more t= han > PcdMaximumAsciiStringLength ASCII characters not including the > Null-terminator, > @@ -2034,7 +2034,7 @@ AsciiStrDecimalToUintn ( > If String has only pad spaces, then 0 is returned. > If String has no pad spaces or valid decimal digits, then 0 is returne= d. > If the number represented by String overflows according to the range > defined by > - UINT64, then ASSERT(). > + UINT64, then MAX_UINT64 is returned. > If String is NULL, then ASSERT(). > If PcdMaximumAsciiStringLength is not zero, and String contains more t= han > PcdMaximumAsciiStringLength ASCII characters not including the > Null-terminator, > @@ -2075,7 +2075,7 @@ AsciiStrDecimalToUint64 ( > 0 is returned. >=20 > If the number represented by String overflows according to the range > defined by UINTN, > - then ASSERT(). > + then MAX_UINTN is returned. > If String is NULL, then ASSERT(). > If PcdMaximumAsciiStringLength is not zero, > and String contains more than PcdMaximumAsciiStringLength ASCII charac= ters > not including > @@ -2116,7 +2116,7 @@ AsciiStrHexToUintn ( > 0 is returned. >=20 > If the number represented by String overflows according to the range > defined by UINT64, > - then ASSERT(). > + then MAX_UINT64 is returned. > If String is NULL, then ASSERT(). > If PcdMaximumAsciiStringLength is not zero, > and String contains more than PcdMaximumAsciiStringLength ASCII charac= ters > not including > diff --git a/MdePkg/Library/BaseLib/String.c b/MdePkg/Library/BaseLib/Str= ing.c > index fa96d1c..e84bf50 100644 > --- a/MdePkg/Library/BaseLib/String.c > +++ b/MdePkg/Library/BaseLib/String.c > @@ -1,7 +1,7 @@ > /** @file > Unicode and ASCII string primitives. >=20 > - Copyright (c) 2006 - 2016, 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 = BSD > License > which accompanies this distribution. The full text of the license may= be > found at > @@ -638,7 +638,7 @@ InternalIsHexaDecimalDigitCharacter ( > If String has no pad spaces or valid decimal digits, > then 0 is returned. > If the number represented by String overflows according > - to the range defined by UINTN, then ASSERT(). > + to the range defined by UINTN, then MAX_UINTN is returned. >=20 > If PcdMaximumUnicodeStringLength is not zero, and String contains > more than PcdMaximumUnicodeStringLength Unicode characters, not > including > @@ -656,40 +656,8 @@ StrDecimalToUintn ( > ) > { > UINTN Result; > - > - // > - // ASSERT String is less long than PcdMaximumUnicodeStringLength. > - // Length tests are performed inside StrLen(). > - // > - ASSERT (StrSize (String) !=3D 0); > - > - // > - // Ignore the pad spaces (space or tab) > - // > - while ((*String =3D=3D L' ') || (*String =3D=3D L'\t')) { > - String++; > - } > - > - // > - // Ignore leading Zeros after the spaces > - // > - while (*String =3D=3D L'0') { > - String++; > - } > - > - Result =3D 0; > - > - while (InternalIsDecimalDigitCharacter (*String)) { > - // > - // If the number represented by String overflows according > - // to the range defined by UINTN, then ASSERT(). > - // > - ASSERT (Result <=3D ((((UINTN) ~0) - (*String - L'0')) / 10)); >=20 > - Result =3D Result * 10 + (*String - L'0'); > - String++; > - } > - > + StrDecimalToUintnS (String, (CHAR16 **) NULL, &Result); > return Result; > } >=20 > @@ -717,7 +685,7 @@ StrDecimalToUintn ( > If String has no pad spaces or valid decimal digits, > then 0 is returned. > If the number represented by String overflows according > - to the range defined by UINT64, then ASSERT(). > + to the range defined by UINT64, then MAX_UINT64 is returned. >=20 > If PcdMaximumUnicodeStringLength is not zero, and String contains > more than PcdMaximumUnicodeStringLength Unicode characters, not > including > @@ -736,39 +704,7 @@ StrDecimalToUint64 ( > { > UINT64 Result; >=20 > - // > - // ASSERT String is less long than PcdMaximumUnicodeStringLength. > - // Length tests are performed inside StrLen(). > - // > - ASSERT (StrSize (String) !=3D 0); > - > - // > - // Ignore the pad spaces (space or tab) > - // > - while ((*String =3D=3D L' ') || (*String =3D=3D L'\t')) { > - String++; > - } > - > - // > - // Ignore leading Zeros after the spaces > - // > - while (*String =3D=3D L'0') { > - String++; > - } > - > - Result =3D 0; > - > - while (InternalIsDecimalDigitCharacter (*String)) { > - // > - // If the number represented by String overflows according > - // to the range defined by UINTN, then ASSERT(). > - // > - ASSERT (Result <=3D DivU64x32 (((UINT64) ~0) - (*String - L'0') , 10= )); > - > - Result =3D MultU64x32 (Result, 10) + (*String - L'0'); > - String++; > - } > - > + StrDecimalToUint64S (String, (CHAR16 **) NULL, &Result); > return Result; > } >=20 > @@ -796,7 +732,7 @@ StrDecimalToUint64 ( > If String has no leading pad spaces, leading zeros or valid hexadecima= l digits, > then zero is returned. > If the number represented by String overflows according to the range > defined by > - UINTN, then ASSERT(). > + UINTN, then MAX_UINTN is returned. >=20 > If PcdMaximumUnicodeStringLength is not zero, and String contains more > than > PcdMaximumUnicodeStringLength Unicode characters, not including the > Null-terminator, > @@ -815,49 +751,7 @@ StrHexToUintn ( > { > UINTN Result; >=20 > - // > - // ASSERT String is less long than PcdMaximumUnicodeStringLength. > - // Length tests are performed inside StrLen(). > - // > - ASSERT (StrSize (String) !=3D 0); > - > - // > - // Ignore the pad spaces (space or tab) > - // > - while ((*String =3D=3D L' ') || (*String =3D=3D L'\t')) { > - String++; > - } > - > - // > - // Ignore leading Zeros after the spaces > - // > - while (*String =3D=3D L'0') { > - String++; > - } > - > - if (InternalCharToUpper (*String) =3D=3D L'X') { > - if (*(String - 1) !=3D L'0') { > - return 0; > - } > - // > - // Skip the 'X' > - // > - String++; > - } > - > - Result =3D 0; > - > - while (InternalIsHexaDecimalDigitCharacter (*String)) { > - // > - // If the Hex Number represented by String overflows according > - // to the range defined by UINTN, then ASSERT(). > - // > - ASSERT (Result <=3D ((((UINTN) ~0) - InternalHexCharToUintn (*String= )) >> > 4)); > - > - Result =3D (Result << 4) + InternalHexCharToUintn (*String); > - String++; > - } > - > + StrHexToUintnS (String, (CHAR16 **) NULL, &Result); > return Result; > } >=20 > @@ -886,7 +780,7 @@ StrHexToUintn ( > If String has no leading pad spaces, leading zeros or valid hexadecima= l digits, > then zero is returned. > If the number represented by String overflows according to the range > defined by > - UINT64, then ASSERT(). > + UINT64, then MAX_UINT64 is returned. >=20 > If PcdMaximumUnicodeStringLength is not zero, and String contains more > than > PcdMaximumUnicodeStringLength Unicode characters, not including the > Null-terminator, > @@ -905,51 +799,7 @@ StrHexToUint64 ( > { > UINT64 Result; >=20 > - // > - // ASSERT String is less long than PcdMaximumUnicodeStringLength. > - // Length tests are performed inside StrLen(). > - // > - ASSERT (StrSize (String) !=3D 0); > - > - // > - // Ignore the pad spaces (space or tab) > - // > - while ((*String =3D=3D L' ') || (*String =3D=3D L'\t')) { > - String++; > - } > - > - // > - // Ignore leading Zeros after the spaces > - // > - while (*String =3D=3D L'0') { > - String++; > - } > - > - if (InternalCharToUpper (*String) =3D=3D L'X') { > - ASSERT (*(String - 1) =3D=3D L'0'); > - if (*(String - 1) !=3D L'0') { > - return 0; > - } > - // > - // Skip the 'X' > - // > - String++; > - } > - > - Result =3D 0; > - > - while (InternalIsHexaDecimalDigitCharacter (*String)) { > - // > - // If the Hex Number represented by String overflows according > - // to the range defined by UINTN, then ASSERT(). > - // > - ASSERT (Result <=3D RShiftU64 (((UINT64) ~0) - InternalHexCharToUint= n > (*String) , 4)); > - > - Result =3D LShiftU64 (Result, 4); > - Result =3D Result + InternalHexCharToUintn (*String); > - String++; > - } > - > + StrHexToUint64S (String, (CHAR16 **) NULL, &Result); > return Result; > } >=20 > @@ -1681,7 +1531,7 @@ AsciiStrStr ( > If String has only pad spaces, then 0 is returned. > If String has no pad spaces or valid decimal digits, then 0 is returne= d. > If the number represented by String overflows according to the range > defined by > - UINTN, then ASSERT(). > + UINTN, then MAX_UINTN is returned. > If String is NULL, then ASSERT(). > If PcdMaximumAsciiStringLength is not zero, and String contains more t= han > PcdMaximumAsciiStringLength ASCII characters not including the > Null-terminator, > @@ -1700,38 +1550,7 @@ AsciiStrDecimalToUintn ( > { > UINTN Result; >=20 > - // > - // ASSERT Strings is less long than PcdMaximumAsciiStringLength > - // > - ASSERT (AsciiStrSize (String) !=3D 0); > - > - // > - // Ignore the pad spaces (space or tab) > - // > - while ((*String =3D=3D ' ') || (*String =3D=3D '\t' )) { > - String++; > - } > - > - // > - // Ignore leading Zeros after the spaces > - // > - while (*String =3D=3D '0') { > - String++; > - } > - > - Result =3D 0; > - > - while (InternalAsciiIsDecimalDigitCharacter (*String)) { > - // > - // If the number represented by String overflows according > - // to the range defined by UINTN, then ASSERT(). > - // > - ASSERT (Result <=3D ((((UINTN) ~0) - (*String - L'0')) / 10)); > - > - Result =3D Result * 10 + (*String - '0'); > - String++; > - } > - > + AsciiStrDecimalToUintnS (String, (CHAR8 **) NULL, &Result); > return Result; > } >=20 > @@ -1755,7 +1574,7 @@ AsciiStrDecimalToUintn ( > If String has only pad spaces, then 0 is returned. > If String has no pad spaces or valid decimal digits, then 0 is returne= d. > If the number represented by String overflows according to the range > defined by > - UINT64, then ASSERT(). > + UINT64, then MAX_UINT64 is returned. > If String is NULL, then ASSERT(). > If PcdMaximumAsciiStringLength is not zero, and String contains more t= han > PcdMaximumAsciiStringLength ASCII characters not including the > Null-terminator, > @@ -1774,38 +1593,7 @@ AsciiStrDecimalToUint64 ( > { > UINT64 Result; >=20 > - // > - // ASSERT Strings is less long than PcdMaximumAsciiStringLength > - // > - ASSERT (AsciiStrSize (String) !=3D 0); > - > - // > - // Ignore the pad spaces (space or tab) > - // > - while ((*String =3D=3D ' ') || (*String =3D=3D '\t' )) { > - String++; > - } > - > - // > - // Ignore leading Zeros after the spaces > - // > - while (*String =3D=3D '0') { > - String++; > - } > - > - Result =3D 0; > - > - while (InternalAsciiIsDecimalDigitCharacter (*String)) { > - // > - // If the number represented by String overflows according > - // to the range defined by UINTN, then ASSERT(). > - // > - ASSERT (Result <=3D DivU64x32 (((UINT64) ~0) - (*String - L'0') , 10= )); > - > - Result =3D MultU64x32 (Result, 10) + (*String - '0'); > - String++; > - } > - > + AsciiStrDecimalToUint64S (String, (CHAR8 **) NULL, &Result); > return Result; > } >=20 > @@ -1832,7 +1620,7 @@ AsciiStrDecimalToUint64 ( > 0 is returned. >=20 > If the number represented by String overflows according to the range > defined by UINTN, > - then ASSERT(). > + then MAX_UINTN is returned. > If String is NULL, then ASSERT(). > If PcdMaximumAsciiStringLength is not zero, > and String contains more than PcdMaximumAsciiStringLength ASCII charac= ters > not including > @@ -1851,49 +1639,7 @@ AsciiStrHexToUintn ( > { > UINTN Result; >=20 > - // > - // ASSERT Strings is less long than PcdMaximumAsciiStringLength > - // > - ASSERT (AsciiStrSize (String) !=3D 0); > - > - // > - // Ignore the pad spaces (space or tab) > - // > - while ((*String =3D=3D ' ') || (*String =3D=3D '\t' )) { > - String++; > - } > - > - // > - // Ignore leading Zeros after the spaces > - // > - while (*String =3D=3D '0') { > - String++; > - } > - > - if (InternalBaseLibAsciiToUpper (*String) =3D=3D 'X') { > - ASSERT (*(String - 1) =3D=3D '0'); > - if (*(String - 1) !=3D '0') { > - return 0; > - } > - // > - // Skip the 'X' > - // > - String++; > - } > - > - Result =3D 0; > - > - while (InternalAsciiIsHexaDecimalDigitCharacter (*String)) { > - // > - // If the Hex Number represented by String overflows according > - // to the range defined by UINTN, then ASSERT(). > - // > - ASSERT (Result <=3D ((((UINTN) ~0) - InternalHexCharToUintn (*String= )) >> > 4)); > - > - Result =3D (Result << 4) + InternalAsciiHexCharToUintn (*String); > - String++; > - } > - > + AsciiStrHexToUintnS (String, (CHAR8 **) NULL, &Result); > return Result; > } >=20 > @@ -1921,7 +1667,7 @@ AsciiStrHexToUintn ( > 0 is returned. >=20 > If the number represented by String overflows according to the range > defined by UINT64, > - then ASSERT(). > + then MAX_UINT64 is returned. > If String is NULL, then ASSERT(). > If PcdMaximumAsciiStringLength is not zero, > and String contains more than PcdMaximumAsciiStringLength ASCII charac= ters > not including > @@ -1940,53 +1686,7 @@ AsciiStrHexToUint64 ( > { > UINT64 Result; >=20 > - // > - // ASSERT Strings is less long than PcdMaximumAsciiStringLength > - // > - ASSERT (AsciiStrSize (String) !=3D 0); > - > - // > - // Ignore the pad spaces (space or tab) and leading Zeros > - // > - // > - // Ignore the pad spaces (space or tab) > - // > - while ((*String =3D=3D ' ') || (*String =3D=3D '\t' )) { > - String++; > - } > - > - // > - // Ignore leading Zeros after the spaces > - // > - while (*String =3D=3D '0') { > - String++; > - } > - > - if (InternalBaseLibAsciiToUpper (*String) =3D=3D 'X') { > - ASSERT (*(String - 1) =3D=3D '0'); > - if (*(String - 1) !=3D '0') { > - return 0; > - } > - // > - // Skip the 'X' > - // > - String++; > - } > - > - Result =3D 0; > - > - while (InternalAsciiIsHexaDecimalDigitCharacter (*String)) { > - // > - // If the Hex Number represented by String overflows according > - // to the range defined by UINTN, then ASSERT(). > - // > - ASSERT (Result <=3D RShiftU64 (((UINT64) ~0) - InternalHexCharToUint= n > (*String) , 4)); > - > - Result =3D LShiftU64 (Result, 4); > - Result =3D Result + InternalAsciiHexCharToUintn (*String); > - String++; > - } > - > + AsciiStrHexToUint64S (String, (CHAR8 **) NULL, &Result); > return Result; > } >=20 > -- > 1.9.5.msysgit.0