Avoid overflow in QTime::addSecs with too big a number of seconds

QDateTime::addSecs needs to do something similar, but not identical
because it needs the number of days too. And then there are daylight
savings transitions...

Task-number: QTBUG-47717
Change-Id: I7de033f80b0e4431b7f1ffff13f976f4f5e5a059
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@theqtcompany.com>
bb10
Thiago Macieira 2015-08-11 09:59:10 -07:00
parent cc6a06632b
commit cc5e84c878
2 changed files with 3 additions and 0 deletions

View File

@ -1681,6 +1681,7 @@ bool QTime::setHMS(int h, int m, int s, int ms)
QTime QTime::addSecs(int s) const
{
s %= SECS_PER_DAY;
return addMSecs(s * 1000);
}

View File

@ -84,6 +84,8 @@ void tst_QTime::addSecs_data()
QTest::newRow("Data0") << QTime(0,0,0) << 200 << QTime(0,3,20);
QTest::newRow("Data1") << QTime(0,0,0) << 20 << QTime(0,0,20);
QTest::newRow("overflow") << QTime(0,0,0) << (INT_MAX / 1000 + 1)
<< QTime(0,0,0).addSecs((INT_MAX / 1000 + 1) % 86400);
}
void tst_QTime::addSecs()