From: Ard Biesheuvel <ard.biesheuvel@linaro.org>
To: edk2-devel@lists.01.org
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>,
Laszlo Ersek <lersek@redhat.com>,
Yonghong Zhu <yonghong.zhu@intel.com>,
Liming Gao <liming.gao@intel.com>,
Bob Feng <bob.c.feng@intel.com>,
Jaben Carsey <jaben.carsey@intel.com>
Subject: [PATCH v2 1/6] BaseTools/CommonLib: avoid using 'native' word size in IP address handling
Date: Fri, 30 Nov 2018 23:45:32 +0100 [thread overview]
Message-ID: <20181130224537.18936-2-ard.biesheuvel@linaro.org> (raw)
In-Reply-To: <20181130224537.18936-1-ard.biesheuvel@linaro.org>
In the context of the BaseTools, there is no such thing as a native word
size, given that the same set of tools may be used to build a firmware
image consisting of both 32-bit and 64-bit modules.
So update StrToIpv4Address() and StrToIpv6Address() to use UINT64
types instead of UINTN types when parsing strings.
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
BaseTools/Source/C/Common/CommonLib.c | 28 ++++++++++----------
1 file changed, 14 insertions(+), 14 deletions(-)
diff --git a/BaseTools/Source/C/Common/CommonLib.c b/BaseTools/Source/C/Common/CommonLib.c
index 618aadac781a..7c559bc3c222 100644
--- a/BaseTools/Source/C/Common/CommonLib.c
+++ b/BaseTools/Source/C/Common/CommonLib.c
@@ -1785,7 +1785,7 @@ StrToIpv4Address (
{
RETURN_STATUS Status;
UINTN AddressIndex;
- UINTN Uintn;
+ UINT64 Uint64;
EFI_IPv4_ADDRESS LocalAddress;
UINT8 LocalPrefixLength;
CHAR16 *Pointer;
@@ -1812,7 +1812,7 @@ StrToIpv4Address (
//
// Get D or P.
//
- Status = StrDecimalToUintnS ((CONST CHAR16 *) Pointer, &Pointer, &Uintn);
+ Status = StrDecimalToUint64S ((CONST CHAR16 *) Pointer, &Pointer, &Uint64);
if (RETURN_ERROR (Status)) {
return RETURN_UNSUPPORTED;
}
@@ -1820,18 +1820,18 @@ StrToIpv4Address (
//
// It's P.
//
- if (Uintn > 32) {
+ if (Uint64 > 32) {
return RETURN_UNSUPPORTED;
}
- LocalPrefixLength = (UINT8) Uintn;
+ LocalPrefixLength = (UINT8) Uint64;
} else {
//
// It's D.
//
- if (Uintn > MAX_UINT8) {
+ if (Uint64 > MAX_UINT8) {
return RETURN_UNSUPPORTED;
}
- LocalAddress.Addr[AddressIndex] = (UINT8) Uintn;
+ LocalAddress.Addr[AddressIndex] = (UINT8) Uint64;
AddressIndex++;
}
@@ -1888,7 +1888,7 @@ StrToIpv6Address (
{
RETURN_STATUS Status;
UINTN AddressIndex;
- UINTN Uintn;
+ UINT64 Uint64;
EFI_IPv6_ADDRESS LocalAddress;
UINT8 LocalPrefixLength;
CONST CHAR16 *Pointer;
@@ -1969,7 +1969,7 @@ StrToIpv6Address (
//
// Get X.
//
- Status = StrHexToUintnS (Pointer, &End, &Uintn);
+ Status = StrHexToUint64S (Pointer, &End, &Uint64);
if (RETURN_ERROR (Status) || End - Pointer > 4) {
//
// Number of hexadecimal digit characters is no more than 4.
@@ -1978,24 +1978,24 @@ StrToIpv6Address (
}
Pointer = End;
//
- // Uintn won't exceed MAX_UINT16 if number of hexadecimal digit characters is no more than 4.
+ // Uint64 won't exceed MAX_UINT16 if number of hexadecimal digit characters is no more than 4.
//
ASSERT (AddressIndex + 1 < ARRAY_SIZE (Address->Addr));
- LocalAddress.Addr[AddressIndex] = (UINT8) ((UINT16) Uintn >> 8);
- LocalAddress.Addr[AddressIndex + 1] = (UINT8) Uintn;
+ LocalAddress.Addr[AddressIndex] = (UINT8) ((UINT16) Uint64 >> 8);
+ LocalAddress.Addr[AddressIndex + 1] = (UINT8) Uint64;
AddressIndex += 2;
} else {
//
// Get P, then exit the loop.
//
- Status = StrDecimalToUintnS (Pointer, &End, &Uintn);
- if (RETURN_ERROR (Status) || End == Pointer || Uintn > 128) {
+ Status = StrDecimalToUint64S (Pointer, &End, &Uint64);
+ if (RETURN_ERROR (Status) || End == Pointer || Uint64 > 128) {
//
// Prefix length should not exceed 128.
//
return RETURN_UNSUPPORTED;
}
- LocalPrefixLength = (UINT8) Uintn;
+ LocalPrefixLength = (UINT8) Uint64;
Pointer = End;
break;
}
--
2.19.1
next prev parent reply other threads:[~2018-11-30 22:45 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 ` Ard Biesheuvel [this message]
2018-12-03 10:25 ` [PATCH v2 1/6] BaseTools/CommonLib: avoid using 'native' word size in IP address handling 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é
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=20181130224537.18936-2-ard.biesheuvel@linaro.org \
--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