From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=209.85.221.68; helo=mail-wr1-f68.google.com; envelope-from=philmd@redhat.com; receiver=edk2-devel@lists.01.org Received: from mail-wr1-f68.google.com (mail-wr1-f68.google.com [209.85.221.68]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 65DDB2007D1F0 for ; Mon, 3 Dec 2018 02:27:19 -0800 (PST) Received: by mail-wr1-f68.google.com with SMTP id j10so11516338wru.4 for ; Mon, 03 Dec 2018 02:27:19 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:openpgp:message-id :date:user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=9zc7ayQTCfKaIX4iF7RiBoK8lTyc4E1RG0hRltFt0SA=; b=FjvPACH36G8RhbQtcOM4+UI5beGsPdgxTXmYY/VxFLNy1q+wCJyyGfM9zugtuSLf8z lAPWxIiSo6pHkFH8EGoWbq0YY56h9USg8m8FYWNwBe6Au7S61iA0lyvbEnbBAan8rlQ/ ImUVZqzG3T8V02akSdM0LGRCmA9+NlsmrnXs7UbpBoAYEMRnGD6S2QFm11z7CHE/35q7 8us7ZJUFOhL/2Cf5aokQkEbntUCj3jR+4FlQNXpTTrXjLgThm905kh9k+rJHhnYBAnyP dEy0B2734v/0dGgWAKCYsv7ud1Z5XXzDAmZ5CtjwwdTYf0PBsPhgwN/3FhjH2wulDela T7dQ== X-Gm-Message-State: AA+aEWawkRHIELWq6w1nVZudWhRwmw51BxRWxIG+8fqAfC+W/45ymNMM 4Pc551yAwAkv8f4+fTRfdZ6+eQ== X-Google-Smtp-Source: AFSGD/UYiuHsG1ZEaADop5UZmON9iLho9ZVhK50eLlD1PIr8gcb9jQs4Nwp+bsfuhwfmlOAWTwP9Vg== X-Received: by 2002:adf:ffca:: with SMTP id x10mr14279927wrs.289.1543832837825; Mon, 03 Dec 2018 02:27:17 -0800 (PST) Received: from ?IPv6:2a01:cb1d:8a0a:f500:48c1:8eab:256a:caf9? ([2a01:cb1d:8a0a:f500:48c1:8eab:256a:caf9]) by smtp.gmail.com with ESMTPSA id j8sm8930242wmd.0.2018.12.03.02.27.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Dec 2018 02:27:16 -0800 (PST) To: Ard Biesheuvel , edk2-devel@lists.01.org Cc: Liming Gao , Jaben Carsey , Laszlo Ersek References: <20181130224537.18936-1-ard.biesheuvel@linaro.org> <20181130224537.18936-6-ard.biesheuvel@linaro.org> From: =?UTF-8?Q?Philippe_Mathieu-Daud=c3=a9?= Openpgp: id=89C1E78F601EE86C867495CBA2A3FD6EDEADC0DE; url=http://pgp.mit.edu/pks/lookup?op=get&search=0xA2A3FD6EDEADC0DE Message-ID: <6f60af92-ac59-0746-bdb3-8547dd38dd71@redhat.com> Date: Mon, 3 Dec 2018 11:27:15 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.1 MIME-Version: 1.0 In-Reply-To: <20181130224537.18936-6-ard.biesheuvel@linaro.org> Subject: Re: [PATCH v2 5/6] BaseTools/CommonLib: get rid of 'native' type string parsing routines X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 03 Dec 2018 10:27:19 -0000 Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit On 30/11/18 23:45, Ard Biesheuvel wrote: > Parsing a string into an integer variable of the native word size > is not defined for the BaseTools, since the same tools may be used > to build firmware for different targets with different native word > sizes. > > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Ard Biesheuvel Reviewed-by: Philippe Mathieu-Daudé > --- > BaseTools/Source/C/Common/CommonLib.h | 24 --- > BaseTools/Source/C/Common/CommonLib.c | 174 +------------------- > 2 files changed, 5 insertions(+), 193 deletions(-) > > diff --git a/BaseTools/Source/C/Common/CommonLib.h b/BaseTools/Source/C/Common/CommonLib.h > index fa10fac4682a..6930d9227b87 100644 > --- a/BaseTools/Source/C/Common/CommonLib.h > +++ b/BaseTools/Source/C/Common/CommonLib.h > @@ -250,16 +250,6 @@ StrSize ( > CONST CHAR16 *String > ); > > -UINTN > -StrHexToUintn ( > - CONST CHAR16 *String > - ); > - > -UINTN > -StrDecimalToUintn ( > - CONST CHAR16 *String > - ); > - > UINT64 > StrHexToUint64 ( > CONST CHAR16 *String > @@ -277,13 +267,6 @@ StrHexToUint64S ( > UINT64 *Data > ); > > -RETURN_STATUS > -StrHexToUintnS ( > - CONST CHAR16 *String, > - CHAR16 **EndPointer, OPTIONAL > - UINTN *Data > - ); > - > RETURN_STATUS > StrDecimalToUint64S ( > CONST CHAR16 *String, > @@ -291,13 +274,6 @@ StrDecimalToUint64S ( > UINT64 *Data > ); > > -RETURN_STATUS > -StrDecimalToUintnS ( > - CONST CHAR16 *String, > - CHAR16 **EndPointer, OPTIONAL > - UINTN *Data > - ); > - > VOID * > ReallocatePool ( > UINTN OldSize, > diff --git a/BaseTools/Source/C/Common/CommonLib.c b/BaseTools/Source/C/Common/CommonLib.c > index 4a28f635f3a8..42dfa821624d 100644 > --- a/BaseTools/Source/C/Common/CommonLib.c > +++ b/BaseTools/Source/C/Common/CommonLib.c > @@ -882,72 +882,6 @@ InternalSafeStringNoStrOverlap ( > return !InternalSafeStringIsOverlap (Str1, Size1 * sizeof(CHAR16), Str2, Size2 * sizeof(CHAR16)); > } > > -RETURN_STATUS > -StrDecimalToUintnS ( > - CONST CHAR16 *String, > - CHAR16 **EndPointer, OPTIONAL > - UINTN *Data > - ) > -{ > - ASSERT (((UINTN) String & BIT0) == 0); > - > - // > - // 1. Neither String nor Data shall be a null pointer. > - // > - SAFE_STRING_CONSTRAINT_CHECK ((String != NULL), RETURN_INVALID_PARAMETER); > - SAFE_STRING_CONSTRAINT_CHECK ((Data != NULL), RETURN_INVALID_PARAMETER); > - > - // > - // 2. The length of String shall not be greater than RSIZE_MAX. > - // > - if (RSIZE_MAX != 0) { > - SAFE_STRING_CONSTRAINT_CHECK ((StrnLenS (String, RSIZE_MAX + 1) <= RSIZE_MAX), RETURN_INVALID_PARAMETER); > - } > - > - if (EndPointer != NULL) { > - *EndPointer = (CHAR16 *) String; > - } > - > - // > - // Ignore the pad spaces (space or tab) > - // > - while ((*String == L' ') || (*String == L'\t')) { > - String++; > - } > - > - // > - // Ignore leading Zeros after the spaces > - // > - while (*String == L'0') { > - String++; > - } > - > - *Data = 0; > - > - while (InternalIsDecimalDigitCharacter (*String)) { > - // > - // If the number represented by String overflows according to the range > - // defined by UINTN, then MAX_UINTN is stored in *Data and > - // RETURN_UNSUPPORTED is returned. > - // > - if (*Data > ((MAX_UINTN - (*String - L'0')) / 10)) { > - *Data = MAX_UINTN; > - if (EndPointer != NULL) { > - *EndPointer = (CHAR16 *) String; > - } > - return RETURN_UNSUPPORTED; > - } > - > - *Data = *Data * 10 + (*String - L'0'); > - String++; > - } > - > - if (EndPointer != NULL) { > - *EndPointer = (CHAR16 *) String; > - } > - return RETURN_SUCCESS; > -} > - > /** > Convert a Null-terminated Unicode decimal string to a value of type UINT64. > > @@ -1064,9 +998,9 @@ StrDecimalToUint64S ( > > /** > Convert a Null-terminated Unicode hexadecimal string to a value of type > - UINTN. > + UINT64. > > - This function outputs a value of type UINTN by interpreting the contents of > + This function outputs a value of type UINT64 by interpreting the contents of > the Unicode string specified by String as a hexadecimal number. The format of > the input Unicode string String is: > > @@ -1091,8 +1025,8 @@ StrDecimalToUint64S ( > > If String has no valid hexadecimal digits in the above format, then 0 is > stored at the location pointed to by Data. > - If the number represented by String exceeds the range defined by UINTN, then > - MAX_UINTN is stored at the location pointed to by Data. > + If the number represented by String exceeds the range defined by UINT64, then > + MAX_UINT64 is stored at the location pointed to by Data. > > If EndPointer is not NULL, a pointer to the character that stopped the scan > is stored at the location pointed to by EndPointer. If String has no valid > @@ -1112,86 +1046,10 @@ StrDecimalToUint64S ( > characters, not including the > Null-terminator. > @retval RETURN_UNSUPPORTED If the number represented by String exceeds > - the range defined by UINTN. > + the range defined by UINT64. > > **/ > RETURN_STATUS > -StrHexToUintnS ( > - CONST CHAR16 *String, > - CHAR16 **EndPointer, OPTIONAL > - UINTN *Data > - ) > -{ > - ASSERT (((UINTN) String & BIT0) == 0); > - > - // > - // 1. Neither String nor Data shall be a null pointer. > - // > - SAFE_STRING_CONSTRAINT_CHECK ((String != NULL), RETURN_INVALID_PARAMETER); > - SAFE_STRING_CONSTRAINT_CHECK ((Data != NULL), RETURN_INVALID_PARAMETER); > - > - // > - // 2. The length of String shall not be greater than RSIZE_MAX. > - // > - if (RSIZE_MAX != 0) { > - SAFE_STRING_CONSTRAINT_CHECK ((StrnLenS (String, RSIZE_MAX + 1) <= RSIZE_MAX), RETURN_INVALID_PARAMETER); > - } > - > - if (EndPointer != NULL) { > - *EndPointer = (CHAR16 *) String; > - } > - > - // > - // Ignore the pad spaces (space or tab) > - // > - while ((*String == L' ') || (*String == L'\t')) { > - String++; > - } > - > - // > - // Ignore leading Zeros after the spaces > - // > - while (*String == L'0') { > - String++; > - } > - > - if (InternalCharToUpper (*String) == L'X') { > - if (*(String - 1) != L'0') { > - *Data = 0; > - return RETURN_SUCCESS; > - } > - // > - // Skip the 'X' > - // > - String++; > - } > - > - *Data = 0; > - > - while (InternalIsHexaDecimalDigitCharacter (*String)) { > - // > - // If the number represented by String overflows according to the range > - // defined by UINTN, then MAX_UINTN is stored in *Data and > - // RETURN_UNSUPPORTED is returned. > - // > - if (*Data > ((MAX_UINTN - InternalHexCharToUintn (*String)) >> 4)) { > - *Data = MAX_UINTN; > - if (EndPointer != NULL) { > - *EndPointer = (CHAR16 *) String; > - } > - return RETURN_UNSUPPORTED; > - } > - > - *Data = (*Data << 4) + InternalHexCharToUintn (*String); > - String++; > - } > - > - if (EndPointer != NULL) { > - *EndPointer = (CHAR16 *) String; > - } > - return RETURN_SUCCESS; > -} > -RETURN_STATUS > StrHexToUint64S ( > CONST CHAR16 *String, > CHAR16 **EndPointer, OPTIONAL > @@ -1291,28 +1149,6 @@ StrHexToUint64 ( > return Result; > } > > -UINTN > -StrDecimalToUintn ( > - CONST CHAR16 *String > - ) > -{ > - UINTN Result; > - > - StrDecimalToUintnS (String, (CHAR16 **) NULL, &Result); > - return Result; > -} > - > -UINTN > -StrHexToUintn ( > - CONST CHAR16 *String > - ) > -{ > - UINTN Result; > - > - StrHexToUintnS (String, (CHAR16 **) NULL, &Result); > - return Result; > -} > - > UINTN > StrSize ( > CONST CHAR16 *String >