From ca106ca4e02814809ba5b28850b03a16fa095929 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Thu, 24 Feb 2011 04:25:35 +0000 Subject: [PATCH] some warning fixes and cleanup --- examples/connection_tester.cpp | 2 +- examples/fragmentation_test.cpp | 2 +- src/enum_net.cpp | 8 +++++--- src/file.cpp | 3 +++ src/kademlia/node.cpp | 2 +- src/magnet_uri.cpp | 6 +++--- src/policy.cpp | 2 -- src/rss.cpp | 7 ++++--- src/session_impl.cpp | 1 - src/socks5_stream.cpp | 25 ++++++++++++------------- src/torrent.cpp | 4 ++++ src/udp_tracker_connection.cpp | 12 ++++++------ src/upnp.cpp | 25 +++++++++++-------------- src/web_peer_connection.cpp | 6 +++--- 14 files changed, 54 insertions(+), 51 deletions(-) diff --git a/examples/connection_tester.cpp b/examples/connection_tester.cpp index 8121e8f68..b19afa4c4 100644 --- a/examples/connection_tester.cpp +++ b/examples/connection_tester.cpp @@ -225,7 +225,7 @@ struct peer_conn } }; -int main(int argc, char const* argv[]) +int main(int argc, char* argv[]) { if (argc < 5) { diff --git a/examples/fragmentation_test.cpp b/examples/fragmentation_test.cpp index 73ca35d3b..28eb26c0a 100644 --- a/examples/fragmentation_test.cpp +++ b/examples/fragmentation_test.cpp @@ -39,7 +39,7 @@ POSSIBILITY OF SUCH DAMAGE. using namespace libtorrent; -int main(int argc, char const* argv[]) +int main(int argc, char* argv[]) { if (argc != 3 && argc != 2) { diff --git a/src/enum_net.cpp b/src/enum_net.cpp index 0a593fc11..a37128403 100644 --- a/src/enum_net.cpp +++ b/src/enum_net.cpp @@ -436,7 +436,8 @@ namespace libtorrent { ifreq req; memset(&req, 0, sizeof(req)); - strncpy(req.ifr_name, iface.name, IF_NAMESIZE); + // -1 to leave a null terminator + strncpy(req.ifr_name, iface.name, IF_NAMESIZE - 1); if (ioctl(s, SIOCGIFMTU, &req) < 0) { continue; @@ -486,7 +487,8 @@ namespace libtorrent ifreq req; memset(&req, 0, sizeof(req)); - strncpy(req.ifr_name, item.ifr_name, IF_NAMESIZE); + // -1 to leave a null terminator + strncpy(req.ifr_name, item.ifr_name, IF_NAMESIZE - 1); if (ioctl(s, SIOCGIFMTU, &req) < 0) { ec = error_code(errno, asio::error::system_category); @@ -496,7 +498,7 @@ namespace libtorrent iface.mtu = req.ifr_mtu; memset(&req, 0, sizeof(req)); - strncpy(req.ifr_name, item.ifr_name, IF_NAMESIZE); + strncpy(req.ifr_name, item.ifr_name, IF_NAMESIZE - 1); if (ioctl(s, SIOCGIFNETMASK, &req) < 0) { #if TORRENT_USE_IPV6 diff --git a/src/file.cpp b/src/file.cpp index 973d8e675..96b1ac975 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -623,6 +623,9 @@ namespace libtorrent : m_done(false) { ec.clear(); + memset(&m_dirent, 0, sizeof(dirent)); + m_name[0] = 0; + #ifdef TORRENT_WINDOWS // the path passed to FindFirstFile() must be // a pattern diff --git a/src/kademlia/node.cpp b/src/kademlia/node.cpp index b878e07f2..84534bade 100644 --- a/src/kademlia/node.cpp +++ b/src/kademlia/node.cpp @@ -440,7 +440,7 @@ time_duration node_impl::connection_timeout() ++i; continue; } - m_feeds.erase(i); + m_feeds.erase(i++); } // look through all peers and see if any have timed out diff --git a/src/magnet_uri.cpp b/src/magnet_uri.cpp index 8f26f766a..2fcd67eed 100644 --- a/src/magnet_uri.cpp +++ b/src/magnet_uri.cpp @@ -199,9 +199,9 @@ namespace libtorrent pos = uri.find("&tr=", pos); if (pos == std::string::npos) break; pos += 4; - error_code ec; - std::string url = unescape_string(uri.substr(pos, uri.find('&', pos) - pos), ec); - if (ec) continue; + error_code e; + std::string url = unescape_string(uri.substr(pos, uri.find('&', pos) - pos), e); + if (e) continue; announce_entry ae(url); ae.tier = tier++; ret.add_tracker(ae); diff --git a/src/policy.cpp b/src/policy.cpp index 179656104..85f3c4a57 100644 --- a/src/policy.cpp +++ b/src/policy.cpp @@ -346,8 +346,6 @@ namespace libtorrent INVARIANT_CHECK; aux::session_impl& ses = m_torrent->session(); - piece_picker* p = 0; - if (m_torrent->has_picker()) p = &m_torrent->picker(); for (iterator i = m_peers.begin(); i != m_peers.end();) { diff --git a/src/rss.cpp b/src/rss.cpp index e08d51fc9..e20d7b6a8 100644 --- a/src/rss.cpp +++ b/src/rss.cpp @@ -368,11 +368,12 @@ void feed::on_feed(error_code const& ec p.ti.reset(); p.info_hash.clear(); p.name = i->title.c_str(); - error_code ec; + + error_code e; // #error session_impl::add_torrent doesn't support magnet links via url - m_ses.add_torrent(p, ec); + m_ses.add_torrent(p, e); - if (ec) + if (e) { // #error alert! } diff --git a/src/session_impl.cpp b/src/session_impl.cpp index 5b4f8e6d9..68368595b 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -1902,7 +1902,6 @@ namespace aux { if (!m_listen_sockets.empty()) { - error_code ec; tcp::endpoint local = m_listen_sockets.front().sock->local_endpoint(ec); if (!ec) { diff --git a/src/socks5_stream.cpp b/src/socks5_stream.cpp index 15ec2d543..3b4d5a1d4 100644 --- a/src/socks5_stream.cpp +++ b/src/socks5_stream.cpp @@ -362,19 +362,18 @@ namespace libtorrent } if (response != 0) { - error_code e(socks_error::general_failure, socks_category); + error_code ec(socks_error::general_failure, socks_category); switch (response) { - case 2: e = asio::error::no_permission; break; - case 3: e = asio::error::network_unreachable; break; - case 4: e = asio::error::host_unreachable; break; - case 5: e = asio::error::connection_refused; break; - case 6: e = asio::error::timed_out; break; - case 7: e = error_code(socks_error::command_not_supported, socks_category); break; - case 8: e = asio::error::address_family_not_supported; break; + case 2: ec = asio::error::no_permission; break; + case 3: ec = asio::error::network_unreachable; break; + case 4: ec = asio::error::host_unreachable; break; + case 5: ec = asio::error::connection_refused; break; + case 6: ec = asio::error::timed_out; break; + case 7: ec = error_code(socks_error::command_not_supported, socks_category); break; + case 8: ec = asio::error::address_family_not_supported; break; } - (*h)(e); - error_code ec; + (*h)(ec); close(ec); return; } @@ -466,9 +465,9 @@ namespace libtorrent case 92: code = socks_error::no_identd; break; case 93: code = socks_error::identd_error; break; } - error_code e(code, socks_category); - (*h)(e); - close(e); + error_code ec(code, socks_category); + (*h)(ec); + close(ec); } } diff --git a/src/torrent.cpp b/src/torrent.cpp index e4fb92ece..0f9991046 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -762,6 +762,10 @@ namespace libtorrent int piece_size = m_torrent_file->piece_size(piece); int blocks_in_piece = (piece_size + block_size() - 1) / block_size(); + // if blocks_in_piece is 0, rp will leak + TORRENT_ASSERT(blocks_in_piece > 0); + TORRENT_ASSERT(piece_size > 0); + read_piece_struct* rp = new read_piece_struct; rp->piece_data.reset(new (std::nothrow) char[piece_size]); rp->blocks_left = 0; diff --git a/src/udp_tracker_connection.cpp b/src/udp_tracker_connection.cpp index fafc0f7e7..4dba776bf 100644 --- a/src/udp_tracker_connection.cpp +++ b/src/udp_tracker_connection.cpp @@ -163,18 +163,18 @@ namespace libtorrent , boost::bind(&tcp::resolver::iterator::value_type::endpoint, _1)); // remove endpoints that are filtered by the IP filter - for (std::list::iterator i = m_endpoints.begin(); - i != m_endpoints.end();) + for (std::list::iterator k = m_endpoints.begin(); + k != m_endpoints.end();) { - if (m_ses.m_ip_filter.access(i->address()) == ip_filter::blocked) + if (m_ses.m_ip_filter.access(k->address()) == ip_filter::blocked) { #if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING - if (cb) cb->debug_log("*** UDP_TRACKER [ IP blocked by filter: " + print_address(i->address()) + " ]"); + if (cb) cb->debug_log("*** UDP_TRACKER [ IP blocked by filter: " + print_address(k->address()) + " ]"); #endif - i = m_endpoints.erase(i); + k = m_endpoints.erase(k); } else - ++i; + ++k; } if (m_endpoints.empty()) diff --git a/src/upnp.cpp b/src/upnp.cpp index 007206cfd..f0d87fe69 100644 --- a/src/upnp.cpp +++ b/src/upnp.cpp @@ -251,12 +251,12 @@ bool upnp::get_mapping(int index, int& local_port, int& external_port, int& prot return true; } -void upnp::resend_request(error_code const& e) +void upnp::resend_request(error_code const& ec) { #if defined TORRENT_ASIO_DEBUGGING complete_async("upnp::resend_request"); #endif - if (e) return; + if (ec) return; boost::intrusive_ptr me(self()); @@ -300,11 +300,10 @@ void upnp::resend_request(error_code const& e) d.upnp_connection->get(d.url, seconds(30), 1); #ifndef BOOST_NO_EXCEPTIONS } - catch (std::exception& e) + catch (std::exception& exc) { - (void)e; char msg[200]; - snprintf(msg, sizeof(msg), "connection failed to: %s %s", d.url.c_str(), e.what()); + snprintf(msg, sizeof(msg), "connection failed to: %s %s", d.url.c_str(), exc.what()); log(msg, l); d.disabled = true; } @@ -563,13 +562,11 @@ void upnp::on_reply(udp::endpoint const& from, char* buffer d.upnp_connection->get(d.url, seconds(30), 1); #ifndef BOOST_NO_EXCEPTIONS } - catch (std::exception& e) + catch (std::exception& exc) { - (void)e; - char msg[200]; snprintf(msg, sizeof(msg), "connection failed to: %s %s" - , d.url.c_str(), e.what()); + , d.url.c_str(), exc.what()); log(msg, l); d.disabled = true; } @@ -655,12 +652,12 @@ void upnp::next(rootdevice& d, int i, mutex::scoped_lock& l) } else { - std::vector::iterator i + std::vector::iterator j = std::find_if(d.mapping.begin(), d.mapping.end() , boost::bind(&mapping_t::action, _1) != int(mapping_t::action_none)); - if (i == d.mapping.end()) return; + if (j == d.mapping.end()) return; - update_map(d, i - d.mapping.begin(), l); + update_map(d, j - d.mapping.begin(), l); } } @@ -1417,12 +1414,12 @@ void upnp::on_upnp_unmap_response(error_code const& e next(d, mapping, l); } -void upnp::on_expire(error_code const& e) +void upnp::on_expire(error_code const& ec) { #if defined TORRENT_ASIO_DEBUGGING complete_async("upnp::on_expire"); #endif - if (e) return; + if (ec) return; ptime now = time_now(); ptime next_expire = max_time(); diff --git a/src/web_peer_connection.cpp b/src/web_peer_connection.cpp index 01b647461..9905eee90 100644 --- a/src/web_peer_connection.cpp +++ b/src/web_peer_connection.cpp @@ -303,13 +303,13 @@ namespace libtorrent bool header_finished = m_parser.header_finished(); if (!header_finished) { - bool error = false; - boost::tie(payload, protocol) = m_parser.incoming(recv_buffer, error); + bool failed = false; + boost::tie(payload, protocol) = m_parser.incoming(recv_buffer, failed); m_statistics.received_bytes(0, protocol); TORRENT_ASSERT(int(bytes_transferred) >= protocol); bytes_transferred -= protocol; - if (error) + if (failed) { m_statistics.received_bytes(0, bytes_transferred); #ifdef TORRENT_VERBOSE_LOGGING