From eb093d929bb3a6a1175fe731145b34a396af73fb Mon Sep 17 00:00:00 2001 From: onevcat Date: Fri, 13 Dec 2019 22:45:29 +0900 Subject: [PATCH] Prevent 32bit int overflow when calculating duration forr day --- Sources/Cache/Storage.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/Cache/Storage.swift b/Sources/Cache/Storage.swift index bbc70900a..f665002f6 100644 --- a/Sources/Cache/Storage.swift +++ b/Sources/Cache/Storage.swift @@ -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. @@ -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 @@ -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) }