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)
|
double secondsRemaining = (fTotalSize - fSizeProcessed)
|
||||||
/ totalBytesPerSecond;
|
/ totalBytesPerSecond;
|
||||||
time_t now = (time_t)real_time_clock();
|
time_t now = (time_t)real_time_clock();
|
||||||
time_t finishTime = (time_t)(now + secondsRemaining);
|
|
||||||
|
|
||||||
char timeText[32];
|
BString string;
|
||||||
if (finishTime - now > kSecondsPerDay) {
|
if (secondsRemaining < 0 || (sizeof(time_t) == 4
|
||||||
BDateTimeFormat().Format(timeText, sizeof(timeText), finishTime,
|
&& now + secondsRemaining > INT32_MAX)) {
|
||||||
B_MEDIUM_DATE_FORMAT, B_MEDIUM_TIME_FORMAT);
|
string = B_TRANSLATE("Finish: after several years");
|
||||||
} else {
|
} else {
|
||||||
BTimeFormat().Format(timeText, sizeof(timeText), finishTime,
|
char timeText[32];
|
||||||
B_MEDIUM_TIME_FORMAT);
|
time_t finishTime = (time_t)(now + secondsRemaining);
|
||||||
}
|
|
||||||
|
|
||||||
BString string(_FullTimeRemainingString(now, finishTime, timeText));
|
if (finishTime - now > kSecondsPerDay) {
|
||||||
float width = StringWidth(string.String());
|
BDateTimeFormat().Format(timeText, sizeof(timeText), finishTime,
|
||||||
if (width > availableSpace) {
|
B_MEDIUM_DATE_FORMAT, B_MEDIUM_TIME_FORMAT);
|
||||||
string.SetTo(_ShortTimeRemainingString(timeText));
|
} else {
|
||||||
width = StringWidth(string.String());
|
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)
|
if (_width != NULL)
|
||||||
*_width = width;
|
*_width = StringWidth(string.String());
|
||||||
|
|
||||||
return string;
|
return string;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user