Changeset 10918


Ignore:
Timestamp:
Jul 1, 2010, 5:14:34 AM (13 years ago)
Author:
charles
Message:

(trunk libT) fix more issues found by -Wconversion

Location:
trunk/libtransmission
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/announcer.c

    r10800 r10918  
    7878
    7979static int
    80 compareTransfer( int a_uploaded, int a_downloaded,
    81                  int b_uploaded, int b_downloaded )
     80compareTransfer( uint32_t a_uploaded, uint32_t a_downloaded,
     81                 uint32_t b_uploaded, uint32_t b_downloaded )
    8282{
    8383    /* higher upload count goes first */
     
    137137    char * host = NULL;
    138138    char * ret;
    139     tr_urlParse( url, strlen( url ), NULL, &host, &port, NULL );
     139    tr_urlParse( url, -1, NULL, &host, &port, NULL );
    140140    ret = tr_strdup_printf( "%s:%d", ( host ? host : "invalid" ), port );
    141141    tr_free( host );
     
    173173    tr_host * host;
    174174    char * url;
    175     int up;
    176     int down;
     175    uint32_t up;
     176    uint32_t down;
    177177};
    178178
     
    339339    size_t i;
    340340    const char * pool = "abcdefghijklmnopqrstuvwxyz0123456789";
    341     const int poolSize = strlen( pool );
     341    const int poolSize = 36;
    342342
    343343    for( i=0; i<msglen; ++i )
     
    386386    /* number of up/down/corrupt bytes since the last time we sent an
    387387     * "event=stopped" message that was acknowledged by the tracker */
    388     uint64_t byteCounts[3];
     388    uint32_t byteCounts[3];
    389389
    390390    tr_ptrArray trackers; /* tr_tracker_item */
     
    618618}
    619619
    620 static int
     620static int8_t
    621621getSeedProbability( int seeds, int leechers )
    622622{
     
    625625
    626626    if( seeds>=0 && leechers>=0 )
    627         return (int)((100.0*seeds)/(seeds+leechers));
     627        return (int8_t)((100.0*seeds)/(seeds+leechers));
    628628
    629629    return -1; /* unknown */
     
    735735                              "&peer_id=%s"
    736736                              "&port=%d"
    737                               "&uploaded=%" PRIu64
    738                               "&downloaded=%" PRIu64
     737                              "&uploaded=%" PRIu32
     738                              "&downloaded=%" PRIu32
    739739                              "&left=%" PRIu64
    740740                              "&numwant=%d"
     
    757757
    758758    if( tier->byteCounts[TR_ANN_CORRUPT] )
    759         evbuffer_add_printf( buf, "&corrupt=%" PRIu64, tier->byteCounts[TR_ANN_CORRUPT] );
     759        evbuffer_add_printf( buf, "&corrupt=%" PRIu32, tier->byteCounts[TR_ANN_CORRUPT] );
    760760
    761761    str = eventName;
     
    781781        inet_ntop( AF_INET6, ipv6, ipv6_readable, INET6_ADDRSTRLEN );
    782782        evbuffer_add_printf( buf, "&ipv6=");
    783         tr_http_escape( buf, ipv6_readable, strlen(ipv6_readable), TRUE );
     783        tr_http_escape( buf, ipv6_readable, -1, TRUE );
    784784    }
    785785
     
    11701170
    11711171static uint8_t *
    1172 parseOldPeers( tr_benc * bePeers, size_t *  byteCount )
     1172parseOldPeers( tr_benc * bePeers, size_t * byteCount )
    11731173{
    11741174    int       i;
     
    11981198
    11991199        memcpy( walk, &addr, sizeof( tr_address ) );
    1200         port = htons( itmp );
     1200        port = htons( (uint16_t)itmp );
    12011201        memcpy( walk + sizeof( tr_address ), &port, 2 );
    12021202        walk += sizeof( tr_address ) + 2;
  • trunk/libtransmission/clients.c

    r10520 r10918  
    2323
    2424static int
    25 charint( char ch )
     25charint( uint8_t ch )
    2626{
    2727    if( '0' <= ch && ch <= '9' ) return      ch - '0';
     
    3232
    3333static int
    34 getShadowInt( char ch, int * setme )
     34getShadowInt( uint8_t ch, int * setme )
    3535{
    3636    const char * str = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.-";
     
    5252
    5353static const char*
    54 getMnemonicEnd( char ch )
     54getMnemonicEnd( uint8_t ch )
    5555{
    5656    switch( ch )
  • trunk/libtransmission/completion.h

    r10911 r10918  
    9393}
    9494
    95 static inline float tr_cpPercentComplete( const tr_completion * cp )
     95static inline double tr_cpPercentComplete( const tr_completion * cp )
    9696{
    9797    const double ratio = tr_getRatio( cp->sizeNow, tr_torrentInfo(cp->tor)->totalSize );
     
    104104}
    105105
    106 static inline float tr_cpPercentDone( const tr_completion * cp )
     106static inline double tr_cpPercentDone( const tr_completion * cp )
    107107{
    108108    const double ratio = tr_getRatio( cp->sizeNow, tr_cpSizeWhenDone( cp ) );
  • trunk/libtransmission/torrent-magnet.c

    r10842 r10918  
    349349}
    350350
    351 float
     351double
    352352tr_torrentGetMetadataPercent( const tr_torrent * tor )
    353353{
    354     float ret;
     354    double ret;
    355355
    356356    if( tr_torrentHasMetadata( tor ) )
     
    361361            ret = 0.0;
    362362        else
    363             ret = (m->pieceCount - m->piecesNeededCount) / (float)m->pieceCount;
     363            ret = (m->pieceCount - m->piecesNeededCount) / (double)m->pieceCount;
    364364    }
    365365
  • trunk/libtransmission/torrent-magnet.h

    r10774 r10918  
    3434void tr_torrentSetMetadataSizeHint( tr_torrent * tor, int metadata_size );
    3535
    36 float tr_torrentGetMetadataPercent( const tr_torrent * tor );
     36double tr_torrentGetMetadataPercent( const tr_torrent * tor );
    3737
    3838#endif
  • trunk/libtransmission/torrent.c

    r10912 r10918  
    18421842{
    18431843    tr_file *        file;
    1844     const uint8_t    dnd = !doDownload;
     1844    const int8_t     dnd = !doDownload;
    18451845    tr_piece_index_t firstPiece, firstPieceDND;
    18461846    tr_piece_index_t lastPiece, lastPieceDND;
  • trunk/libtransmission/torrent.h

    r10912 r10918  
    277277tr_torPieceCountBlocks( const tr_torrent * tor, const tr_piece_index_t piece )
    278278{
    279     return piece == tor->info.pieceCount - 1 ? tor->blockCountInLastPiece
    280                                              : tor->blockCountInPiece;
     279    if( piece + 1 == tor->info.pieceCount )
     280        return tor->blockCountInLastPiece;
     281    else
     282        return tor->blockCountInPiece;
    281283}
    282284
  • trunk/libtransmission/transmission.h

    r10912 r10918  
    6464typedef uint32_t tr_file_index_t;
    6565typedef uint32_t tr_piece_index_t;
    66 typedef uint64_t tr_block_index_t;
     66/* assuming a 16 KiB block, a 32-bit block index gives us a maximum torrent size of 63 TiB.
     67 * if we ever need to grow past that, change this to uint64_t ;) */
     68typedef uint32_t tr_block_index_t;
    6769typedef uint16_t tr_port;
    6870typedef uint8_t tr_bool;
     
    17221724        Range is [0..1]
    17231725        @see tr_stat.status */
    1724     float    recheckProgress;
     1726    double recheckProgress;
    17251727
    17261728    /** How much has been downloaded of the entire torrent.
    17271729        Range is [0..1] */
    1728     float    percentComplete;
     1730    double percentComplete;
    17291731
    17301732    /** How much of the metadata the torrent has.
     
    17321734        For magnet links, this number will from from 0 to 1 as the metadata is downloaded.
    17331735        Range is [0..1] */
    1734     float    metadataPercentComplete;
     1736    double metadataPercentComplete;
    17351737
    17361738    /** How much has been downloaded of the files the user wants.  This differs
     
    17381740        Range is [0..1]
    17391741        @see tr_stat.leftUntilDone */
    1740     float    percentDone;
     1742    double percentDone;
    17411743
    17421744    /** How much has been uploaded to satisfy the seed ratio.
    17431745        This is 1 if the ratio is reached or the torrent is set to seed forever.
    17441746        Range is [0..1] */
    1745     float    seedRatioPercentDone;
     1747    double seedRatioPercentDone;
    17461748
    17471749    /** Speed all data being sent for this torrent. (KiB/s)
  • trunk/libtransmission/utils.c

    r10916 r10918  
    867867
    868868double
    869 tr_getRatio( double numerator, double denominator )
     869tr_getRatio( uint64_t numerator, uint64_t denominator )
    870870{
    871871    double ratio;
    872872
    873     if( fabs(denominator) > 0.01 )
    874         ratio = numerator / denominator;
    875     else if( fabs(numerator) > 0.01 )
     873    if( denominator > 0 )
     874        ratio = numerator / (double)denominator;
     875    else if( numerator > 0 )
    876876        ratio = TR_RATIO_INF;
    877877    else
  • trunk/libtransmission/utils.h

    r10916 r10918  
    465465/** @brief return TR_RATIO_NA, TR_RATIO_INF, or a number in [0..1]
    466466    @return TR_RATIO_NA, TR_RATIO_INF, or a number in [0..1] */
    467 double tr_getRatio( double numerator, double denominator );
     467double tr_getRatio( uint64_t numerator, uint64_t denominator );
    468468
    469469/**
Note: See TracChangeset for help on using the changeset viewer.