diff options
| author | Linus Groh <mail@linusgroh.de> | 2025-03-02 22:31:02 +0000 |
|---|---|---|
| committer | Linus Groh <mail@linusgroh.de> | 2025-03-02 22:58:45 +0000 |
| commit | 6378295b771b2e621918d20e45debf91ee114eac (patch) | |
| tree | f2eff891f7157ce248187071bb24c0dc3115d72c /lib/std | |
| parent | 0367d684fccf8bf011fe8ac1a984820c824871a8 (diff) | |
| download | zig-6378295b771b2e621918d20e45debf91ee114eac.tar.gz zig-6378295b771b2e621918d20e45debf91ee114eac.zip | |
std.os.uefi: Fix integer overflow in Time.toEpoch()
Instead of thinking hard about what the actual supported maximum value
for each sub-calculation is we can simply use an u64 from hours onwards.
Diffstat (limited to 'lib/std')
| -rw-r--r-- | lib/std/os/uefi.zig | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/lib/std/os/uefi.zig b/lib/std/os/uefi.zig index f67fe5623e..d7f6da26cf 100644 --- a/lib/std/os/uefi.zig +++ b/lib/std/os/uefi.zig @@ -132,12 +132,12 @@ pub const Time = extern struct { /// Time is to be interpreted as local time pub const unspecified_timezone: i16 = 0x7ff; - fn daysInYear(year: u16, maxMonth: u4) u32 { - const leapYear: std.time.epoch.YearLeapKind = if (std.time.epoch.isLeapYear(year)) .leap else .not_leap; - var days: u32 = 0; + fn daysInYear(year: u16, max_month: u4) u9 { + const leap_year: std.time.epoch.YearLeapKind = if (std.time.epoch.isLeapYear(year)) .leap else .not_leap; + var days: u9 = 0; var month: u4 = 0; - while (month < maxMonth) : (month += 1) { - days += std.time.epoch.getDaysInMonth(leapYear, @enumFromInt(month + 1)); + while (month < max_month) : (month += 1) { + days += std.time.epoch.getDaysInMonth(leap_year, @enumFromInt(month + 1)); } return days; } @@ -151,9 +151,9 @@ pub const Time = extern struct { } days += daysInYear(self.year, @as(u4, @intCast(self.month)) - 1) + self.day; - const hours = self.hour + (days * 24); - const minutes = self.minute + (hours * 60); - const seconds = self.second + (minutes * std.time.s_per_min); + const hours: u64 = self.hour + (days * 24); + const minutes: u64 = self.minute + (hours * 60); + const seconds: u64 = self.second + (minutes * std.time.s_per_min); return self.nanosecond + (seconds * std.time.ns_per_s); } }; |
