From: "Leif Lindholm" <leif.lindholm@linaro.org>
To: devel@edk2.groups.io
Cc: ard.biesheuvel@linaro.org, Alexei Fedorov <Alexei.Fedorov@arm.com>
Subject: [PATCH 2/2] EmbeddedPkg: improve TimeBaseLib type safety
Date: Thu, 13 Jun 2019 17:18:33 +0100 [thread overview]
Message-ID: <20190613161833.30102-3-leif.lindholm@linaro.org> (raw)
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>
---
EmbeddedPkg/Include/Library/TimeBaseLib.h | 4 ++--
EmbeddedPkg/Library/TimeBaseLib/TimeBaseLib.c | 18 +++++++++---------
2 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/EmbeddedPkg/Include/Library/TimeBaseLib.h b/EmbeddedPkg/Include/Library/TimeBaseLib.h
index d51059cb1f7d..4103c89b3891 100644
--- a/EmbeddedPkg/Include/Library/TimeBaseLib.h
+++ b/EmbeddedPkg/Include/Library/TimeBaseLib.h
@@ -1,7 +1,7 @@
/** @file
*
* Copyright (c) 2016, Hisilicon Limited. All rights reserved.
-* Copyright (c) 2016, Linaro Limited. All rights reserved.
+* Copyright (c) 2016-2019, Linaro Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-2-Clause-Patent
*
@@ -53,7 +53,7 @@ EpochToEfiTime (
/**
Converts EFI_TIME to Epoch seconds (elapsed since 1970 JANUARY 01, 00:00:00 UTC)
**/
-UINTN
+UINT32
EFIAPI
EfiTimeToEpoch (
IN EFI_TIME *Time
diff --git a/EmbeddedPkg/Library/TimeBaseLib/TimeBaseLib.c b/EmbeddedPkg/Library/TimeBaseLib/TimeBaseLib.c
index 662cbdd5da99..136ce8a51e86 100644
--- a/EmbeddedPkg/Library/TimeBaseLib/TimeBaseLib.c
+++ b/EmbeddedPkg/Library/TimeBaseLib/TimeBaseLib.c
@@ -1,7 +1,7 @@
/** @file
*
* Copyright (c) 2016, Hisilicon Limited. All rights reserved.
-* Copyright (c) 2016, Linaro Limited. All rights reserved.
+* Copyright (c) 2016-2019, Linaro Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-2-Clause-Patent
*
@@ -53,9 +53,9 @@ EpochToEfiTime (
m = (((da * 5) + 308) / 153) - 2;
d = da - (((m + 4) * 153) / 5) + 122;
- Time->Year = y - 4800 + ((m + 2) / 12);
+ Time->Year = (UINT16)(y - 4800 + ((m + 2) / 12));
Time->Month = ((m + 2) % 12) + 1;
- Time->Day = d + 1;
+ Time->Day = (UINT8)(d + 1);
ss = EpochSeconds % 60;
a = (EpochSeconds - ss) / 60;
@@ -63,9 +63,9 @@ EpochToEfiTime (
b = (a - mm) / 60;
hh = b % 24;
- Time->Hour = hh;
- Time->Minute = mm;
- Time->Second = ss;
+ Time->Hour = (UINT8)hh;
+ Time->Minute = (UINT8)mm;
+ Time->Second = (UINT8)ss;
Time->Nanosecond = 0;
}
@@ -99,14 +99,14 @@ EfiGetEpochDays (
/**
Converts EFI_TIME to Epoch seconds (elapsed since 1970 JANUARY 01, 00:00:00 UTC)
**/
-UINTN
+UINT32
EFIAPI
EfiTimeToEpoch (
IN EFI_TIME *Time
)
{
- UINTN EpochDays; // Number of days elapsed since EPOCH_JULIAN_DAY
- UINTN EpochSeconds;
+ UINT32 EpochDays; // Number of days elapsed since EPOCH_JULIAN_DAY
+ UINT32 EpochSeconds;
EpochDays = EfiGetEpochDays (Time);
--
2.11.0
reply other threads:[~2019-06-13 16:18 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20190613161833.30102-3-leif.lindholm@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