mirror of
https://github.com/HowardHinnant/date.git
synced 2024-12-27 00:14:07 +08:00
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:
parent
66a5aa482e
commit
9502bc27a3
@ -1564,7 +1564,7 @@ inline
|
||||
month
|
||||
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;
|
||||
return month{static_cast<unsigned>(mu - yr * 12 + 1)};
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user