forked from HowardHinnant/date
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:
@@ -1719,8 +1719,8 @@ inline
|
|||||||
unsigned char
|
unsigned char
|
||||||
weekday::weekday_from_days(int z) NOEXCEPT
|
weekday::weekday_from_days(int z) NOEXCEPT
|
||||||
{
|
{
|
||||||
return static_cast<unsigned char>(static_cast<unsigned>(
|
auto u = static_cast<unsigned>(z);
|
||||||
z >= -4 ? (z+4) % 7 : (z+5) % 7 + 6));
|
return static_cast<unsigned char>(z >= -4 ? (u+4) % 7 : u % 7);
|
||||||
}
|
}
|
||||||
|
|
||||||
CONSTCD11
|
CONSTCD11
|
||||||
|
Reference in New Issue
Block a user