diff mbox series

[edk2,1/6] BaseTools/CommonLib: avoid using 'native' word size in IP address handling

Message ID 20181129123129.25095-2-ard.biesheuvel@linaro.org
State Superseded
Headers show
Series BaseTools: get rid of MAX_UINTN | expand

Commit Message

Ard Biesheuvel Nov. 29, 2018, 12:31 p.m. UTC
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(-)

-- 
2.19.1

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel

Comments

Gao, Liming Nov. 29, 2018, 3:11 p.m. UTC | #1
Ard:
  I mean the build error. Besides, what test have you done with this patch set?

CommonLib.c(1651): error C2220: warning treated as error - no 'object' file generated
CommonLib.c(1651): warning C4133: 'function': incompatible types - from 'UINTN *' to 'UINT64 *'
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\cl.exe"' : return code '0x2'

Below > +  UINTN                  Uint64; ==> > +  UINT64                  Uint64;
> -----Original Message-----

> From: Ard Biesheuvel [mailto:ard.biesheuvel@linaro.org]

> Sent: Thursday, November 29, 2018 8:31 PM

> To: edk2-devel@lists.01.org

> Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>; Laszlo Ersek <lersek@redhat.com>; Zhu, Yonghong <yonghong.zhu@intel.com>; Gao,

> Liming <liming.gao@intel.com>; Feng, Bob C <bob.c.feng@intel.com>

> Subject: [PATCH 1/6] BaseTools/CommonLib: avoid using 'native' word size in IP address handling

> 

> 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..bea6af0a45b1 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;

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


_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
Ard Biesheuvel Nov. 29, 2018, 3:13 p.m. UTC | #2
On Thu, 29 Nov 2018 at 16:11, Gao, Liming <liming.gao@intel.com> wrote:
>

> Ard:

>   I mean the build error. Besides, what test have you done with this patch set?

>

> CommonLib.c(1651): error C2220: warning treated as error - no 'object' file generated

> CommonLib.c(1651): warning C4133: 'function': incompatible types - from 'UINTN *' to 'UINT64 *'

> NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\cl.exe"' : return code '0x2'

>


Apologies, i missed this change at line 1624

-  UINTN                  Uint64;
+  UINT64                 Uint64;

It builds fine with GCC though.

> Below > +  UINTN                  Uint64; ==> > +  UINT64                  Uint64;

> > -----Original Message-----

> > From: Ard Biesheuvel [mailto:ard.biesheuvel@linaro.org]

> > Sent: Thursday, November 29, 2018 8:31 PM

> > To: edk2-devel@lists.01.org

> > Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>; Laszlo Ersek <lersek@redhat.com>; Zhu, Yonghong <yonghong.zhu@intel.com>; Gao,

> > Liming <liming.gao@intel.com>; Feng, Bob C <bob.c.feng@intel.com>

> > Subject: [PATCH 1/6] BaseTools/CommonLib: avoid using 'native' word size in IP address handling

> >

> > 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..bea6af0a45b1 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;

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

>

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
Gao, Liming Nov. 29, 2018, 3:15 p.m. UTC | #3
Do you verify which GCC arch? 32bit or 64bit or ARM?

> -----Original Message-----

> From: Ard Biesheuvel [mailto:ard.biesheuvel@linaro.org]

> Sent: Thursday, November 29, 2018 11:14 PM

> To: Gao, Liming <liming.gao@intel.com>

> Cc: edk2-devel@lists.01.org; Laszlo Ersek <lersek@redhat.com>; Zhu, Yonghong <yonghong.zhu@intel.com>; Feng, Bob C

> <bob.c.feng@intel.com>

> Subject: Re: [PATCH 1/6] BaseTools/CommonLib: avoid using 'native' word size in IP address handling

> 

> On Thu, 29 Nov 2018 at 16:11, Gao, Liming <liming.gao@intel.com> wrote:

> >

> > Ard:

> >   I mean the build error. Besides, what test have you done with this patch set?

> >

> > CommonLib.c(1651): error C2220: warning treated as error - no 'object' file generated

> > CommonLib.c(1651): warning C4133: 'function': incompatible types - from 'UINTN *' to 'UINT64 *'

> > NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\cl.exe"' : return code '0x2'

> >

> 

> Apologies, i missed this change at line 1624

> 

> -  UINTN                  Uint64;

> +  UINT64                 Uint64;

> 

> It builds fine with GCC though.

> 

> > Below > +  UINTN                  Uint64; ==> > +  UINT64                  Uint64;

> > > -----Original Message-----

> > > From: Ard Biesheuvel [mailto:ard.biesheuvel@linaro.org]

> > > Sent: Thursday, November 29, 2018 8:31 PM

> > > To: edk2-devel@lists.01.org

> > > Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>; Laszlo Ersek <lersek@redhat.com>; Zhu, Yonghong <yonghong.zhu@intel.com>;

> Gao,

> > > Liming <liming.gao@intel.com>; Feng, Bob C <bob.c.feng@intel.com>

> > > Subject: [PATCH 1/6] BaseTools/CommonLib: avoid using 'native' word size in IP address handling

> > >

> > > 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..bea6af0a45b1 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;

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

> >

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
Ard Biesheuvel Nov. 29, 2018, 3:18 p.m. UTC | #4
On Thu, 29 Nov 2018 at 16:15, Gao, Liming <liming.gao@intel.com> wrote:
>

> Do you verify which GCC arch? 32bit or 64bit or ARM?

>


64-bit ARM

> > -----Original Message-----

