What changed, and why it matters
This commit is a routine code cleanup: it replaces the old Boost 'BOOST_FOREACH' macro with modern C++11 range-based 'for' loops across several source and test files. There is no functional change, no bug fix, and no security relevance in the diff itself.
No security action required. Treat as normal refactoring/cleanup.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The merge commit removes ‘#include
Changed components
contrib/epee/include/net/abstract_tcp_server2.inlcontrib/epee/include/serialization/keyvalue_serialization.hcontrib/epee/include/serialization/keyvalue_serialization_overloads.htests/core_tests/block_reward.cpptests/core_tests/chain_switch_1.cpptests/core_tests/chaingen.cpptests/core_tests/chaingen_main.cpptests/core_tests/tx_validation.cpptests/core_tests/wallet_tools.cpptests/functional_tests/transactions_flow_test.cpptests/trezor/trezor_tests.cpptests/unit_tests/serialization.cpptests/unit_tests/varint.cppInspect captured patch +40 / −43
### contrib/epee/include/net/abstract_tcp_server2.inl
@@ -36,7 +36,6 @@
#include <boost/asio/read.hpp>
#include <boost/asio/placeholders.hpp>
#include <boost/asio/ip/v6_only.hpp>
-#include <boost/foreach.hpp>
#include <boost/uuid/random_generator.hpp>
#include <boost/uuid/uuid_io.hpp>
#include <boost/chrono.hpp>
@@ -1572,7 +1571,7 @@ namespace net_utils
{
TRY_ENTRY();
CRITICAL_REGION_LOCAL(m_threads_lock);
- BOOST_FOREACH(boost::shared_ptr<boost::thread>& thp, m_threads)
+ for (const boost::shared_ptr<boost::thread>& thp : m_threads)
{
if(thp->get_id() == boost::this_thread::get_id())
return true;
### contrib/epee/include/serialization/keyvalue_serialization.h
@@ -28,7 +28,6 @@
#include <type_traits>
#include <boost/utility/value_init.hpp>
-#include <boost/foreach.hpp>
#include "misc_log_ex.h"
#include "keyvalue_serialization_overloads.h"
### contrib/epee/include/serialization/keyvalue_serialization_overloads.h
@@ -122,7 +122,7 @@ namespace epee
std::string mb;
mb.resize(sizeof(typename stl_container::value_type)*container.size());
char *p_elem = mb.data();
- BOOST_FOREACH(const typename stl_container::value_type& v, container)
+ for (const typename stl_container::value_type& v : container)
{
memcpy(p_elem, std::addressof(v), sizeof(typename stl_container::value_type));
p_elem += sizeof(typename stl_container::value_type);
### tests/core_tests/block_reward.cpp
@@ -110,7 +110,7 @@ namespace
uint64_t get_tx_out_amount(const transaction& tx)
{
uint64_t amount = 0;
- BOOST_FOREACH(auto& o, tx.vout)
+ for (const auto& o : tx.vout)
amount += o.amount;
return amount;
}
### tests/core_tests/chain_switch_1.cpp
@@ -181,7 +181,7 @@ bool gen_chain_switch_1::check_split_switched(cryptonote::core& c, size_t ev_ind
CHECK_EQ(2, c.get_alternative_blocks_count());
// Some blocks that were in main chain are in alt chain now
- BOOST_FOREACH(block b, alt_blocks)
+ for (const block &b : alt_blocks)
{
CHECK_TEST_CONDITION(m_chain_1.end() != std::find(m_chain_1.begin(), m_chain_1.end(), b));
}
### tests/core_tests/chaingen.cpp
@@ -173,7 +173,7 @@ static std::unique_ptr<cryptonote::BlockchainAndPool> init_blockchain(const std:
auto bdb = new TestDB();
- BOOST_FOREACH(const test_event_entry &ev, events)
+ for(const test_event_entry &ev : events)
{
if (typeid(block) != ev.type())
{
@@ -212,7 +212,7 @@ void test_generator::get_last_n_block_weights(std::vector<size_t>& block_weights
{
std::vector<block_info> blockchain;
get_block_chain(blockchain, head, n);
- BOOST_FOREACH(auto& bi, blockchain)
+ for (const auto& bi : blockchain)
{
block_weights.push_back(bi.block_weight);
}
@@ -251,7 +251,7 @@ bool test_generator::construct_block(cryptonote::block& blk, uint64_t height, co
blk.prev_id = prev_id;
blk.tx_hashes.reserve(tx_list.size());
- BOOST_FOREACH(const transaction &tx, tx_list)
+ for(const transaction &tx : tx_list)
{
crypto::hash tx_hash;
get_transaction_hash(tx, tx_hash);
@@ -260,7 +260,7 @@ bool test_generator::construct_block(cryptonote::block& blk, uint64_t height, co
uint64_t total_fee = 0;
size_t txs_weight = 0;
- BOOST_FOREACH(auto& tx, tx_list)
+ for (const auto& tx : tx_list)
{
uint64_t fee = 0;
bool r = get_tx_fee(tx, fee);
@@ -429,7 +429,7 @@ namespace
uint64_t get_inputs_amount(const vector<tx_source_entry> &s)
{
uint64_t r = 0;
- BOOST_FOREACH(const tx_source_entry &e, s)
+ for (const tx_source_entry &e : s)
{
r += e.amount;
}
@@ -440,11 +440,11 @@ namespace
bool init_output_indices(map_output_idx_t& outs, std::map<uint64_t, std::vector<size_t> >& outs_mine, const std::vector<cryptonote::block>& blockchain, const map_hash2tx_t& mtx, const cryptonote::account_base& from) {
- BOOST_FOREACH (const block& blk, blockchain) {
+ for (const block& blk : blockchain) {
vector<const transaction*> vtx;
vtx.push_back(&blk.miner_tx);
- BOOST_FOREACH(const crypto::hash &h, blk.tx_hashes) {
+ for (const crypto::hash &h : blk.tx_hashes) {
const map_hash2tx_t::const_iterator cit = mtx.find(h);
if (mtx.end() == cit)
throw std::runtime_error("block contains an unknown tx hash");
@@ -485,7 +485,7 @@ bool init_output_indices(map_output_idx_t& outs, std::map<uint64_t, std::vector<
bool init_spent_output_indices(map_output_idx_t& outs, map_output_t& outs_mine, const std::vector<cryptonote::block>& blockchain, const map_hash2tx_t& mtx, const cryptonote::account_base& from) {
- BOOST_FOREACH (const map_output_t::value_type &o, outs_mine) {
+ for (const map_output_t::value_type &o : outs_mine) {
for (size_t i = 0; i < o.second.size(); ++i) {
output_index &oi = outs[o.first][o.second[i]];
@@ -498,9 +498,9 @@ bool init_spent_output_indices(map_output_idx_t& outs, map_output_t& outs_mine,
generate_key_image_helper(from.get_keys(), subaddresses, out_key, get_tx_pub_key_from_extra(*oi.p_tx), get_additional_tx_pub_keys_from_extra(*oi.p_tx), oi.out_no, in_ephemeral, img, hw::get_device(("default")));
// lookup for this key image in the events vector
- BOOST_FOREACH(auto& tx_pair, mtx) {
+ for (const auto& tx_pair : mtx) {
const transaction& tx = *tx_pair.second;
- BOOST_FOREACH(const txin_v &in, tx.vin) {
+ for (const txin_v &in : tx.vin) {
if (typeid(txin_to_key) == in.type()) {
const txin_to_key &itk = boost::get<txin_to_key>(in);
if (itk.k_image == img) {
@@ -578,8 +578,9 @@ bool fill_tx_sources(std::vector<tx_source_entry>& sources, const std::vector<te
uint64_t head_height = check_unlock_time ? get_block_height(blk_head) : std::numeric_limits<uint64_t>::max() - 1;
uint64_t sources_amount = 0;
bool sources_found = false;
- BOOST_REVERSE_FOREACH(const map_output_t::value_type o, outs_mine)
+ for (auto o_it = outs_mine.crbegin(); o_it != outs_mine.crend(); ++o_it)
{
+ const map_output_t::value_type &o = *o_it;
for (size_t i = 0; i < o.second.size() && !sources_found; ++i)
{
size_t sender_out = o.second[i];
@@ -643,7 +644,7 @@ void block_tracker::process(const std::vector<cryptonote::block>& blockchain, co
std::vector<const cryptonote::block*> blks;
blks.reserve(blockchain.size());
- BOOST_FOREACH (const block& blk, blockchain) {
+ for (const block& blk : blockchain) {
auto hsh = get_block_hash(blk);
auto it = m_blocks.find(hsh);
if (it == m_blocks.end()){
@@ -658,11 +659,11 @@ void block_tracker::process(const std::vector<cryptonote::block>& blockchain, co
void block_tracker::process(const std::vector<const cryptonote::block*>& blockchain, const map_hash2tx_t& mtx)
{
- BOOST_FOREACH (const block* blk, blockchain) {
+ for (const block* blk : blockchain) {
vector<const transaction*> vtx;
vtx.push_back(&(blk->miner_tx));
- BOOST_FOREACH(const crypto::hash &h, blk->tx_hashes) {
+ for (const crypto::hash &h : blk->tx_hashes) {
const map_hash2tx_t::const_iterator cit = mtx.find(h);
CHECK_AND_ASSERT_THROW_MES(mtx.end() != cit, "block contains an unknown tx hash");
vtx.push_back(cit->second);
@@ -1129,7 +1130,7 @@ uint64_t get_balance(const cryptonote::account_base& addr, const std::vector<cry
if (!init_spent_output_indices(outs, outs_mine, blockchain, confirmed_txs, addr))
return false;
- BOOST_FOREACH (const map_output_t::value_type &o, outs_mine) {
+ for (const map_output_t::value_type &o : outs_mine) {
for (size_t i = 0; i < o.second.size(); ++i) {
if (outs[o.first][o.second[i]].spent)
continue;
@@ -1187,15 +1188,15 @@ bool extract_hard_forks_from_blocks(const std::vector<test_event_entry>& events,
void get_confirmed_txs(const std::vector<cryptonote::block>& blockchain, const map_hash2tx_t& mtx, map_hash2tx_t& confirmed_txs)
{
std::unordered_set<crypto::hash> confirmed_hashes;
- BOOST_FOREACH(const block& blk, blockchain)
+ for (const block& blk : blockchain)
{
- BOOST_FOREACH(const crypto::hash& tx_hash, blk.tx_hashes)
+ for (const crypto::hash& tx_hash : blk.tx_hashes)
{
confirmed_hashes.insert(tx_hash);
}
}
- BOOST_FOREACH(const auto& tx_pair, mtx)
+ for (const auto& tx_pair : mtx)
{
if (0 != confirmed_hashes.count(tx_pair.first))
{
@@ -1247,7 +1248,7 @@ bool trim_block_chain(std::vector<const cryptonote::block*>& blockchain, const c
uint64_t num_blocks(const std::vector<test_event_entry>& events)
{
uint64_t res = 0;
- BOOST_FOREACH(const test_event_entry& ev, events)
+ for (const test_event_entry& ev : events)
{
if (typeid(block) == ev.type())
{
@@ -1274,7 +1275,7 @@ cryptonote::block get_head_block(const std::vector<test_event_entry>& events)
bool find_block_chain(const std::vector<test_event_entry>& events, std::vector<cryptonote::block>& blockchain, map_hash2tx_t& mtx, const crypto::hash& head) {
std::unordered_map<crypto::hash, const block*> block_index;
- BOOST_FOREACH(const test_event_entry& ev, events)
+ for (const test_event_entry& ev : events)
{
if (typeid(block) == ev.type())
{
@@ -1307,7 +1308,7 @@ bool find_block_chain(const std::vector<test_event_entry>& events, std::vector<c
bool find_block_chain(const std::vector<test_event_entry>& events, std::vector<const cryptonote::block*>& blockchain, map_hash2tx_t& mtx, const crypto::hash& head) {
std::unordered_map<crypto::hash, const block*> block_index;
- BOOST_FOREACH(const test_event_entry& ev, events)
+ for (const test_event_entry& ev : events)
{
if (typeid(block) == ev.type())
{
### tests/core_tests/chaingen_main.cpp
@@ -301,7 +301,7 @@ int main(int argc, char* argv[])
if (!failed_tests.empty())
{
MLOG(level, "FAILED TESTS:");
- BOOST_FOREACH(auto test_name, failed_tests)
+ for (const auto &test_name : failed_tests)
{
MLOG(level, " " << test_name);
}
### tests/core_tests/tx_validation.cpp
@@ -55,7 +55,7 @@ namespace
void step2_fill_inputs(const account_keys& sender_account_keys, const std::vector<tx_source_entry>& sources)
{
- BOOST_FOREACH(const tx_source_entry& src_entr, sources)
+ for (const tx_source_entry& src_entr : sources)
{
m_in_contexts.push_back(keypair());
keypair& in_ephemeral = m_in_contexts.back();
@@ -71,7 +71,7 @@ namespace
input_to_key.k_image = img;
// fill outputs array and use relative offsets
- BOOST_FOREACH(const tx_source_entry::output_entry& out_entry, src_entr.outputs)
+ for (const tx_source_entry::output_entry& out_entry : src_entr.outputs)
input_to_key.key_offsets.push_back(out_entry.first);
input_to_key.key_offsets = absolute_output_offsets_to_relative(input_to_key.key_offsets);
@@ -82,7 +82,7 @@ namespace
void step3_fill_outputs(const std::vector<tx_destination_entry>& destinations)
{
size_t output_index = 0;
- BOOST_FOREACH(const tx_destination_entry& dst_entr, destinations)
+ for (const tx_destination_entry& dst_entr : destinations)
{
crypto::key_derivation derivation;
crypto::public_key out_eph_public_key;
@@ -109,12 +109,12 @@ namespace
m_tx.signatures.clear();
size_t i = 0;
- BOOST_FOREACH(const tx_source_entry& src_entr, sources)
+ for (const tx_source_entry& src_entr : sources)
{
std::vector<const crypto::public_key*> keys_ptrs;
std::vector<crypto::public_key> keys(src_entr.outputs.size());
size_t j = 0;
- BOOST_FOREACH(const tx_source_entry::output_entry& o, src_entr.outputs)
+ for (const tx_source_entry::output_entry& o : src_entr.outputs)
{
keys[j] = rct::rct2pk(o.second.dest);
keys_ptrs.push_back(&keys[j]);
### tests/core_tests/wallet_tools.cpp
@@ -219,7 +219,7 @@ void wallet_tools::gen_block_data(block_tracker &bt, const cryptonote::block *bl
vtx.push_back(&(bl->miner_tx));
height = boost::get<txin_gen>(*bl->miner_tx.vin.begin()).height;
- BOOST_FOREACH(const crypto::hash &h, bl->tx_hashes) {
+ for (const crypto::hash &h : bl->tx_hashes) {
const map_hash2tx_t::const_iterator cit = mtx.find(h);
CHECK_AND_ASSERT_THROW_MES(mtx.end() != cit, "block contains an unknown tx hash @ " << height << ", " << h);
vtx.push_back(cit->second);
@@ -237,7 +237,7 @@ void wallet_tools::gen_block_data(block_tracker &bt, const cryptonote::block *bl
o_indices.reserve(bl->tx_hashes.size() + 1);
size_t cur = 0;
- BOOST_FOREACH(const transaction *tx, vtx){
+ for (const transaction *tx : vtx){
cur += 1;
o_indices.emplace_back();
bt.process(bl, tx, cur - 1);
### tests/functional_tests/transactions_flow_test.cpp
@@ -100,7 +100,7 @@ uint64_t get_money_in_first_transfers(const tools::wallet2::transfer_container&
{
uint64_t summ = 0;
size_t count = 0;
- BOOST_FOREACH(const tools::wallet2::transfer_details& td, incoming_transfers)
+ for (const tools::wallet2::transfer_details& td : incoming_transfers)
{
summ += td.m_tx.vout[td.m_internal_output_index].amount;
if(++count >= n_transfers)
@@ -189,7 +189,7 @@ bool transactions_flow_test(std::string& working_folder,
{
//lets go!
size_t count = 0;
- BOOST_FOREACH(tools::wallet2::transfer_details& td, incoming_transfers)
+ for (const tools::wallet2::transfer_details& td : incoming_transfers)
{
cryptonote::transaction tx_s;
bool r = do_send_money(w1, w1, 0, td.m_tx.vout[td.m_internal_output_index].amount - TEST_FEE, tx_s, 50);
@@ -278,14 +278,14 @@ bool transactions_flow_test(std::string& working_folder,
{
tools::wallet2::transfer_container tc;
w2.get_transfers(tc);
- BOOST_FOREACH(tools::wallet2::transfer_details& td, tc)
+ for (const tools::wallet2::transfer_details& td : tc)
{
auto it = txs.find(td.m_txid);
CHECK_AND_ASSERT_MES(it != txs.end(), false, "transaction not found in local cache");
it->second.m_received_count += 1;
}
- BOOST_FOREACH(auto& tx_pair, txs)
+ for (const auto& tx_pair : txs)
{
if(tx_pair.second.m_received_count != 1)
{
### tests/trezor/trezor_tests.cpp
@@ -246,7 +246,7 @@ int main(int argc, char* argv[])
if (!failed_tests.empty())
{
MLOG(level, "FAILED TESTS:");
- BOOST_FOREACH(auto test_name, failed_tests)
+ for (const auto &test_name : failed_tests)
{
MLOG(level, " " << test_name);
}
### tests/unit_tests/serialization.cpp
@@ -33,7 +33,6 @@
#include <cstdio>
#include <iostream>
#include <vector>
-#include <boost/foreach.hpp>
#include <boost/archive/portable_binary_iarchive.hpp>
#include <boost/type_traits/make_unsigned.hpp>
#include "cryptonote_basic/cryptonote_basic.h"
@@ -394,7 +393,7 @@ namespace
std::vector<T> linearize_vector2(const std::vector< std::vector<T> >& vec_vec)
{
std::vector<T> res;
- BOOST_FOREACH(const auto& vec, vec_vec)
+ for (const auto& vec : vec_vec)
{
res.insert(res.end(), vec.begin(), vec.end());
}
### tests/unit_tests/varint.cpp
@@ -33,7 +33,6 @@
#include <cstdio>
#include <iostream>
#include <vector>
-#include <boost/foreach.hpp>
#include "cryptonote_basic/cryptonote_basic.h"
#include "cryptonote_basic/cryptonote_basic_impl.h"
#include "serialization/binary_archive.h"Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.