fix: bugprone-narrowing-conversions warnings in bitfield.cc (#2806)

This commit is contained in:
Charles Kerr 2022-03-24 08:31:00 -05:00 committed by GitHub
parent b8c3778cf4
commit f19c09ad9b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 7 deletions

View File

@ -87,7 +87,7 @@ size_t tr_bitfield::countFlags(size_t begin, size_t end) const
{
uint8_t val = flags_[first_byte];
int i = begin - (first_byte * 8);
auto i = begin - (first_byte * 8);
val <<= i;
val >>= i;
i = (last_byte + 1) * 8 - end;
@ -295,9 +295,8 @@ void tr_bitfield::setRaw(uint8_t const* raw, size_t byte_count)
// ensure any excess bits at the end of the array are set to '0'.
if (byte_count == getBytesNeeded(bit_count_))
{
int const excess_bit_count = byte_count * 8 - bit_count_;
auto const excess_bit_count = byte_count * 8 - bit_count_;
TR_ASSERT(excess_bit_count >= 0);
TR_ASSERT(excess_bit_count <= 7);
if (excess_bit_count != 0)
@ -376,8 +375,8 @@ void tr_bitfield::setSpan(size_t begin, size_t end, bool value)
return;
}
size_t walk = begin >> 3;
size_t const last_byte = end >> 3;
auto walk = begin >> 3;
auto const last_byte = end >> 3;
if (value)
{
@ -395,7 +394,7 @@ void tr_bitfield::setSpan(size_t begin, size_t end, bool value)
if (++walk < last_byte)
{
std::fill_n(std::begin(flags_) + walk, last_byte - walk, 0xff);
std::fill_n(std::data(flags_) + walk, last_byte - walk, 0xff);
}
}
@ -417,7 +416,7 @@ void tr_bitfield::setSpan(size_t begin, size_t end, bool value)
if (++walk < last_byte)
{
std::fill_n(std::begin(flags_) + walk, last_byte - walk, 0);
std::fill_n(std::data(flags_) + walk, last_byte - walk, 0);
}
}