Skip to content

Commit

Permalink
zeit: prevent integer overflow when creating Instant from unix_timestamp
Browse files Browse the repository at this point in the history
Explicitly cast unix_timestamp to i128 to prevent integer overflow. Zig
will overflow because unix_timestamp is i64, but Nanoseconds is i128
which wouldn't overflow in some cases.

Fixes: #18
  • Loading branch information
rockorager committed Jan 14, 2025
1 parent 856e777 commit 52b100c
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/zeit.zig
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ pub const Instant = struct {
pub fn instant(cfg: Instant.Config) !Instant {
const ts: Nanoseconds = switch (cfg.source) {
.now => std.time.nanoTimestamp(),
.unix_timestamp => |unix| unix * ns_per_s,
.unix_timestamp => |unix| @as(i128, unix) * ns_per_s,
.unix_nano => |nano| nano,
.time => |time| time.instant().timestamp,
.iso8601,
Expand Down

0 comments on commit 52b100c

Please sign in to comment.