*** empty log message ***

This commit is contained in:
Magnus Jonsson 2004-01-25 02:59:27 +00:00
parent 30329cc225
commit bb36fa8e24
4 changed files with 30 additions and 10 deletions

View File

@ -116,8 +116,8 @@ namespace libtorrent
// the begining) and return the new index to the tracker. // the begining) and return the new index to the tracker.
int prioritize_tracker(int index); int prioritize_tracker(int index);
size_type total_size() const { return m_total_size; } size_type total_size() const { assert(m_total_size>=0); return m_total_size; }
size_type piece_length() const { return m_piece_length; } size_type piece_length() const { assert(m_piece_length>0); return m_piece_length; }
int num_pieces() const { return (int)m_piece_hash.size(); } int num_pieces() const { return (int)m_piece_hash.size(); }
const sha1_hash& info_hash() const { return m_info_hash; } const sha1_hash& info_hash() const { return m_info_hash; }
const std::string& name() const { return m_name; } const std::string& name() const { return m_name; }

View File

@ -638,9 +638,9 @@ namespace libtorrent
assert(offset >= 0); assert(offset >= 0);
assert(size > 0); assert(size > 0);
assert(piece_index >= 0 && (unsigned)piece_index < m_piece_to_slot.size()); assert(piece_index >= 0 && (unsigned)piece_index < m_piece_to_slot.size());
assert(m_piece_to_slot[piece_index] >= 0); assert(m_piece_to_slot[piece_index] >= 0 && (unsigned)m_piece_to_slot[piece_index] < m_slot_to_piece.size());
int slot = m_piece_to_slot[piece_index]; int slot = m_piece_to_slot[piece_index];
assert(slot >= 0 && slot < (int)m_slot_to_piece.size()); assert(slot >= 0 && (unsigned)slot < m_slot_to_piece.size());
return m_storage.read(buf, slot, offset, size); return m_storage.read(buf, slot, offset, size);
} }
@ -663,7 +663,6 @@ namespace libtorrent
assert(offset >= 0); assert(offset >= 0);
assert(size > 0); assert(size > 0);
assert(piece_index >= 0 && (unsigned)piece_index < m_piece_to_slot.size()); assert(piece_index >= 0 && (unsigned)piece_index < m_piece_to_slot.size());
assert(m_piece_to_slot[piece_index] >= 0);
int slot = allocate_slot_for_piece(piece_index); int slot = allocate_slot_for_piece(piece_index);
assert(slot >= 0 && (unsigned)slot < m_slot_to_piece.size()); assert(slot >= 0 && (unsigned)slot < m_slot_to_piece.size());
m_storage.write(buf, slot, offset, size); m_storage.write(buf, slot, offset, size);
@ -942,6 +941,27 @@ namespace libtorrent
bytes_to_read = m_info.piece_size(current_slot); bytes_to_read = m_info.piece_size(current_slot);
} }
// dirty "fix" for a bug when file is corrupt
for(int i=0;(unsigned)i<m_info.num_pieces();i++)
{
if(m_piece_to_slot[i]!=has_no_slot && m_piece_to_slot[i]!=i && m_slot_to_piece[i]!=unallocated)
{
assert(m_piece_to_slot[i]>=0 && (unsigned)m_piece_to_slot[i]<m_slot_to_piece.size());
assert(m_slot_to_piece[m_piece_to_slot[i]]==i);
if(m_slot_to_piece[i]!=unassigned)
{
assert(m_slot_to_piece[i]>=0 && (unsigned)m_slot_to_piece[i]<m_piece_to_slot.size());
assert(m_piece_to_slot[m_slot_to_piece[i]]==i);
m_piece_to_slot[m_slot_to_piece[i]]=has_no_slot;
m_slot_to_piece[i]=unassigned;
m_free_slots.push_back(i);
}
m_slot_to_piece[m_piece_to_slot[i]]=unassigned;
m_free_slots.push_back(m_piece_to_slot[i]);
m_piece_to_slot[i]=has_no_slot;
}
}
#ifndef NDEBUG #ifndef NDEBUG
std::stringstream s; std::stringstream s;
@ -1198,17 +1218,16 @@ namespace libtorrent
for (int i = 0; i < m_info.num_pieces(); ++i) for (int i = 0; i < m_info.num_pieces(); ++i)
{ {
// Check that piece_to_slot's elements are within bounds // Check domain of piece_to_slot's elements
assert(m_piece_to_slot[i]==has_no_slot assert(m_piece_to_slot[i]==has_no_slot
||(m_piece_to_slot[i]>=0 && (unsigned)m_piece_to_slot[i]<m_slot_to_piece.size())); ||(m_piece_to_slot[i]>=0 && (unsigned)m_piece_to_slot[i]<m_slot_to_piece.size()));
// Check that piece_to_slot's elements are within bounds // Check domain of slot_to_piece's elements
assert(m_slot_to_piece[i]==unallocated assert(m_slot_to_piece[i]==unallocated
|| m_slot_to_piece[i]==unassigned || m_slot_to_piece[i]==unassigned
||(m_slot_to_piece[i]>=0 && (unsigned)m_slot_to_piece[i]<m_piece_to_slot.size())); ||(m_slot_to_piece[i]>=0 && (unsigned)m_slot_to_piece[i]<m_piece_to_slot.size()));
// do more detailed checks on piece_to_slot // do more detailed checks on piece_to_slot
if (m_piece_to_slot[i]>=0) if (m_piece_to_slot[i]>=0)
{ {
assert(m_slot_to_piece[m_piece_to_slot[i]]==i); assert(m_slot_to_piece[m_piece_to_slot[i]]==i);

View File

@ -235,7 +235,8 @@ namespace libtorrent
int torrent_info::prioritize_tracker(int index) int torrent_info::prioritize_tracker(int index)
{ {
if (index > (int)m_urls.size()) return (int)m_urls.size()-1; assert(index >= 0);
if (index >= (int)m_urls.size()) return (int)m_urls.size()-1;
while (index > 0 && m_urls[index].tier == m_urls[index-1].tier) while (index > 0 && m_urls[index].tier == m_urls[index-1].tier)
{ {