Protect weekday_from_days from signed overflow

Found by static analyzer.
This change makes weekday_from_days slightly more efficient.
This commit is contained in:
Howard Hinnant
2019-03-19 19:51:32 -04:00
parent b5d025ea2f
commit cb7ca96f68

View File

@ -1719,8 +1719,8 @@ inline
unsigned char
weekday::weekday_from_days(int z) NOEXCEPT
{
return static_cast<unsigned char>(static_cast<unsigned>(
z >= -4 ? (z+4) % 7 : (z+5) % 7 + 6));
auto u = static_cast<unsigned>(z);
return static_cast<unsigned char>(z >= -4 ? (u+4) % 7 : u % 7);
}
CONSTCD11