Update Date.h (#529)

* Remove arithmetic overflow: 

Using operator '-' on a 4 byte value and then casting the result to a 8 byte value. Casting the value to the wider type before calling operator '-' to avoid overflow.
This commit is contained in:
Nexus Web Development 2020-01-11 15:24:10 -05:00 committed by Howard Hinnant
parent 66a5aa482e
commit 9502bc27a3

View File

@ -1564,7 +1564,7 @@ inline
month month
operator+(const month& x, const months& y) NOEXCEPT operator+(const month& x, const months& y) NOEXCEPT
{ {
auto const mu = static_cast<long long>(static_cast<unsigned>(x)) + (y.count() - 1); auto const mu = static_cast<long long>(static_cast<unsigned>(x)) + y.count() - 1;
auto const yr = (mu >= 0 ? mu : mu-11) / 12; auto const yr = (mu >= 0 ? mu : mu-11) / 12;
return month{static_cast<unsigned>(mu - yr * 12 + 1)}; return month{static_cast<unsigned>(mu - yr * 12 + 1)};
} }