Skip to content

Commit

Permalink
Fix issue for Int.max overflow (#211)
Browse files Browse the repository at this point in the history
* Fix issue for Int.max overflow

For Iphone 5c and lower the processors is built on a 32-bit architecture. So any Int will be 32 bit. For these device we need to use Int64 as Date().timeIntervalSince1970 * 1000 will be out of range.

* suggestion fix

* ageInMilliseconds theoretically can cause a fatal exception on 32-bit arch
  • Loading branch information
Antoine Jacquemin (Rubicon) authored and ppuviarasu committed Jun 25, 2019
1 parent 15926b8 commit 7149f90
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/PrebidMobile/PrebidMobile/BidManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import Foundation
if (!Prebid.shared.timeoutUpdated) {
let tmax = self.getTmaxRequest(data!)
if (tmax > 0) {
Prebid.shared.timeoutMillis = min(demandFetchEndTime - demandFetchStartTime + tmax + 200, .PB_Request_Timeout)
Prebid.shared.timeoutMillis = min(Int(demandFetchEndTime - demandFetchStartTime) + tmax + 200, .PB_Request_Timeout)
Prebid.shared.timeoutUpdated = true
}
}
Expand Down Expand Up @@ -144,8 +144,8 @@ import Foundation

}

func getCurrentMillis() -> Int {
return Int(Date().timeIntervalSince1970 * 1000)
func getCurrentMillis() -> Int64 {
return Int64(Date().timeIntervalSince1970 * 1000)
}

func getTmaxRequest(_ data: Data) -> Int {
Expand Down
2 changes: 1 addition & 1 deletion src/PrebidMobile/PrebidMobile/RequestBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ import AdSupport

let locationTimestamp: Date? = Location.shared.location?.timestamp
let ageInSeconds: TimeInterval = -1.0 * (locationTimestamp?.timeIntervalSinceNow ?? 0.0)
let ageInMilliseconds = Int(ageInSeconds * 1000)
let ageInMilliseconds = Int64(ageInSeconds * 1000)

geoDict["lastfix"] = ageInMilliseconds
geoDict["accuracy"] = Int(Location.shared.location?.horizontalAccuracy ?? 0)
Expand Down

0 comments on commit 7149f90

Please sign in to comment.