fix integer overflow assert

This commit is contained in:
Arvid Norberg
2011-12-24 20:13:51 +00:00
parent 08523e3855
commit ec5555940b

View File

@@ -57,8 +57,9 @@ namespace libtorrent
TORRENT_ASSERT(index >= 0 && index < num_pieces()); TORRENT_ASSERT(index >= 0 && index < num_pieces());
if (index == num_pieces()-1) if (index == num_pieces()-1)
{ {
int size = int(total_size() size_type size_except_last = num_pieces() - 1;
- size_type(num_pieces() - 1) * piece_length()); size_except_last *= piece_length();
int size = int(total_size() - size_except_last);
TORRENT_ASSERT(size > 0); TORRENT_ASSERT(size > 0);
TORRENT_ASSERT(size <= piece_length()); TORRENT_ASSERT(size <= piece_length());
return int(size); return int(size);