From c66f4cc62ad9b0d4550ba820fbce343944de1353 Mon Sep 17 00:00:00 2001 From: arvidn Date: Thu, 28 Sep 2017 01:11:20 -0700 Subject: [PATCH] fix some warnings, mostly 0 -> nullptr --- include/libtorrent/assert.hpp | 4 ++-- include/libtorrent/aux_/escape_string.hpp | 2 +- include/libtorrent/bitfield.hpp | 6 +++--- include/libtorrent/block_cache.hpp | 5 ++--- include/libtorrent/copy_ptr.hpp | 12 ++++++------ include/libtorrent/disk_buffer_holder.hpp | 2 +- include/libtorrent/file_storage.hpp | 4 ++-- include/libtorrent/http_connection.hpp | 4 ++-- include/libtorrent/lazy_entry.hpp | 8 ++++---- include/libtorrent/magnet_uri.hpp | 2 +- include/libtorrent/peer_connection.hpp | 2 +- include/libtorrent/piece_picker.hpp | 2 +- include/libtorrent/session_handle.hpp | 4 ++-- include/libtorrent/sha1_hash.hpp | 2 +- include/libtorrent/torrent.hpp | 6 +++--- include/libtorrent/torrent_handle.hpp | 2 +- include/libtorrent/tracker_manager.hpp | 5 +---- include/libtorrent/utp_stream.hpp | 10 +++++----- src/disk_io_thread.cpp | 4 +++- src/settings_pack.cpp | 2 +- 20 files changed, 43 insertions(+), 45 deletions(-) diff --git a/include/libtorrent/assert.hpp b/include/libtorrent/assert.hpp index 00503dfba..8ccabf3b8 100644 --- a/include/libtorrent/assert.hpp +++ b/include/libtorrent/assert.hpp @@ -81,10 +81,10 @@ extern char const* libtorrent_assert_log; #ifndef TORRENT_USE_SYSTEM_ASSERTS #define TORRENT_ASSERT_PRECOND(x) \ - do { if (x) {} else assert_fail(#x, __LINE__, __FILE__, TORRENT_FUNCTION, 0, 1); } TORRENT_WHILE_0 + do { if (x) {} else assert_fail(#x, __LINE__, __FILE__, TORRENT_FUNCTION, nullptr, 1); } TORRENT_WHILE_0 #define TORRENT_ASSERT(x) \ - do { if (x) {} else assert_fail(#x, __LINE__, __FILE__, TORRENT_FUNCTION, 0, 0); } TORRENT_WHILE_0 + do { if (x) {} else assert_fail(#x, __LINE__, __FILE__, TORRENT_FUNCTION, nullptr, 0); } TORRENT_WHILE_0 #if TORRENT_USE_IOSTREAM #define TORRENT_ASSERT_VAL(x, y) \ diff --git a/include/libtorrent/aux_/escape_string.hpp b/include/libtorrent/aux_/escape_string.hpp index 06b81ab4a..74e255d91 100644 --- a/include/libtorrent/aux_/escape_string.hpp +++ b/include/libtorrent/aux_/escape_string.hpp @@ -86,7 +86,7 @@ namespace libtorrent { TORRENT_EXTRA_EXPORT std::string base32decode(string_view s); TORRENT_EXTRA_EXPORT string_view url_has_argument( - string_view url, std::string argument, std::string::size_type* out_pos = 0); + string_view url, std::string argument, std::string::size_type* out_pos = nullptr); // replaces \ with / TORRENT_EXTRA_EXPORT void convert_path_to_posix(std::string& path); diff --git a/include/libtorrent/bitfield.hpp b/include/libtorrent/bitfield.hpp index 7f36e42c9..2b8cafb1f 100644 --- a/include/libtorrent/bitfield.hpp +++ b/include/libtorrent/bitfield.hpp @@ -176,7 +176,7 @@ namespace libtorrent { const_iterator operator--(int) { const_iterator ret(*this); dec(); return ret; } - const_iterator(): buf(0), bit(0x80000000) {} + const_iterator() {} bool operator==(const_iterator const& rhs) const { return buf == rhs.buf && bit == rhs.bit; } @@ -212,8 +212,8 @@ namespace libtorrent { } const_iterator(std::uint32_t const* ptr, int offset) : buf(ptr), bit(0x80000000 >> offset) {} - std::uint32_t const* buf; - std::uint32_t bit; + std::uint32_t const* buf = nullptr; + std::uint32_t bit = 0x80000000; }; const_iterator begin() const { return const_iterator(m_buf ? buf() : nullptr, 0); } diff --git a/include/libtorrent/block_cache.hpp b/include/libtorrent/block_cache.hpp index ca708f037..4de81bb74 100644 --- a/include/libtorrent/block_cache.hpp +++ b/include/libtorrent/block_cache.hpp @@ -119,15 +119,14 @@ namespace aux { struct cached_block_entry { cached_block_entry() - : buf(0) - , refcount(0) + : refcount(0) , dirty(0) , pending(0) , cache_hit(0) { } - char* buf; + char* buf = nullptr; static constexpr int max_refcount = (1 << 29) - 1; diff --git a/include/libtorrent/copy_ptr.hpp b/include/libtorrent/copy_ptr.hpp index c17ce3d5d..d605d45c8 100644 --- a/include/libtorrent/copy_ptr.hpp +++ b/include/libtorrent/copy_ptr.hpp @@ -38,15 +38,15 @@ namespace libtorrent { template struct copy_ptr { - copy_ptr(): m_ptr(0) {} + copy_ptr(): m_ptr(nullptr) {} explicit copy_ptr(T* t): m_ptr(t) {} - copy_ptr(copy_ptr const& p): m_ptr(p.m_ptr ? new T(*p.m_ptr) : 0) {} - void reset(T* t = 0) { delete m_ptr; m_ptr = t; } + copy_ptr(copy_ptr const& p): m_ptr(p.m_ptr ? new T(*p.m_ptr) : nullptr) {} + void reset(T* t = nullptr) { delete m_ptr; m_ptr = t; } copy_ptr& operator=(copy_ptr const& p) { if (m_ptr == p.m_ptr) return *this; delete m_ptr; - m_ptr = p.m_ptr ? new T(*p.m_ptr) : 0; + m_ptr = p.m_ptr ? new T(*p.m_ptr) : nullptr; return *this; } T* operator->() { return m_ptr; } @@ -59,10 +59,10 @@ namespace libtorrent { m_ptr = p.m_ptr; p.m_ptr = tmp; } - explicit operator bool() const { return m_ptr != 0; } + explicit operator bool() const { return m_ptr != nullptr; } ~copy_ptr() { delete m_ptr; } private: - T* m_ptr; + T* m_ptr = nullptr; }; } diff --git a/include/libtorrent/disk_buffer_holder.hpp b/include/libtorrent/disk_buffer_holder.hpp index 9188fe552..b50de93e1 100644 --- a/include/libtorrent/disk_buffer_holder.hpp +++ b/include/libtorrent/disk_buffer_holder.hpp @@ -92,7 +92,7 @@ namespace libtorrent { // set the holder object to hold the specified buffer // (or nullptr by default). If it's already holding a // disk buffer, it will first be freed. - void reset(char* buf = 0); + void reset(char* buf = nullptr); void reset(aux::block_cache_reference const& ref, char* buf); // swap pointers of two disk buffer holders. diff --git a/include/libtorrent/file_storage.hpp b/include/libtorrent/file_storage.hpp index a5771c34f..282bc844a 100644 --- a/include/libtorrent/file_storage.hpp +++ b/include/libtorrent/file_storage.hpp @@ -270,7 +270,7 @@ namespace libtorrent { // can be changed by calling ``set_name``. void add_file_borrow(string_view filename , std::string const& path, std::int64_t file_size - , file_flags_t file_flags = {}, char const* filehash = 0 + , file_flags_t file_flags = {}, char const* filehash = nullptr , std::int64_t mtime = 0, string_view symlink_path = string_view()); void add_file(std::string const& path, std::int64_t file_size , file_flags_t file_flags = {} @@ -284,7 +284,7 @@ namespace libtorrent { TORRENT_DEPRECATED void add_file_borrow(char const* filename, int filename_len , std::string const& path, std::int64_t file_size - , file_flags_t file_flags = {}, char const* filehash = 0 + , file_flags_t file_flags = {}, char const* filehash = nullptr , std::int64_t mtime = 0, string_view symlink_path = string_view()); TORRENT_DEPRECATED void add_file(file_entry const& fe, char const* filehash = nullptr); diff --git a/include/libtorrent/http_connection.hpp b/include/libtorrent/http_connection.hpp index 87ac15819..4bd69af58 100644 --- a/include/libtorrent/http_connection.hpp +++ b/include/libtorrent/http_connection.hpp @@ -105,7 +105,7 @@ struct TORRENT_EXTRA_EXPORT http_connection , boost::optional
const& bind_addr = boost::optional
() , resolver_flags resolve_flags = resolver_flags{}, std::string const& auth_ = std::string() #if TORRENT_USE_I2P - , i2p_connection* i2p_conn = 0 + , i2p_connection* i2p_conn = nullptr #endif ); @@ -115,7 +115,7 @@ struct TORRENT_EXTRA_EXPORT http_connection , boost::optional
const& bind_addr = boost::optional
() , resolver_flags resolve_flags = resolver_flags{} #if TORRENT_USE_I2P - , i2p_connection* i2p_conn = 0 + , i2p_connection* i2p_conn = nullptr #endif ); diff --git a/include/libtorrent/lazy_entry.hpp b/include/libtorrent/lazy_entry.hpp index bbe7569a5..a0cc5b254 100644 --- a/include/libtorrent/lazy_entry.hpp +++ b/include/libtorrent/lazy_entry.hpp @@ -83,7 +83,7 @@ namespace libtorrent { // which will be set to the byte offset into the buffer where an error occurred, // in case the function fails. TORRENT_DEPRECATED_EXPORT int lazy_bdecode(char const* start, char const* end - , lazy_entry& ret, error_code& ec, int* error_pos = 0 + , lazy_entry& ret, error_code& ec, int* error_pos = nullptr , int depth_limit = 1000, int item_limit = 1000000); // for backwards compatibility, does not report error code @@ -142,7 +142,7 @@ namespace libtorrent { }; // internal - lazy_entry() : m_begin(0), m_len(0), m_size(0), m_type(none_t) + lazy_entry() : m_size(0), m_type(none_t) { m_data.start = nullptr; } // tells you which specific type this lazy entry has. @@ -370,11 +370,11 @@ namespace libtorrent { // used for dictionaries and lists to record the range // in the original buffer they are based on - char const* m_begin; + char const* m_begin = nullptr; // the number of bytes this entry extends in the // bencoded buffer - std::uint32_t m_len; + std::uint32_t m_len = 0; // if list or dictionary, the number of items std::uint32_t m_size:29; diff --git a/include/libtorrent/magnet_uri.hpp b/include/libtorrent/magnet_uri.hpp index 66400229f..dac987542 100644 --- a/include/libtorrent/magnet_uri.hpp +++ b/include/libtorrent/magnet_uri.hpp @@ -61,7 +61,7 @@ namespace libtorrent { , storage_mode_t storage_mode = storage_mode_sparse , bool paused = false , storage_constructor_type sc = default_storage_constructor - , void* userdata = 0); + , void* userdata = nullptr); // deprecated in 0.16. Instead, pass in the magnet link as add_torrent_params::url TORRENT_DEPRECATED_EXPORT diff --git a/include/libtorrent/peer_connection.hpp b/include/libtorrent/peer_connection.hpp index b860962e2..e2090d83e 100644 --- a/include/libtorrent/peer_connection.hpp +++ b/include/libtorrent/peer_connection.hpp @@ -654,7 +654,7 @@ namespace aux { #endif time_t last_seen_complete() const { return m_last_seen_complete; } - void set_last_seen_complete(int ago) { m_last_seen_complete = ::time(0) - ago; } + void set_last_seen_complete(int ago) { m_last_seen_complete = ::time(nullptr) - ago; } std::int64_t uploaded_in_last_round() const { return m_statistics.total_payload_upload() - m_uploaded_at_last_round; } diff --git a/include/libtorrent/piece_picker.hpp b/include/libtorrent/piece_picker.hpp index 2bfd17bf8..7bbaeb735 100644 --- a/include/libtorrent/piece_picker.hpp +++ b/include/libtorrent/piece_picker.hpp @@ -347,7 +347,7 @@ namespace libtorrent { // clears the given piece's download flag // this means that this piece-block can be picked again - void abort_download(piece_block block, torrent_peer* peer = 0); + void abort_download(piece_block block, torrent_peer* peer = nullptr); // returns true if all blocks in this piece are finished // or if we have the piece diff --git a/include/libtorrent/session_handle.hpp b/include/libtorrent/session_handle.hpp index 0da41acd7..c5362b7c3 100644 --- a/include/libtorrent/session_handle.hpp +++ b/include/libtorrent/session_handle.hpp @@ -245,7 +245,7 @@ namespace libtorrent { , storage_mode_t storage_mode = storage_mode_sparse , bool paused = false , storage_constructor_type sc = default_storage_constructor - , void* userdata = 0); + , void* userdata = nullptr); #endif #endif @@ -729,7 +729,7 @@ namespace libtorrent { void listen_on( std::pair const& port_range , error_code& ec - , const char* net_interface = 0 + , const char* net_interface = nullptr , int flags = 0); #endif diff --git a/include/libtorrent/sha1_hash.hpp b/include/libtorrent/sha1_hash.hpp index 88610615f..01bd2267b 100644 --- a/include/libtorrent/sha1_hash.hpp +++ b/include/libtorrent/sha1_hash.hpp @@ -296,7 +296,7 @@ namespace std { std::size_t ret; // this is OK because sha1_hash is already a hash - std::memcpy(&ret, &k[0], sizeof(ret)); + std::memcpy(&ret, k.data(), sizeof(ret)); return ret; } }; diff --git a/include/libtorrent/torrent.hpp b/include/libtorrent/torrent.hpp index b1a4326e6..02fbf14d7 100644 --- a/include/libtorrent/torrent.hpp +++ b/include/libtorrent/torrent.hpp @@ -950,7 +950,7 @@ namespace libtorrent { void need_picker(); bool has_picker() const { - return m_picker.get() != 0; + return m_picker.get() != nullptr; } void update_max_failcount() @@ -995,8 +995,8 @@ namespace libtorrent { void write_resume_data(add_torrent_params& atp) const; - void seen_complete() { m_last_seen_complete = ::time(0); } - int time_since_complete() const { return int(::time(0) - m_last_seen_complete); } + void seen_complete() { m_last_seen_complete = ::time(nullptr); } + int time_since_complete() const { return int(::time(nullptr) - m_last_seen_complete); } time_t last_seen_complete() const { return m_last_seen_complete; } template diff --git a/include/libtorrent/torrent_handle.hpp b/include/libtorrent/torrent_handle.hpp index 280ea7efc..91fbcecf0 100644 --- a/include/libtorrent/torrent_handle.hpp +++ b/include/libtorrent/torrent_handle.hpp @@ -537,7 +537,7 @@ namespace aux { // a torrent_plugin instance. void add_extension( std::function(torrent_handle const&, void*)> const& ext - , void* userdata = 0); + , void* userdata = nullptr); // ``set_metadata`` expects the *info* section of metadata. i.e. The // buffer passed in will be hashed and verified against the info-hash. If diff --git a/include/libtorrent/tracker_manager.hpp b/include/libtorrent/tracker_manager.hpp index 042c66876..5c1e30f39 100644 --- a/include/libtorrent/tracker_manager.hpp +++ b/include/libtorrent/tracker_manager.hpp @@ -100,9 +100,6 @@ namespace libtorrent { , triggered_manually(false) #ifdef TORRENT_USE_OPENSSL , ssl_ctx(0) -#endif -#if TORRENT_USE_I2P - , i2pconn(0) #endif {} @@ -167,7 +164,7 @@ namespace libtorrent { boost::asio::ssl::context* ssl_ctx; #endif #if TORRENT_USE_I2P - i2p_connection* i2pconn; + i2p_connection* i2pconn = nullptr; #endif }; diff --git a/include/libtorrent/utp_stream.hpp b/include/libtorrent/utp_stream.hpp index 261c25471..6d2794bf7 100644 --- a/include/libtorrent/utp_stream.hpp +++ b/include/libtorrent/utp_stream.hpp @@ -294,7 +294,7 @@ struct TORRENT_EXTRA_EXPORT utp_stream return; } - if (m_impl == 0) + if (m_impl == nullptr) { m_io_service.post(std::bind(handler, boost::asio::error::not_connected, 0)); return; @@ -307,7 +307,7 @@ struct TORRENT_EXTRA_EXPORT utp_stream template void async_read_some(Mutable_Buffers const& buffers, Handler const& handler) { - if (m_impl == 0) + if (m_impl == nullptr) { m_io_service.post(std::bind(handler, boost::asio::error::not_connected, 0)); return; @@ -344,7 +344,7 @@ struct TORRENT_EXTRA_EXPORT utp_stream template void async_read_some(null_buffers const&, Handler const& handler) { - if (m_impl == 0) + if (m_impl == nullptr) { m_io_service.post(std::bind(handler, boost::asio::error::not_connected, 0)); return; @@ -376,7 +376,7 @@ struct TORRENT_EXTRA_EXPORT utp_stream std::size_t read_some(Mutable_Buffers const& buffers, error_code& ec) { TORRENT_ASSERT(!m_read_handler); - if (m_impl == 0) + if (m_impl == nullptr) { ec = boost::asio::error::not_connected; return 0; @@ -440,7 +440,7 @@ struct TORRENT_EXTRA_EXPORT utp_stream template void async_write_some(Const_Buffers const& buffers, Handler const& handler) { - if (m_impl == 0) + if (m_impl == nullptr) { m_io_service.post(std::bind(handler , boost::asio::error::not_connected, 0)); diff --git a/src/disk_io_thread.cpp b/src/disk_io_thread.cpp index 45b986ac2..6502f7ead 100644 --- a/src/disk_io_thread.cpp +++ b/src/disk_io_thread.cpp @@ -55,7 +55,9 @@ POSSIBILITY OF SUCH DAMAGE. #include +#include "libtorrent/aux_/disable_warnings_push.hpp" #include +#include "libtorrent/aux_/disable_warnings_pop.hpp" #define DEBUG_DISK_THREAD 0 @@ -1877,7 +1879,7 @@ constexpr disk_job_flags_t disk_interface::cache_hit; for (auto& p : pieces) { cached_piece_entry* pe = m_disk_cache.find_piece(p.first, p.second); - if (pe == NULL) continue; + if (pe == nullptr) continue; TORRENT_ASSERT(pe->outstanding_read == 1); pe->outstanding_read = 0; } diff --git a/src/settings_pack.cpp b/src/settings_pack.cpp index 3b35fa82b..ff757f02d 100644 --- a/src/settings_pack.cpp +++ b/src/settings_pack.cpp @@ -330,7 +330,7 @@ constexpr int CLOSE_FILE_INTERVAL = 0; SET(proxy_port, 0, &session_impl::update_proxy), SET(i2p_port, 0, &session_impl::update_i2p_bridge), SET(cache_size_volatile, 256, nullptr), - SET(urlseed_max_request_bytes, 16 * 1024 * 1024, 0), + SET(urlseed_max_request_bytes, 16 * 1024 * 1024, nullptr), SET(web_seed_name_lookup_retry, 1800, nullptr), SET(close_file_interval, CLOSE_FILE_INTERVAL, nullptr), SET(max_web_seed_connections, 3, nullptr),