QDateTime: fix UB (signed overflow) in addDays()
The comment indicated that the author expected any overflow to be caught by a bounds check in the subsequent function, however, signed overflow is UB, so anything can happen. Fix by using our API for safe additions instead. Pick-to: 6.3 6.2 5.15 Change-Id: I41909defffa5305b02fdfcf6d5808e0d9fd5924f Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
52da10f645
commit
c47c98ea2b
@ -1227,9 +1227,10 @@ QDate QDate::addDays(qint64 ndays) const
|
||||
if (isNull())
|
||||
return QDate();
|
||||
|
||||
// Due to limits on minJd() and maxJd() we know that any overflow
|
||||
// will be invalid and caught by fromJulianDay().
|
||||
return fromJulianDay(jd + ndays);
|
||||
if (qint64 r; Q_UNLIKELY(qAddOverflow(jd, ndays, &r)))
|
||||
return QDate();
|
||||
else
|
||||
return fromJulianDay(r);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
Loading…
Reference in New Issue
Block a user