public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@redhat.com>
To: Ard Biesheuvel <ard.biesheuvel@linaro.org>, edk2-devel@lists.01.org
Cc: Liming Gao <liming.gao@intel.com>,
	Jaben Carsey <jaben.carsey@intel.com>,
	 Laszlo Ersek <lersek@redhat.com>
Subject: Re: [PATCH v2 5/6] BaseTools/CommonLib: get rid of 'native' type string parsing routines
Date: Mon, 3 Dec 2018 11:27:15 +0100	[thread overview]
Message-ID: <6f60af92-ac59-0746-bdb3-8547dd38dd71@redhat.com> (raw)
In-Reply-To: <20181130224537.18936-6-ard.biesheuvel@linaro.org>

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 <ard.biesheuvel@linaro.org>

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>

> ---
>  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
> 


  reply	other threads:[~2018-12-03 10:27 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-30 22:45 [PATCH v2 0/6] BaseTools: get rid of MAX_UINTN Ard Biesheuvel
2018-11-30 22:45 ` [PATCH v2 1/6] BaseTools/CommonLib: avoid using 'native' word size in IP address handling Ard Biesheuvel
2018-12-03 10:25   ` Philippe Mathieu-Daudé
2018-12-03 12:50   ` Laszlo Ersek
2018-11-30 22:45 ` [PATCH v2 2/6] BaseTools/CommonLib: use explicit 64-bit type in Strtoi() Ard Biesheuvel
2018-12-03 10:25   ` Philippe Mathieu-Daudé
2018-12-03 12:52   ` Laszlo Ersek
2018-11-30 22:45 ` [PATCH v2 3/6] BaseTools/DevicePath: use explicit 64-bit number parsing routines Ard Biesheuvel
2018-12-03 10:25   ` Philippe Mathieu-Daudé
2018-12-03 12:55   ` Laszlo Ersek
2018-11-30 22:45 ` [PATCH v2 4/6] BaseTools/DevicePath: use MAX_UINT16 as default device path max size Ard Biesheuvel
2018-12-03 13:05   ` Laszlo Ersek
2018-12-05  0:04     ` Gao, Liming
2018-12-05  7:42       ` Ard Biesheuvel
2018-12-05  7:53         ` Gao, Liming
2018-11-30 22:45 ` [PATCH v2 5/6] BaseTools/CommonLib: get rid of 'native' type string parsing routines Ard Biesheuvel
2018-12-03 10:27   ` Philippe Mathieu-Daudé [this message]
2018-12-03 13:08   ` Laszlo Ersek
2018-11-30 22:45 ` [PATCH v2 6/6] BaseTools/CommonLib: drop definition of MAX_UINTN Ard Biesheuvel
2018-12-03 10:28   ` Philippe Mathieu-Daudé
2018-12-03 13:08   ` Laszlo Ersek
2018-12-11  7:11     ` David F.
2018-12-11 15:45       ` Laszlo Ersek
2018-12-11 22:53         ` David F.
2018-12-11 22:55           ` Ard Biesheuvel
2018-12-11 23:03             ` David F.
2018-12-05  0:04 ` [PATCH v2 0/6] BaseTools: get rid " Gao, Liming
2018-12-05  8:12   ` Ard Biesheuvel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6f60af92-ac59-0746-bdb3-8547dd38dd71@redhat.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox