Skip to content

Commit

Permalink
Use const and narrow_cast.
Browse files Browse the repository at this point in the history
  • Loading branch information
evoskuil committed Apr 10, 2024
1 parent a4d3985 commit a3f2261
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/stream/binary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ binary binary::from_string(const std::string bits) NOEXCEPT
if (!binary::is_base2(bits))
return {};

auto length = bits.length();
const auto length = bits.length();
data_chunk data(ceilinged_divide(length, byte_bits), pad);
write::bits::copy writer(data);

Expand Down
10 changes: 5 additions & 5 deletions src/wallet/addresses/stealth_address.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ stealth_address stealth_address::from_stealth(

// [scan_pubkey:33]
++iterator;
auto scan_key_begin = iterator;
const auto scan_key_begin = iterator;
iterator += ec_compressed_size;
ec_compressed scan_key;
std::copy_n(scan_key_begin, ec_compressed_size, scan_key.begin());
Expand All @@ -143,7 +143,7 @@ stealth_address stealth_address::from_stealth(
ec_compressed point;
for (auto key = 0; key < spend_keys_count; ++key)
{
auto spend_key_begin = iterator;
const auto spend_key_begin = iterator;
std::advance(iterator, ec_compressed_size);
std::copy_n(spend_key_begin, ec_compressed_size, point.begin());
spend_keys.push_back(point);
Expand Down Expand Up @@ -189,7 +189,7 @@ stealth_address stealth_address::from_stealth(const binary& filter,
return {};

// Guard against prefix too long.
auto prefix_number_bits = filter.bits();
const auto prefix_number_bits = filter.bits();
if (prefix_number_bits > max_filter_bits)
return {};

Expand Down Expand Up @@ -262,7 +262,7 @@ data_chunk stealth_address::to_chunk() const NOEXCEPT
extend(address, scan_key_);

// Spend_pubkeys must have been guarded against a max size of 255.
auto number_spend_pubkeys = static_cast<uint8_t>(spend_keys_.size());
auto number_spend_pubkeys = narrow_cast<uint8_t>(spend_keys_.size());

// Adjust for key reuse.
if (reuse_key())
Expand All @@ -279,7 +279,7 @@ data_chunk stealth_address::to_chunk() const NOEXCEPT

// The prefix must be guarded against a size greater than 32
// so that the bitfield can convert into uint32_t and sized by uint8_t.
const auto prefix_number_bits = static_cast<uint8_t>(filter_.bits());
const auto prefix_number_bits = narrow_cast<uint8_t>(filter_.bits());

// Serialize the prefix bytes/blocks.
address.push_back(prefix_number_bits);
Expand Down

0 comments on commit a3f2261

Please sign in to comment.