Skip to content

Commit

Permalink
Prevent 32bit int overflow when calculating duration forr day
Browse files Browse the repository at this point in the history
  • Loading branch information
onevcat committed Dec 13, 2019
1 parent b8ea4a1 commit eb093d9
Showing 1 changed file with 3 additions and 3 deletions.
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

0 comments on commit eb093d9

Please sign in to comment.