fix some overflow and division by zero issues

This commit is contained in:
Arvid Norberg
2012-04-28 05:05:39 +00:00
parent 2aadba290b
commit 5583ed407a
2 changed files with 12 additions and 3 deletions

View File

@@ -54,9 +54,13 @@ namespace libtorrent
TORRENT_ASSERT(assigned < request_size);
int quota = request_size - assigned;
TORRENT_ASSERT(quota >= 0);
--ttl;
if (quota == 0) return quota;
for (int j = 0; j < 5 && channel[j]; ++j)
{
if (channel[j]->throttle() == 0) continue;
if (channel[j]->tmp == 0) continue;
quota = (std::min)(int(boost::int64_t(channel[j]->distribute_quota)
* priority / channel[j]->tmp), quota);
}
@@ -64,7 +68,6 @@ namespace libtorrent
for (int j = 0; j < 5 && channel[j]; ++j)
channel[j]->use_quota(quota);
TORRENT_ASSERT(assigned <= request_size);
--ttl;
return quota;
}
}