Changeset 4213


Ignore:
Timestamp:
Dec 19, 2007, 5:57:55 AM (14 years ago)
Author:
charles
Message:

fix an obscure bug in tr_torrentStat() where (% verified + % unverified + % unavailable) could be > 1.0

Location:
trunk/libtransmission
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/torrent.c

    r4209 r4213  
    791791    {
    792792        int i;
    793         tr_bitfield * available = tr_peerMgrGetAvailable( tor->handle->peerMgr,
    794                                                           tor->info.hash );
     793        tr_bitfield * availablePieces = tr_peerMgrGetAvailable( tor->handle->peerMgr,
     794                                                                tor->info.hash );
    795795        s->desiredSize = 0;
    796796        s->desiredAvailable = 0;
     
    798798        for( i=0; i<tor->info.pieceCount; ++i ) {
    799799            if( !tor->info.pieces[i].dnd ) {
    800                 s->desiredSize += tr_torPieceCountBytes( tor, i );
    801                 if( tr_bitfieldHas( available, i ) )
    802                     s->desiredAvailable += tr_torPieceCountBytes( tor, i );
     800                const uint64_t byteCount = tr_torPieceCountBytes( tor, i );
     801                s->desiredSize += byteCount;
     802                if( tr_bitfieldHas( availablePieces, i ) )
     803                    s->desiredAvailable += byteCount;
    803804            }
    804805        }
    805806
    806         tr_bitfieldFree( available );
     807        /* "availablePieces" can miss our unverified blocks... */
     808        if( s->desiredAvailable < s->haveValid + s->haveUnchecked )
     809            s->desiredAvailable = s->haveValid + s->haveUnchecked;
     810
     811        tr_bitfieldFree( availablePieces );
    807812    }
    808813   
  • trunk/libtransmission/utils.c

    r4111 r4213  
    699699    assert( a->len == b->len );
    700700
    701     for( ait=a->bits, bit=b->bits, aend=ait+a->len; ait!=aend; ++ait, ++bit )
    702         *ait |= *bit;
     701    for( ait=a->bits, bit=b->bits, aend=ait+a->len; ait!=aend; )
     702        *ait++ |= *bit++;
    703703
    704704    return a;
Note: See TracChangeset for help on using the changeset viewer.