Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent 32bit int overflow when calculating duration of days #1371

Merged
merged 1 commit into from
Dec 13, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Sources/Cache/Storage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ struct TimeConstants {
static let secondsInOneMinute = 60
static let minutesInOneHour = 60
static let hoursInOneDay = 24
static let secondsInOneDay = secondsInOneMinute * minutesInOneHour * hoursInOneDay
static let secondsInOneDay = TimeInterval(secondsInOneMinute * minutesInOneHour * hoursInOneDay)
}

/// Represents the expiration strategy used in storage.
Expand All @@ -58,7 +58,7 @@ public enum StorageExpiration {
case .seconds(let seconds):
return date.addingTimeInterval(seconds)
case .days(let days):
let duration = TimeInterval(TimeConstants.secondsInOneDay * days)
let duration = TimeConstants.secondsInOneDay * TimeInterval(days)
return date.addingTimeInterval(duration)
case .date(let ref):
return ref
Expand All @@ -79,7 +79,7 @@ public enum StorageExpiration {
switch self {
case .never: return .infinity
case .seconds(let seconds): return seconds
case .days(let days): return TimeInterval(TimeConstants.secondsInOneDay * days)
case .days(let days): return TimeConstants.secondsInOneDay * TimeInterval(days)
case .date(let ref): return ref.timeIntervalSinceNow
case .expired: return -(.infinity)
}
Expand Down