> > From: Ard Biesheuvel [mailto:ard.biesheuvel@linaro.org]

> > Sent: Thursday, November 29, 2018 11:14 PM

> > To: Gao, Liming <liming.gao@intel.com>

> > Cc: edk2-devel@lists.01.org; Laszlo Ersek <lersek@redhat.com>; Zhu, Yonghong <yonghong.zhu@intel.com>; Feng, Bob C

> > <bob.c.feng@intel.com>

> > Subject: Re: [PATCH 1/6] BaseTools/CommonLib: avoid using 'native' word size in IP address handling

> >

> > On Thu, 29 Nov 2018 at 16:11, Gao, Liming <liming.gao@intel.com> wrote:

> > >

> > > Ard:

> > >   I mean the build error. Besides, what test have you done with this patch set?

> > >

> > > CommonLib.c(1651): error C2220: warning treated as error - no 'object' file generated

> > > CommonLib.c(1651): warning C4133: 'function': incompatible types - from 'UINTN *' to 'UINT64 *'

> > > NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\cl.exe"' : return code '0x2'

> > >

> >

> > Apologies, i missed this change at line 1624

> >

> > -  UINTN                  Uint64;

> > +  UINT64                 Uint64;

> >

> > It builds fine with GCC though.

> >

> > > Below > +  UINTN                  Uint64; ==> > +  UINT64                  Uint64;

> > > > -----Original Message-----

> > > > From: Ard Biesheuvel [mailto:ard.biesheuvel@linaro.org]

> > > > Sent: Thursday, November 29, 2018 8:31 PM

> > > > To: edk2-devel@lists.01.org

> > > > Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>; Laszlo Ersek <lersek@redhat.com>; Zhu, Yonghong <yonghong.zhu@intel.com>;

> > Gao,

> > > > Liming <liming.gao@intel.com>; Feng, Bob C <bob.c.feng@intel.com>

> > > > Subject: [PATCH 1/6] BaseTools/CommonLib: avoid using 'native' word size in IP address handling

> > > >

> > > > 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..bea6af0a45b1 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;

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

> > >

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
Gao, Liming Nov. 30, 2018, 3:47 p.m. UTC | #5
Ard: 
  OK. Will you send v2 patch to fix this issue?

> -----Original Message-----

> From: Ard Biesheuvel [mailto:ard.biesheuvel@linaro.org]

> Sent: Thursday, November 29, 2018 11:18 PM

> To: Gao, Liming <liming.gao@intel.com>

> Cc: edk2-devel@lists.01.org; Laszlo Ersek <lersek@redhat.com>; Zhu, Yonghong <yonghong.zhu@intel.com>; Feng, Bob C

> <bob.c.feng@intel.com>

> Subject: Re: [PATCH 1/6] BaseTools/CommonLib: avoid using 'native' word size in IP address handling

> 

> On Thu, 29 Nov 2018 at 16:15, Gao, Liming <liming.gao@intel.com> wrote:

> >

> > Do you verify which GCC arch? 32bit or 64bit or ARM?

> >

> 

> 64-bit ARM

> 

> > > -----Original Message-----

> > > From: Ard Biesheuvel [mailto:ard.biesheuvel@linaro.org]

> > > Sent: Thursday, November 29, 2018 11:14 PM

> > > To: Gao, Liming <liming.gao@intel.com>

> > > Cc: edk2-devel@lists.01.org; Laszlo Ersek <lersek@redhat.com>; Zhu, Yonghong <yonghong.zhu@intel.com>; Feng, Bob C

> > > <bob.c.feng@intel.com>

> > > Subject: Re: [PATCH 1/6] BaseTools/CommonLib: avoid using 'native' word size in IP address handling

> > >

> > > On Thu, 29 Nov 2018 at 16:11, Gao, Liming <liming.gao@intel.com> wrote:

> > > >

> > > > Ard:

> > > >   I mean the build error. Besides, what test have you done with this patch set?

> > > >

> > > > CommonLib.c(1651): error C2220: warning treated as error - no 'object' file generated

> > > > CommonLib.c(1651): warning C4133: 'function': incompatible types - from 'UINTN *' to 'UINT64 *'

> > > > NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\cl.exe"' : return code '0x2'

> > > >

> > >

> > > Apologies, i missed this change at line 1624

> > >

> > > -  UINTN                  Uint64;

> > > +  UINT64                 Uint64;

> > >

> > > It builds fine with GCC though.

> > >

> > > > Below > +  UINTN                  Uint64; ==> > +  UINT64                  Uint64;

> > > > > -----Original Message-----

> > > > > From: Ard Biesheuvel [mailto:ard.biesheuvel@linaro.org]

> > > > > Sent: Thursday, November 29, 2018 8:31 PM

> > > > > To: edk2-devel@lists.01.org

> > > > > Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>; Laszlo Ersek <lersek@redhat.com>; Zhu, Yonghong <yonghong.zhu@intel.com>;

> > > Gao,

> > > > > Liming <liming.gao@intel.com>; Feng, Bob C <bob.c.feng@intel.com>

> > > > > Subject: [PATCH 1/6] BaseTools/CommonLib: avoid using 'native' word size in IP address handling

> > > > >

> > > > > 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..bea6af0a45b1 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;

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

> > > >

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
diff mbox series

Patch

diff --git a/BaseTools/Source/C/Common/CommonLib.c b/BaseTools/Source/C/Common/CommonLib.c
index 618aadac781a..bea6af0a45b1 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;
+  UINTN                  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;
       }