]> git.proxmox.com Git - mirror_edk2.git/commitdiff
EmbeddedPkg: improve TimeBaseLib type safety
authorLeif Lindholm <leif.lindholm@linaro.org>
Thu, 13 Jun 2019 15:48:28 +0000 (16:48 +0100)
committerLeif Lindholm <leif.lindholm@linaro.org>
Mon, 17 Jun 2019 11:04:11 +0000 (12:04 +0100)
EfiTimeToEpoch currently returns a UINTN.
Also, some internal calculations was using UINTN for fixed-width.
Both of these lead to warnings/errors with VS2017.

Replace with appropriate fixed-size types.

BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=997

Cc: Alexei Fedorov <Alexei.Fedorov@arm.com>
Signed-off-by: Leif Lindholm <leif.lindholm@linaro.org>
Acked-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Philippe Mathieu-Daude <philmd@redhat.com>
EmbeddedPkg/Include/Library/TimeBaseLib.h
EmbeddedPkg/Library/TimeBaseLib/TimeBaseLib.c

index d51059cb1f7d9572264f18c7c658a34cf1c5f6cc..4103c89b38913c3b54b9df1bacc0e0da51d2c62f 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
 *\r
 *  Copyright (c) 2016, Hisilicon Limited. All rights reserved.\r
-*  Copyright (c) 2016, Linaro Limited. All rights reserved.\r
+*  Copyright (c) 2016-2019, Linaro Limited. All rights reserved.\r
 *\r
 *  SPDX-License-Identifier: BSD-2-Clause-Patent\r
 *\r
@@ -53,7 +53,7 @@ EpochToEfiTime (
 /**\r
   Converts EFI_TIME to Epoch seconds (elapsed since 1970 JANUARY 01, 00:00:00 UTC)\r
  **/\r
-UINTN\r
+UINT32\r
 EFIAPI\r
 EfiTimeToEpoch (\r
   IN  EFI_TIME  *Time\r
index 662cbdd5da99c32d4d613ae67fcc72d14c05cdc0..136ce8a51e864d506433f38966948dac65b1f630 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
 *\r
 *  Copyright (c) 2016, Hisilicon Limited. All rights reserved.\r
-*  Copyright (c) 2016, Linaro Limited. All rights reserved.\r
+*  Copyright (c) 2016-2019, Linaro Limited. All rights reserved.\r
 *\r
 *  SPDX-License-Identifier: BSD-2-Clause-Patent\r
 *\r
@@ -53,9 +53,9 @@ EpochToEfiTime (
   m  = (((da * 5) + 308) / 153) - 2;\r
   d  = da - (((m + 4) * 153) / 5) + 122;\r
 \r
-  Time->Year  = y - 4800 + ((m + 2) / 12);\r
+  Time->Year  = (UINT16)(y - 4800 + ((m + 2) / 12));\r
   Time->Month = ((m + 2) % 12) + 1;\r
-  Time->Day   = d + 1;\r
+  Time->Day   = (UINT8)(d + 1);\r
 \r
   ss = EpochSeconds % 60;\r
   a  = (EpochSeconds - ss) / 60;\r
@@ -63,9 +63,9 @@ EpochToEfiTime (
   b = (a - mm) / 60;\r
   hh = b % 24;\r
 \r
-  Time->Hour        = hh;\r
-  Time->Minute      = mm;\r
-  Time->Second      = ss;\r
+  Time->Hour        = (UINT8)hh;\r
+  Time->Minute      = (UINT8)mm;\r
+  Time->Second      = (UINT8)ss;\r
   Time->Nanosecond  = 0;\r
 \r
 }\r
@@ -99,14 +99,14 @@ EfiGetEpochDays (
 /**\r
   Converts EFI_TIME to Epoch seconds (elapsed since 1970 JANUARY 01, 00:00:00 UTC)\r
  **/\r
-UINTN\r
+UINT32\r
 EFIAPI\r
 EfiTimeToEpoch (\r
   IN  EFI_TIME  *Time\r
   )\r
 {\r
-  UINTN EpochDays;   // Number of days elapsed since EPOCH_JULIAN_DAY\r
-  UINTN EpochSeconds;\r
+  UINT32 EpochDays;   // Number of days elapsed since EPOCH_JULIAN_DAY\r
+  UINT32 EpochSeconds;\r
 \r
   EpochDays = EfiGetEpochDays (Time);\r
 \r