diff --git a/include/libtorrent/bdecode.hpp b/include/libtorrent/bdecode.hpp index 8150ba7f0..dc13ddbbc 100644 --- a/include/libtorrent/bdecode.hpp +++ b/include/libtorrent/bdecode.hpp @@ -280,7 +280,7 @@ struct TORRENT_EXPORT bdecode_node type_t type() const; // returns true if type() != none_t. - operator bool() const; + explicit operator bool() const; // return a non-owning reference to this node. This is useful to refer to // the root node without copying it in assignments. diff --git a/include/libtorrent/copy_ptr.hpp b/include/libtorrent/copy_ptr.hpp index 73c0d2e2b..7aa9903e6 100644 --- a/include/libtorrent/copy_ptr.hpp +++ b/include/libtorrent/copy_ptr.hpp @@ -59,7 +59,7 @@ namespace libtorrent m_ptr = p.m_ptr; p.m_ptr = tmp; } - operator bool() const { return m_ptr != 0; } + explicit operator bool() const { return m_ptr != 0; } ~copy_ptr() { delete m_ptr; } private: T* m_ptr; diff --git a/include/libtorrent/error_code.hpp b/include/libtorrent/error_code.hpp index 8ff7af16c..bd3a3e248 100644 --- a/include/libtorrent/error_code.hpp +++ b/include/libtorrent/error_code.hpp @@ -502,7 +502,7 @@ namespace libtorrent storage_error(): file(-1), operation(0) {} explicit storage_error(error_code e): ec(e), file(-1), operation(0) {} - operator bool() const { return ec.value() != 0; } + explicit operator bool() const { return ec.value() != 0; } // the error that occurred error_code ec; diff --git a/include/libtorrent/file.hpp b/include/libtorrent/file.hpp index 7cab161f7..9a37d4561 100644 --- a/include/libtorrent/file.hpp +++ b/include/libtorrent/file.hpp @@ -219,7 +219,7 @@ namespace libtorrent file const& operator*() const; file* get(); file const* get() const; - operator bool() const; + explicit operator bool() const; file_handle& reset(file* f = nullptr); char stack[2048]; diff --git a/src/http_tracker_connection.cpp b/src/http_tracker_connection.cpp index 46f2ec68c..a8c921de5 100644 --- a/src/http_tracker_connection.cpp +++ b/src/http_tracker_connection.cpp @@ -394,7 +394,7 @@ namespace libtorrent // extract ip i = info.dict_find_string("ip"); - if (i == 0) + if (!i) { ec = errors::invalid_tracker_response; return false; @@ -403,7 +403,7 @@ namespace libtorrent // extract port i = info.dict_find_int("port"); - if (i == 0) + if (!i) { ec = errors::invalid_tracker_response; return false; diff --git a/src/kademlia/item.cpp b/src/kademlia/item.cpp index 429c8979c..ed70b6843 100644 --- a/src/kademlia/item.cpp +++ b/src/kademlia/item.cpp @@ -140,10 +140,12 @@ item::item(entry v) {} item::item(bdecode_node const& v) - : m_value(std::move(v)) - , m_seq(0) + : m_seq(0) , m_mutable(false) -{} +{ + // TODO: implement ctor for entry from bdecode_node? + m_value = v; +} item::item(entry v, span salt , sequence_number const seq, public_key const& pk, secret_key const& sk) diff --git a/src/kademlia/msg.cpp b/src/kademlia/msg.cpp index 3affaf6ea..ed476ec67 100644 --- a/src/kademlia/msg.cpp +++ b/src/kademlia/msg.cpp @@ -73,7 +73,7 @@ bool verify_message_impl(bdecode_node const& message, span des // none_t means any type if (ret[i] && ret[i].type() != k.type && k.type != bdecode_node::none_t) ret[i].clear(); - if (ret[i] == 0 && (k.flags & key_desc_t::optional) == 0) + if (!ret[i] && (k.flags & key_desc_t::optional) == 0) { // the key was not found, and it's not an optional key std::snprintf(error.data(), error.size(), "missing '%s' key", k.name); diff --git a/src/torrent_info.cpp b/src/torrent_info.cpp index 9a8e4008a..aa0e433e2 100644 --- a/src/torrent_info.cpp +++ b/src/torrent_info.cpp @@ -1336,7 +1336,7 @@ namespace libtorrent } bdecode_node info = torrent_file.dict_find_dict("info"); - if (info == 0) + if (!info) { bdecode_node link = torrent_file.dict_find_string("magnet-uri"); if (link) diff --git a/src/ut_pex.cpp b/src/ut_pex.cpp index 58f63e3b1..d2b1fd0b6 100644 --- a/src/ut_pex.cpp +++ b/src/ut_pex.cpp @@ -360,7 +360,7 @@ namespace libtorrent { namespace #ifndef TORRENT_DISABLE_LOGGING if (p6) num_dropped += p6.string_length() / 18; #endif - if (p6 != 0 && p6.type() == bdecode_node::string_t) + if (p6.type() == bdecode_node::string_t) { int const num_peers = p6.string_length() / 18; char const* in = p6.string_ptr(); @@ -379,9 +379,7 @@ namespace libtorrent { namespace if (p6) num_added += p6.string_length() / 18; #endif bdecode_node p6f = pex_msg.dict_find("added6.f"); - if (p6 != 0 - && p6f != 0 - && p6.type() == bdecode_node::string_t + if (p6.type() == bdecode_node::string_t && p6f.type() == bdecode_node::string_t && p6f.string_length() == p6.string_length() / 18) { diff --git a/test/test_magnet.cpp b/test/test_magnet.cpp index c6093819a..59fe45326 100644 --- a/test/test_magnet.cpp +++ b/test/test_magnet.cpp @@ -199,8 +199,8 @@ TORRENT_TEST(magnet) std::printf("session_state\n%s\n", print_entry(session_state2).c_str()); // make sure settings that haven't been changed from their defaults are not saved - TEST_CHECK(session_state2.dict_find("settings") - .dict_find("optimistic_disk_retry") == 0); + TEST_CHECK(!session_state2.dict_find("settings") + .dict_find("optimistic_disk_retry")); s->load_state(session_state2);