fix division by zero

This commit is contained in:
Arvid Norberg 2012-04-02 05:30:15 +00:00
parent 21b51afd5f
commit 46683f59f8
2 changed files with 6 additions and 4 deletions

View File

@ -606,6 +606,8 @@ namespace libtorrent
{
TORRENT_ASSERT(!m_dirty);
TORRENT_ASSERT(priority >= 0);
TORRENT_ASSERT(elem_index < int(m_pieces.size()));
TORRENT_ASSERT(elem_index >= 0);
#ifdef TORRENT_PICKER_LOG
std::cerr << "remove " << m_pieces[elem_index] << " (" << priority << ")" << std::endl;

View File

@ -3893,9 +3893,9 @@ namespace aux {
STAT_LOG(d, m_connect_timeouts);
STAT_LOG(d, m_uninteresting_peers);
STAT_LOG(d, m_timeout_peers);
STAT_LOG(f, (float(m_total_failed_bytes) * 100.f / m_stat.total_payload_download()));
STAT_LOG(f, (float(m_total_redundant_bytes) * 100.f / m_stat.total_payload_download()));
STAT_LOG(f, (float(m_stat.total_protocol_download()) * 100.f / m_stat.total_download()));
STAT_LOG(f, (float(m_total_failed_bytes) * 100.f / (m_stat.total_payload_download() == 0 ? 1 : m_stat.total_payload_download())));
STAT_LOG(f, (float(m_total_redundant_bytes) * 100.f / (m_stat.total_payload_download() == 0 ? 1 : m_stat.total_payload_download())));
STAT_LOG(f, (float(m_stat.total_protocol_download()) * 100.f / (m_stat.total_download() == 0 ? 1 : m_stat.total_download())));
STAT_LOG(f, float(cs.average_read_time) / 1000000.f);
STAT_LOG(f, float(cs.average_write_time) / 1000000.f);
STAT_LOG(f, float(cs.average_queue_time) / 1000000.f);
@ -3979,7 +3979,7 @@ namespace aux {
/ double(tick_interval_ms * 10));
for (int i = 0; i < torrent::waste_reason_max; ++i)
STAT_LOG(f, (m_redundant_bytes[i] * 100.) / double(m_total_redundant_bytes));
STAT_LOG(f, (m_redundant_bytes[i] * 100.) / double(m_total_redundant_bytes == 0 ? 1 : m_total_redundant_bytes));
STAT_LOG(d, m_no_memory_peers);
STAT_LOG(d, m_too_many_peers);