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
parent
cc6a06632b
commit
cc5e84c878
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Reference in New Issue