In some odd cases (such as if unchoked without having shown interest), the code could dividing a number by the torrent's block size without checking to see if the torrent had its metadata yet. This caused a division by zero because a magnet torrent's blocksize is unset until the metadata is downloaded.
{
const tr_torrent * const torrent = msgs->torrent;
- if( tr_torrentIsSeed( msgs->torrent ) )
- {
- msgs->desiredRequestCount = 0;
- }
- else if( msgs->peer->clientIsChoked )
- {
- msgs->desiredRequestCount = 0;
- }
- else if( !msgs->peer->clientIsInterested )
+
+ /* there are lots of reasons we might not want to request any blocks... */
+ if( tr_torrentIsSeed( torrent ) || !tr_torrentHasMetadata( torrent )
+ || msgs->peer->clientIsChoked
+ || !msgs->peer->clientIsInterested )
{
msgs->desiredRequestCount = 0;
}