Skip to content

Commit b3efa77

Browse files
committed
EmbeddedPkg/VirtualRealTimeClockLib: Fix VS2022 type conversion warnings
Fix type conversion warnings (C4244) in VirtualRealTimeClockLib that prevent it from building with Visual Studio 2022 when the /WX flag (treat warnings as errors) is enabled. Changes made: EmbeddedPkg/Library/VirtualRealTimeClockLib/VirtualRealTimeClockLib.c - Add (UINTN) casts for DivU64x64Remainder return values in LibGetTime() - Add (UINTN) casts for DivU64x64Remainder return values in LibSetTime() Rationale: - DivU64x64Remainder returns UINT64 values - On IA32 architecture, UINTN is 32-bit while the return value is 64-bit - Explicit casts are required to handle the 64-bit to 32-bit conversion on IA32 without data loss warnings - The casts are safe because the values represent elapsed seconds since platform reset, which will not overflow 32-bit values in practice Tested on: - Windows 11 with VS2022 (X64 and IA32) - Ubuntu with GCC5 (X64) Addresses: #11737 Signed-off-by: Gary Beihl <[email protected]>
1 parent d18fae3 commit b3efa77

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

EmbeddedPkg/Library/VirtualRealTimeClockLib/VirtualRealTimeClockLib.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ LibGetTime (
9898
}
9999

100100
Counter = GetPerformanceCounter ();
101-
EpochSeconds += DivU64x64Remainder (Counter, Freq, &Remainder);
101+
EpochSeconds += (UINTN)DivU64x64Remainder (Counter, Freq, &Remainder);
102102

103103
// Get the current time zone information from non-volatile storage
104104
Size = sizeof (TimeZone);
@@ -271,8 +271,8 @@ LibSetTime (
271271
Freq = GetPerformanceCounterProperties (NULL, NULL);
272272
if (Freq != 0) {
273273
Counter = GetPerformanceCounter ();
274-
if (EpochSeconds > DivU64x64Remainder (Counter, Freq, &Remainder)) {
275-
EpochSeconds -= DivU64x64Remainder (Counter, Freq, &Remainder);
274+
if (EpochSeconds > (UINTN)DivU64x64Remainder (Counter, Freq, &Remainder)) {
275+
EpochSeconds -= (UINTN)DivU64x64Remainder (Counter, Freq, &Remainder);
276276
}
277277
}
278278

0 commit comments

Comments
 (0)