summaryrefslogtreecommitdiff
path: root/BaseTools
diff options
context:
space:
mode:
authorArd Biesheuvel <ard.biesheuvel@linaro.org>2018-11-29 13:05:38 +0100
committerArd Biesheuvel <ard.biesheuvel@linaro.org>2018-12-05 09:04:54 +0100
commit98a9519f1c58188ee083cfc980f27e520c463723 (patch)
treefb0924f62ee4593f6aceb255e7a644ef7bec1e98 /BaseTools
parentc0b7379a31091f9640f7d6592222b286669ef510 (diff)
downloadedk2-98a9519f1c58188ee083cfc980f27e520c463723.zip
edk2-98a9519f1c58188ee083cfc980f27e520c463723.tar.gz
edk2-98a9519f1c58188ee083cfc980f27e520c463723.tar.bz2
BaseTools/CommonLib: get rid of 'native' type string parsing routines
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> Reviewed-by: Laszlo Ersek <lersek@redhat.com> Reviewed-by: Liming Gao <liming.gao@intel.com>
Diffstat (limited to 'BaseTools')
-rw-r--r--BaseTools/Source/C/Common/CommonLib.c174
-rw-r--r--BaseTools/Source/C/Common/CommonLib.h24
2 files changed, 5 insertions, 193 deletions
diff --git a/BaseTools/Source/C/Common/CommonLib.c b/BaseTools/Source/C/Common/CommonLib.c
index 4a28f63..42dfa82 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
@@ -1292,28 +1150,6 @@ StrHexToUint64 (
}
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
)
diff --git a/BaseTools/Source/C/Common/CommonLib.h b/BaseTools/Source/C/Common/CommonLib.h
index adec0ed..7f67a45 100644
--- a/BaseTools/Source/C/Common/CommonLib.h
+++ b/BaseTools/Source/C/Common/CommonLib.h
@@ -251,16 +251,6 @@ StrSize (
CONST CHAR16 *String
);
-UINTN
-StrHexToUintn (
- CONST CHAR16 *String
- );
-
-UINTN
-StrDecimalToUintn (
- CONST CHAR16 *String
- );
-
UINT64
StrHexToUint64 (
CONST CHAR16 *String
@@ -279,26 +269,12 @@ StrHexToUint64S (
);
RETURN_STATUS
-StrHexToUintnS (
- CONST CHAR16 *String,
- CHAR16 **EndPointer, OPTIONAL
- UINTN *Data
- );
-
-RETURN_STATUS
StrDecimalToUint64S (
CONST CHAR16 *String,
CHAR16 **EndPointer, OPTIONAL
UINT64 *Data
);
-RETURN_STATUS
-StrDecimalToUintnS (
- CONST CHAR16 *String,
- CHAR16 **EndPointer, OPTIONAL
- UINTN *Data
- );
-
VOID *
ReallocatePool (
UINTN OldSize,