diff --git a/include/libtorrent/add_torrent_params.hpp b/include/libtorrent/add_torrent_params.hpp index dfc74340e..3daaa7b10 100644 --- a/include/libtorrent/add_torrent_params.hpp +++ b/include/libtorrent/add_torrent_params.hpp @@ -78,27 +78,7 @@ namespace libtorrent // which determines the storage mechanism for the downloaded or seeding // data for the torrent. For more information, see the ``storage`` field. explicit add_torrent_params(storage_constructor_type sc = default_storage_constructor) - : version(LIBTORRENT_VERSION_NUM) - , storage_mode(storage_mode_sparse) - , storage(sc) - , userdata(0) - , flags(default_flags) - , max_uploads(-1) - , max_connections(-1) - , upload_limit(-1) - , download_limit(-1) - , total_uploaded(0) - , total_downloaded(0) - , active_time(0) - , finished_time(0) - , seeding_time(0) - , added_time(0) - , completed_time(0) - , last_seen_complete(0) - , num_complete(-1) - , num_incomplete(-1) - , num_downloaded(-1) - {} + : storage(sc) {} // values for the ``flags`` field enum flags_t : std::uint64_t @@ -281,7 +261,7 @@ namespace libtorrent // filled in by the constructor and should be left untouched. It is used // for forward binary compatibility. - int version; + int version = LIBTORRENT_VERSION_NUM; // torrent_info object with the torrent to add. Unless the url or // info_hash is set, this is required to be initialized. @@ -314,7 +294,7 @@ namespace libtorrent // One of the values from storage_mode_t. For more information, see // storage-allocation_. - storage_mode_t storage_mode; + storage_mode_t storage_mode = storage_mode_sparse; // can be used to customize how the data is stored. The default storage // will simply write the data to the files it belongs to, but it could be @@ -327,7 +307,7 @@ namespace libtorrent // The ``userdata`` parameter is optional and will be passed on to the // extension constructor functions, if any // (see torrent_handle::add_extension()). - void* userdata; + void* userdata = nullptr; // can be set to control the initial file priorities when adding a // torrent. The semantics are the same as for @@ -364,7 +344,7 @@ namespace libtorrent // constructor. In order to preserve default behavior when clearing or // setting other flags, make sure to bitwise OR or in a flag or bitwise // AND the inverse of a flag to clear it. - std::uint64_t flags; + std::uint64_t flags = default_flags; // set this to the info hash of the torrent to add in case the info-hash // is the only known property of the torrent. i.e. you don't have a @@ -380,34 +360,34 @@ namespace libtorrent // // -1 means unlimited on these settings just like their counterpart // functions on torrent_handle - int max_uploads; - int max_connections; - int upload_limit; - int download_limit; + int max_uploads = -1; + int max_connections = -1; + int upload_limit = -1; + int download_limit = -1; // the total number of bytes uploaded and downloaded by this torrent so // far. - std::int64_t total_uploaded; - std::int64_t total_downloaded; + std::int64_t total_uploaded = 0; + std::int64_t total_downloaded = 0; // the number of seconds this torrent has spent in started, finished and // seeding state so far, respectively. - int active_time; - int finished_time; - int seeding_time; + int active_time = 0; + int finished_time = 0; + int seeding_time = 0; // if set to a non-zero value, this is the posix time of when this torrent // was first added, including previous runs/sessions. If set to zero, the // internal added_time will be set to the time of when add_torrent() is // called. - time_t added_time; - time_t completed_time; + time_t added_time = 0; + time_t completed_time = 0; // if set to non-zero, initializes the time (expressed in posix time) when // we last saw a seed or peers that together formed a complete copy of the // torrent. If left set to zero, the internal counterpart to this field // will be updated when we see a seed or a distributed copies >= 1.0. - time_t last_seen_complete; + time_t last_seen_complete = 0; // these field can be used to initialize the torrent's cached scrape data. // The scrape data is high level metadata about the current state of the @@ -421,9 +401,9 @@ namespace libtorrent // // Leaving any of these values set to -1 indicates we don't know, or we // have not received any scrape data. - int num_complete; - int num_incomplete; - int num_downloaded; + int num_complete = -1; + int num_incomplete = -1; + int num_downloaded = -1; // URLs can be added to these two lists to specify additional web // seeds to be used by the torrent. If the ``flag_override_web_seeds`` diff --git a/include/libtorrent/disk_io_job.hpp b/include/libtorrent/disk_io_job.hpp index 85ef7abf0..1cc9618b2 100644 --- a/include/libtorrent/disk_io_job.hpp +++ b/include/libtorrent/disk_io_job.hpp @@ -72,6 +72,8 @@ namespace libtorrent { disk_io_job(); ~disk_io_job(); + disk_io_job(disk_io_job const&) = delete; + disk_io_job& operator=(disk_io_job const&) = delete; enum action_t { @@ -133,7 +135,7 @@ namespace libtorrent bool completed(cached_piece_entry const* pe, int block_size); // unique identifier for the peer when reading - void* requester; + void* requester = nullptr; // for write, this points to the data to write, // for read, the data read is returned here @@ -209,24 +211,24 @@ namespace libtorrent enum { operation_failed = -1 }; // return value of operation - std::int32_t ret; + std::int32_t ret = 0; // flags controlling this job - std::uint8_t flags; + std::uint8_t flags = 0; #if TORRENT_USE_ASSERTS - bool in_use:1; + bool in_use = false; // set to true when the job is added to the completion queue. // to make sure we don't add it twice - mutable bool job_posted:1; + mutable bool job_posted = false; // set to true when the callback has been called once // used to make sure we don't call it twice - mutable bool callback_called:1; + mutable bool callback_called = false; // this is true when the job is blocked by a storage_fence - mutable bool blocked:1; + mutable bool blocked = false; #endif }; diff --git a/include/libtorrent/piece_picker.hpp b/include/libtorrent/piece_picker.hpp index 598a2a2b1..de062c9cf 100644 --- a/include/libtorrent/piece_picker.hpp +++ b/include/libtorrent/piece_picker.hpp @@ -725,10 +725,10 @@ namespace libtorrent // the number of seeds. These are not added to // the availability counters of the pieces - int m_seeds; + int m_seeds = 0; // the number of pieces that have passed the hash check - int m_num_passed; + int m_num_passed = 0; // this vector contains all piece indices that are pickable // sorted by priority. Pieces are in random random order @@ -761,41 +761,41 @@ namespace libtorrent // this is a free-list. std::vector m_free_block_infos; - std::uint16_t m_blocks_per_piece; - std::uint16_t m_blocks_in_last_piece; + std::uint16_t m_blocks_per_piece = 0; + std::uint16_t m_blocks_in_last_piece = 0; // the number of filtered pieces that we don't already // have. total_number_of_pieces - number_of_pieces_we_have // - num_filtered is supposed to the number of pieces // we still want to download - int m_num_filtered; + int m_num_filtered = 0; // the number of pieces we have that also are filtered - int m_num_have_filtered; + int m_num_have_filtered = 0; // we have all pieces in the range [0, m_cursor) // m_cursor is the first piece we don't have - int m_cursor; + int m_cursor = 0; // we have all pieces in the range [m_reverse_cursor, end) // m_reverse_cursor is the first piece where we also have // all the subsequent pieces - int m_reverse_cursor; + int m_reverse_cursor = 0; // the number of pieces we have (i.e. passed + flushed). // This includes pieces that we have filtered but still have - int m_num_have; + int m_num_have = 0; // this is the number of partial download pieces // that may be caused by pad files. We raise the limit // of number of partial pieces by this amount, to not // prioritize pieces that intersect pad files for no // apparent reason - int m_num_pad_files; + int m_num_pad_files = 0; // if this is set to true, it means update_pieces() // has to be called before accessing m_pieces. - mutable bool m_dirty; + mutable bool m_dirty = false; public: #ifdef TORRENT_OPTIMIZE_MEMORY_USAGE diff --git a/include/libtorrent/utp_socket_manager.hpp b/include/libtorrent/utp_socket_manager.hpp index 7b103d203..8acdb8312 100644 --- a/include/libtorrent/utp_socket_manager.hpp +++ b/include/libtorrent/utp_socket_manager.hpp @@ -149,9 +149,9 @@ namespace libtorrent std::vector m_stalled_sockets; // the last socket we received a packet on - utp_socket_impl* m_last_socket; + utp_socket_impl* m_last_socket = nullptr; - int m_new_connection; + int m_new_connection = -1; aux::session_settings const& m_sett; @@ -161,15 +161,15 @@ namespace libtorrent // the timestamp for the last time we updated // the routing table - mutable time_point m_last_route_update; + mutable time_point m_last_route_update = min_time(); // cache of interfaces mutable std::vector m_interfaces; - mutable time_point m_last_if_update; + mutable time_point m_last_if_update = min_time(); // the buffer size of the socket. This is used // to now lower the buffer size - int m_sock_buf_size; + int m_sock_buf_size = 0; // stats counters counters& m_counters; @@ -177,7 +177,7 @@ namespace libtorrent io_service& m_ios; std::array m_restrict_mtu; - int m_mtu_idx; + int m_mtu_idx = 0; // this is passed on to the instantiate connection // if this is non-nullptr it will create SSL connections over uTP diff --git a/src/disk_io_job.cpp b/src/disk_io_job.cpp index e2d368a2b..f58c7b1e9 100644 --- a/src/disk_io_job.cpp +++ b/src/disk_io_job.cpp @@ -36,17 +36,8 @@ POSSIBILITY OF SUCH DAMAGE. namespace libtorrent { disk_io_job::disk_io_job() - : requester(nullptr) - , piece(0) + : piece(0) , action(read) - , ret(0) - , flags(0) -#if TORRENT_USE_ASSERTS - , in_use(false) - , job_posted(false) - , callback_called(false) - , blocked(false) -#endif { buffer.disk_block = nullptr; d.io.offset = 0; diff --git a/src/piece_picker.cpp b/src/piece_picker.cpp index 72fb3d863..7f8c5787c 100644 --- a/src/piece_picker.cpp +++ b/src/piece_picker.cpp @@ -65,18 +65,7 @@ namespace libtorrent const piece_block piece_block::invalid((std::numeric_limits::max)(), (std::numeric_limits::max)()); piece_picker::piece_picker() - : m_seeds(0) - , m_num_passed(0) - , m_priority_boundaries(1, int(m_pieces.size())) - , m_blocks_per_piece(0) - , m_blocks_in_last_piece(0) - , m_num_filtered(0) - , m_num_have_filtered(0) - , m_cursor(0) - , m_reverse_cursor(0) - , m_num_have(0) - , m_num_pad_files(0) - , m_dirty(false) + : m_priority_boundaries(1, int(m_pieces.size())) { #ifdef TORRENT_PICKER_LOG std::cerr << "[" << this << "] " << "new piece_picker" << std::endl; diff --git a/src/utp_socket_manager.cpp b/src/utp_socket_manager.cpp index ebfc14bae..4c41f36f2 100644 --- a/src/utp_socket_manager.cpp +++ b/src/utp_socket_manager.cpp @@ -57,15 +57,9 @@ namespace libtorrent , void* ssl_context) : m_send_fun(send_fun) , m_cb(cb) - , m_last_socket(nullptr) - , m_new_connection(-1) , m_sett(sett) - , m_last_route_update(min_time()) - , m_last_if_update(min_time()) - , m_sock_buf_size(0) , m_counters(cnt) , m_ios(ios) - , m_mtu_idx(0) , m_ssl_context(ssl_context) { m_restrict_mtu.fill(65536);