Tracker: add some time_t overflow checks in StatusWindow
Don't pretend file copies will end in 1901, that's obviously wrong. Helps with #11176, but we should really not use time_t here, or make it 64bit. Fun fact: we're now closer to the end of the UNIX epoch than to the creation of Haiku! Change-Id: I64acc5ab29fb778fe3034c65b5a8418951d30505 Reviewed-on: https://review.haiku-os.org/c/haiku/+/2608 Reviewed-by: waddlesplash <[email protected]>
This commit is contained in:
committed by
waddlesplash
parent
d8d403ef5d
commit
9670db20dd
@@ -794,26 +794,31 @@ BStatusView::_TimeStatusString(float availableSpace, float* _width)
|
||||
double secondsRemaining = (fTotalSize - fSizeProcessed)
|
||||
/ totalBytesPerSecond;
|
||||
time_t now = (time_t)real_time_clock();
|
||||
time_t finishTime = (time_t)(now + secondsRemaining);
|
||||
|
||||
char timeText[32];
|
||||
if (finishTime - now > kSecondsPerDay) {
|
||||
BDateTimeFormat().Format(timeText, sizeof(timeText), finishTime,
|
||||
B_MEDIUM_DATE_FORMAT, B_MEDIUM_TIME_FORMAT);
|
||||
BString string;
|
||||
if (secondsRemaining < 0 || (sizeof(time_t) == 4
|
||||
&& now + secondsRemaining > INT32_MAX)) {
|
||||
string = B_TRANSLATE("Finish: after several years");
|
||||
} else {
|
||||
BTimeFormat().Format(timeText, sizeof(timeText), finishTime,
|
||||
B_MEDIUM_TIME_FORMAT);
|
||||
}
|
||||
char timeText[32];
|
||||
time_t finishTime = (time_t)(now + secondsRemaining);
|
||||
|
||||
BString string(_FullTimeRemainingString(now, finishTime, timeText));
|
||||
float width = StringWidth(string.String());
|
||||
if (width > availableSpace) {
|
||||
string.SetTo(_ShortTimeRemainingString(timeText));
|
||||
width = StringWidth(string.String());
|
||||
if (finishTime - now > kSecondsPerDay) {
|
||||
BDateTimeFormat().Format(timeText, sizeof(timeText), finishTime,
|
||||
B_MEDIUM_DATE_FORMAT, B_MEDIUM_TIME_FORMAT);
|
||||
} else {
|
||||
BTimeFormat().Format(timeText, sizeof(timeText), finishTime,
|
||||
B_MEDIUM_TIME_FORMAT);
|
||||
}
|
||||
string = _FullTimeRemainingString(now, finishTime, timeText);
|
||||
float width = StringWidth(string.String());
|
||||
if (width > availableSpace) {
|
||||
string.SetTo(_ShortTimeRemainingString(timeText));
|
||||
}
|
||||
}
|
||||
|
||||
if (_width != NULL)
|
||||
*_width = width;
|
||||
*_width = StringWidth(string.String());
|
||||
|
||||
return string;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user