diff mbox series

[edk2,v2,2/6] BaseTools/CommonLib: use explicit 64-bit type in Strtoi()

Message ID 20181130224537.18936-3-ard.biesheuvel@linaro.org
State Accepted
Commit 76e5f493d20cbe521dccb0c184012f0336ffd323
Headers show
Series BaseTools: get rid of MAX_UINTN | expand

Commit Message

Ard Biesheuvel Nov. 30, 2018, 10:45 p.m. UTC
Don't use the native word size string to number parsing routines,
but instead, use the 64-bit one and cast to UINTN.

Currently, the only user is in Source/C/DevicePath/DevicePathFromText.c
which takes care to use Strtoi64 () unless it assumes the value fits
in 32-bit, so this change is a no-op even on 32-bit build hosts.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>

Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>

---
 BaseTools/Source/C/Common/CommonLib.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

-- 
2.19.1

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

Comments

Philippe Mathieu-Daudé Dec. 3, 2018, 10:25 a.m. UTC | #1
On 30/11/18 23:45, Ard Biesheuvel wrote:
> Don't use the native word size string to number parsing routines,
> but instead, use the 64-bit one and cast to UINTN.
> 
> Currently, the only user is in Source/C/DevicePath/DevicePathFromText.c
> which takes care to use Strtoi64 () unless it assumes the value fits
> in 32-bit, so this change is a no-op even on 32-bit build hosts.
> 
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
> Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>

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

> ---
>  BaseTools/Source/C/Common/CommonLib.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/BaseTools/Source/C/Common/CommonLib.c b/BaseTools/Source/C/Common/CommonLib.c
> index 7c559bc3c222..4a28f635f3a8 100644
> --- a/BaseTools/Source/C/Common/CommonLib.c
> +++ b/BaseTools/Source/C/Common/CommonLib.c
> @@ -2252,9 +2252,9 @@ Strtoi (
>    )
>  {
>    if (IsHexStr (Str)) {
> -    return StrHexToUintn (Str);
> +    return (UINTN)StrHexToUint64 (Str);
>    } else {
> -    return StrDecimalToUintn (Str);
> +    return (UINTN)StrDecimalToUint64 (Str);
>    }
>  }
>  
>
Laszlo Ersek Dec. 3, 2018, 12:52 p.m. UTC | #2
On 11/30/18 23:45, Ard Biesheuvel wrote:
> Don't use the native word size string to number parsing routines,

> but instead, use the 64-bit one and cast to UINTN.

> 

> Currently, the only user is in Source/C/DevicePath/DevicePathFromText.c

> which takes care to use Strtoi64 () unless it assumes the value fits

> in 32-bit, so this change is a no-op even on 32-bit build hosts.

> 

> Contributed-under: TianoCore Contribution Agreement 1.1

> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>

> Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>

> ---

>  BaseTools/Source/C/Common/CommonLib.c | 4 ++--

>  1 file changed, 2 insertions(+), 2 deletions(-)

> 

> diff --git a/BaseTools/Source/C/Common/CommonLib.c b/BaseTools/Source/C/Common/CommonLib.c

> index 7c559bc3c222..4a28f635f3a8 100644

> --- a/BaseTools/Source/C/Common/CommonLib.c

> +++ b/BaseTools/Source/C/Common/CommonLib.c

> @@ -2252,9 +2252,9 @@ Strtoi (

>    )

>  {

>    if (IsHexStr (Str)) {

> -    return StrHexToUintn (Str);

> +    return (UINTN)StrHexToUint64 (Str);

>    } else {

> -    return StrDecimalToUintn (Str);

> +    return (UINTN)StrDecimalToUint64 (Str);

>    }

>  }

>  

> 


Reviewed-by: Laszlo Ersek <lersek@redhat.com>

_______________________________________________
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 7c559bc3c222..4a28f635f3a8 100644
--- a/BaseTools/Source/C/Common/CommonLib.c
+++ b/BaseTools/Source/C/Common/CommonLib.c
@@ -2252,9 +2252,9 @@  Strtoi (
   )
 {
   if (IsHexStr (Str)) {
-    return StrHexToUintn (Str);
+    return (UINTN)StrHexToUint64 (Str);
   } else {
-    return StrDecimalToUintn (Str);
+    return (UINTN)StrDecimalToUint64 (Str);
   }
 }