Fix: values above INT_MAX (68 years) are interpreted as negative values (#4085)
This commit is contained in:
parent
fd7bb4a287
commit
69ee92113f
|
@ -2068,20 +2068,16 @@ bool trashDataFile(char const* filename, void* /*user_data*/, tr_error** error)
|
|||
|
||||
- (NSString*)etaString
|
||||
{
|
||||
NSInteger eta;
|
||||
BOOL fromIdle;
|
||||
//don't check for both, since if there's a regular ETA, the torrent isn't idle so it's meaningless
|
||||
if (self.fStat->eta != TR_ETA_NOT_AVAIL && self.fStat->eta != TR_ETA_UNKNOWN)
|
||||
{
|
||||
eta = self.fStat->eta;
|
||||
fromIdle = NO;
|
||||
}
|
||||
else if (self.fStat->etaIdle != TR_ETA_NOT_AVAIL && self.fStat->etaIdle < kETAIdleDisplaySec)
|
||||
time_t eta = self.fStat->eta;
|
||||
// if there's a regular ETA, the torrent isn't idle
|
||||
BOOL fromIdle = NO;
|
||||
if (eta == TR_ETA_NOT_AVAIL || eta == TR_ETA_UNKNOWN)
|
||||
{
|
||||
eta = self.fStat->etaIdle;
|
||||
fromIdle = YES;
|
||||
}
|
||||
else
|
||||
// Foundation undocumented behavior: values above INT_MAX (68 years) are interpreted as negative values by `stringFromTimeInterval` (#3451)
|
||||
if (eta < 0 || eta > INT_MAX || (fromIdle && eta >= kETAIdleDisplaySec))
|
||||
{
|
||||
return NSLocalizedString(@"remaining time unknown", "Torrent -> eta string");
|
||||
}
|
||||
|
@ -2095,6 +2091,8 @@ bool trashDataFile(char const* filename, void* /*user_data*/, tr_error** error)
|
|||
formatter.collapsesLargestUnit = YES;
|
||||
formatter.includesTimeRemainingPhrase = YES;
|
||||
});
|
||||
// the duration of months being variable, setting the reference date to now (instead of 00:00:00 UTC on 1 January 2001)
|
||||
formatter.referenceDate = NSDate.date;
|
||||
NSString* idleString = [formatter stringFromTimeInterval:eta];
|
||||
|
||||
if (fromIdle)
|
||||
|
|
Loading…
Reference in New Issue