silence valgrind warning about uninitialized memory

This commit is contained in:
Arvid Norberg 2011-11-20 20:49:18 +00:00
parent 0bcdf7706c
commit 5d8ce01c7a
3 changed files with 10 additions and 5 deletions

View File

@ -452,7 +452,7 @@ namespace libtorrent
void get_full_peer_list(std::vector<peer_list_entry>& v) const; void get_full_peer_list(std::vector<peer_list_entry>& v) const;
void get_peer_info(std::vector<peer_info>& v); void get_peer_info(std::vector<peer_info>& v);
void get_download_queue(std::vector<partial_piece_info>& queue); void get_download_queue(std::vector<partial_piece_info>* queue);
void refresh_explicit_cache(int cache_size); void refresh_explicit_cache(int cache_size);

View File

@ -5350,10 +5350,10 @@ ctx->set_verify_callback(verify_function, ec);
} }
} }
void torrent::get_download_queue(std::vector<partial_piece_info>& queue) void torrent::get_download_queue(std::vector<partial_piece_info>* queue)
{ {
TORRENT_ASSERT(m_ses.is_network_thread()); TORRENT_ASSERT(m_ses.is_network_thread());
queue.clear(); queue->clear();
std::vector<block_info>& blk = m_ses.m_block_info_storage; std::vector<block_info>& blk = m_ses.m_block_info_storage;
blk.clear(); blk.clear();
@ -5364,6 +5364,10 @@ ctx->set_verify_callback(verify_function, ec);
const int blocks_per_piece = m_picker->blocks_in_piece(0); const int blocks_per_piece = m_picker->blocks_in_piece(0);
blk.resize(q.size() * blocks_per_piece); blk.resize(q.size() * blocks_per_piece);
// for some weird reason valgrind claims these are uninitialized
// unless it's zeroed out here (block_info has a construct that's
// supposed to initialize it)
memset(&blk[0], 0, sizeof(blk[0]) * blk.size());
int counter = 0; int counter = 0;
for (std::vector<piece_picker::downloading_piece>::const_iterator i for (std::vector<piece_picker::downloading_piece>::const_iterator i
@ -5375,6 +5379,7 @@ ctx->set_verify_callback(verify_function, ec);
pi.finished = (int)i->finished; pi.finished = (int)i->finished;
pi.writing = (int)i->writing; pi.writing = (int)i->writing;
pi.requested = (int)i->requested; pi.requested = (int)i->requested;
TORRENT_ASSERT(counter * blocks_per_piece + pi.blocks_in_piece <= int(blk.size()));
pi.blocks = &blk[counter * blocks_per_piece]; pi.blocks = &blk[counter * blocks_per_piece];
int piece_size = int(torrent_file().piece_size(i->index)); int piece_size = int(torrent_file().piece_size(i->index));
for (int j = 0; j < pi.blocks_in_piece; ++j) for (int j = 0; j < pi.blocks_in_piece; ++j)
@ -5425,7 +5430,7 @@ ctx->set_verify_callback(verify_function, ec);
pi.blocks[j].num_peers = i->info[j].num_peers; pi.blocks[j].num_peers = i->info[j].num_peers;
} }
pi.piece_index = i->index; pi.piece_index = i->index;
queue.push_back(pi); queue->push_back(pi);
} }
} }

View File

@ -877,7 +877,7 @@ namespace libtorrent
void torrent_handle::get_download_queue(std::vector<partial_piece_info>& queue) const void torrent_handle::get_download_queue(std::vector<partial_piece_info>& queue) const
{ {
INVARIANT_CHECK; INVARIANT_CHECK;
TORRENT_SYNC_CALL1(get_download_queue, boost::ref(queue)); TORRENT_SYNC_CALL1(get_download_queue, &queue);
} }
void torrent_handle::set_piece_deadline(int index, int deadline, int flags) const void torrent_handle::set_piece_deadline(int index, int deadline, int flags) const