mirror of https://github.com/odrling/Aegisub
Fix overflow handling in AssTime::GetAssFormatted
Originally committed to SVN as r4790.
This commit is contained in:
parent
35b9769092
commit
7586f28ffe
|
@ -172,22 +172,18 @@ void AssTime::SetMS (int _ms) {
|
||||||
/// @return
|
/// @return
|
||||||
///
|
///
|
||||||
wxString AssTime::GetASSFormated (bool msPrecision) const {
|
wxString AssTime::GetASSFormated (bool msPrecision) const {
|
||||||
int h,m,s,ms;
|
int ms = time;
|
||||||
int _ms = time;
|
|
||||||
|
|
||||||
// Centisecond precision
|
// Centisecond precision
|
||||||
msPrecision = msPrecision || UseMSPrecision;
|
msPrecision = msPrecision || UseMSPrecision;
|
||||||
if (!msPrecision) _ms = _ms/10*10;
|
if (!msPrecision) ms = ms/10*10;
|
||||||
|
|
||||||
// Reset
|
if (ms < 0) ms = 0;
|
||||||
h = m = s = ms = 0;
|
|
||||||
if (_ms < 0) _ms = 0;
|
|
||||||
|
|
||||||
// Hours
|
int h = ms / (1000 * 60 * 60);
|
||||||
while (_ms >= 3600000) {
|
int m = (ms / (1000 * 60)) % 60;
|
||||||
_ms -= 3600000;
|
int s = (ms / 1000) % 60;
|
||||||
h++;
|
ms = ms % 1000;
|
||||||
}
|
|
||||||
|
|
||||||
// Ass overflow
|
// Ass overflow
|
||||||
if (h > 9) {
|
if (h > 9) {
|
||||||
|
@ -197,19 +193,6 @@ wxString AssTime::GetASSFormated (bool msPrecision) const {
|
||||||
ms = 999;
|
ms = 999;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Minutes
|
|
||||||
while (_ms >= 60000) {
|
|
||||||
_ms -= 60000;
|
|
||||||
m++;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Seconds
|
|
||||||
while (_ms >= 1000) {
|
|
||||||
_ms -= 1000;
|
|
||||||
s++;
|
|
||||||
}
|
|
||||||
ms = _ms;
|
|
||||||
|
|
||||||
if (msPrecision) return wxString::Format(_T("%01i:%02i:%02i.%03i"),h,m,s,ms);
|
if (msPrecision) return wxString::Format(_T("%01i:%02i:%02i.%03i"),h,m,s,ms);
|
||||||
else return wxString::Format(_T("%01i:%02i:%02i.%02i"),h,m,s,ms/10);
|
else return wxString::Format(_T("%01i:%02i:%02i.%02i"),h,m,s,ms/10);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue