fix some coverity issues

This commit is contained in:
Arvid Norberg 2015-05-03 03:28:39 +00:00
parent b417f2ba98
commit 4a304273fd
6 changed files with 35 additions and 16 deletions

View File

@ -179,6 +179,12 @@ void terminal_size(int* terminal_width, int* terminal_height)
*terminal_height = coninfo.srWindow.Bottom - coninfo.srWindow.Top;
#else
int tty = open("/dev/tty", O_RDONLY);
if (tty < 0)
{
*terminal_width = 190;
*terminal_height = 100;
return;
}
winsize size;
int ret = ioctl(tty, TIOCGWINSZ, reinterpret_cast<char*>(&size));
close(tty);

View File

@ -393,7 +393,8 @@ namespace libtorrent
error_code error;
};
void read_piece(int piece);
void on_disk_read_complete(disk_io_job const* j, peer_request r, read_piece_struct* rp);
void on_disk_read_complete(disk_io_job const* j, peer_request r
, boost::shared_ptr<read_piece_struct> rp);
storage_mode_t storage_mode() const { return (storage_mode_t)m_storage_mode; }
storage_interface* get_storage()

View File

@ -5316,19 +5316,21 @@ namespace libtorrent
TORRENT_ASSERT(is_single_thread());
shared_ptr<torrent> t = m_torrent.lock();
const int tick_interval = (std::max)(1, m_settings.get_int(settings_pack::tick_interval));
if (channel == download_channel)
{
return (std::max)((std::max)(m_outstanding_bytes
, m_recv_buffer.packet_bytes_remaining()) + 30
, int(boost::int64_t(m_statistics.download_rate()) * 2
/ (1000 / m_settings.get_int(settings_pack::tick_interval))));
/ (1000 / tick_interval)));
}
else
{
return (std::max)((std::max)(m_reading_bytes
, m_send_buffer.size())
, int((boost::int64_t(m_statistics.upload_rate()) * 2
* m_settings.get_int(settings_pack::tick_interval)) / 1000));
* tick_interval) / 1000));
}
}

View File

@ -835,6 +835,8 @@ namespace libtorrent
int priority = p.priority(this);
TORRENT_ASSERT(priority >= 0);
if (priority < 0) return;
if (int(m_priority_boundries.size()) <= priority)
m_priority_boundries.resize(priority + 1, m_pieces.size());

View File

@ -918,14 +918,22 @@ namespace libtorrent
}
TORRENT_ASSERT(piece >= 0 && piece < m_torrent_file->num_pieces());
int piece_size = m_torrent_file->piece_size(piece);
int blocks_in_piece = (piece_size + block_size() - 1) / block_size();
const int piece_size = m_torrent_file->piece_size(piece);
const 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;
if (blocks_in_piece == 0)
{
// this shouldn't actually happen
boost::shared_array<char> buf;
m_ses.alerts().emplace_alert<read_piece_alert>(
get_handle(), piece, buf, 0);
return;
}
boost::shared_ptr<read_piece_struct> rp = boost::make_shared<read_piece_struct>();
rp->piece_data.reset(new (std::nothrow) char[piece_size]);
rp->blocks_left = 0;
rp->fail = false;
@ -939,7 +947,6 @@ namespace libtorrent
rp->piece_data.reset();
m_ses.alerts().emplace_alert<read_piece_alert>(
get_handle(), r.piece, rp->piece_data, 0);
delete rp;
return;
}
for (int i = 0; i < blocks_in_piece; ++i, r.start += block_size())
@ -1194,7 +1201,8 @@ namespace libtorrent
}
}
void torrent::on_disk_read_complete(disk_io_job const* j, peer_request r, read_piece_struct* rp)
void torrent::on_disk_read_complete(disk_io_job const* j, peer_request r
, boost::shared_ptr<read_piece_struct> rp)
{
// hold a reference until this function returns
torrent_ref_holder h(this, "read_piece");
@ -1229,7 +1237,6 @@ namespace libtorrent
m_ses.alerts().emplace_alert<read_piece_alert>(
get_handle(), r.piece, rp->piece_data, size);
}
delete rp;
}
}
@ -9920,7 +9927,7 @@ namespace libtorrent
int num_downloaded_pieces = (std::max)(m_picker->num_have()
, pieces_in_torrent - m_picker->num_filtered());
if (num_downloaded_pieces * m_torrent_file->piece_length()
if (boost::int64_t(num_downloaded_pieces) * m_torrent_file->piece_length()
* settings().get_int(settings_pack::share_mode_target) > m_total_uploaded
&& num_downloaded_pieces > 0)
return;

View File

@ -3323,7 +3323,8 @@ bool utp_socket_impl::incoming_packet(boost::uint8_t const* buf, int size
return false;
}
void utp_socket_impl::do_ledbat(int acked_bytes, int delay, int in_flight)
void utp_socket_impl::do_ledbat(const int acked_bytes, const int delay
, const int in_flight)
{
INVARIANT_CHECK;
@ -3333,15 +3334,15 @@ void utp_socket_impl::do_ledbat(int acked_bytes, int delay, int in_flight)
TORRENT_ASSERT(in_flight > 0);
TORRENT_ASSERT(acked_bytes > 0);
int target_delay = m_sm->target_delay();
const int target_delay = (std::max)(1, m_sm->target_delay());
// true if the upper layer is pushing enough data down the socket to be
// limited by the cwnd. If this is not the case, we should not adjust cwnd.
bool cwnd_saturated = (m_bytes_in_flight + acked_bytes + m_mtu > (m_cwnd >> 16));
const bool cwnd_saturated = (m_bytes_in_flight + acked_bytes + m_mtu > (m_cwnd >> 16));
// all of these are fixed points with 16 bits fraction portion
boost::int64_t window_factor = (boost::int64_t(acked_bytes) << 16) / in_flight;
boost::int64_t delay_factor = (boost::int64_t(target_delay - delay) << 16) / target_delay;
const boost::int64_t window_factor = (boost::int64_t(acked_bytes) << 16) / in_flight;
const boost::int64_t delay_factor = (boost::int64_t(target_delay - delay) << 16) / target_delay;
boost::int64_t scaled_gain;
if (delay >= target_delay)