diff --git a/libtransmission/announcer.c b/libtransmission/announcer.c index 0fbd380c3..841a4a104 100644 --- a/libtransmission/announcer.c +++ b/libtransmission/announcer.c @@ -77,8 +77,8 @@ enum ***/ static int -compareTransfer( int a_uploaded, int a_downloaded, - int b_uploaded, int b_downloaded ) +compareTransfer( uint32_t a_uploaded, uint32_t a_downloaded, + uint32_t b_uploaded, uint32_t b_downloaded ) { /* higher upload count goes first */ if( a_uploaded != b_uploaded ) @@ -136,7 +136,7 @@ getHostName( const char * url ) int port = 0; char * host = NULL; char * ret; - tr_urlParse( url, strlen( url ), NULL, &host, &port, NULL ); + tr_urlParse( url, -1, NULL, &host, &port, NULL ); ret = tr_strdup_printf( "%s:%d", ( host ? host : "invalid" ), port ); tr_free( host ); return ret; @@ -172,8 +172,8 @@ struct stop_message { tr_host * host; char * url; - int up; - int down; + uint32_t up; + uint32_t down; }; static void @@ -338,7 +338,7 @@ generateKeyParam( char * msg, size_t msglen ) { size_t i; const char * pool = "abcdefghijklmnopqrstuvwxyz0123456789"; - const int poolSize = strlen( pool ); + const int poolSize = 36; for( i=0; i=0 && leechers>=0 ) - return (int)((100.0*seeds)/(seeds+leechers)); + return (int8_t)((100.0*seeds)/(seeds+leechers)); return -1; /* unknown */ } @@ -734,8 +734,8 @@ createAnnounceURL( const tr_announcer * announcer, "info_hash=%s" "&peer_id=%s" "&port=%d" - "&uploaded=%" PRIu64 - "&downloaded=%" PRIu64 + "&uploaded=%" PRIu32 + "&downloaded=%" PRIu32 "&left=%" PRIu64 "&numwant=%d" "&key=%s" @@ -756,7 +756,7 @@ createAnnounceURL( const tr_announcer * announcer, evbuffer_add_printf( buf, "&requirecrypto=1" ); if( tier->byteCounts[TR_ANN_CORRUPT] ) - evbuffer_add_printf( buf, "&corrupt=%" PRIu64, tier->byteCounts[TR_ANN_CORRUPT] ); + evbuffer_add_printf( buf, "&corrupt=%" PRIu32, tier->byteCounts[TR_ANN_CORRUPT] ); str = eventName; if( str && *str ) @@ -780,7 +780,7 @@ createAnnounceURL( const tr_announcer * announcer, char ipv6_readable[INET6_ADDRSTRLEN]; inet_ntop( AF_INET6, ipv6, ipv6_readable, INET6_ADDRSTRLEN ); evbuffer_add_printf( buf, "&ipv6="); - tr_http_escape( buf, ipv6_readable, strlen(ipv6_readable), TRUE ); + tr_http_escape( buf, ipv6_readable, -1, TRUE ); } ret = tr_strndup( EVBUFFER_DATA( buf ), EVBUFFER_LENGTH( buf ) ); @@ -1169,7 +1169,7 @@ compareTiers( const void * va, const void * vb ) } static uint8_t * -parseOldPeers( tr_benc * bePeers, size_t * byteCount ) +parseOldPeers( tr_benc * bePeers, size_t * byteCount ) { int i; uint8_t * array, *walk; @@ -1197,7 +1197,7 @@ parseOldPeers( tr_benc * bePeers, size_t * byteCount ) continue; memcpy( walk, &addr, sizeof( tr_address ) ); - port = htons( itmp ); + port = htons( (uint16_t)itmp ); memcpy( walk + sizeof( tr_address ), &port, 2 ); walk += sizeof( tr_address ) + 2; } diff --git a/libtransmission/clients.c b/libtransmission/clients.c index 55dabfbb5..4c3c861cd 100644 --- a/libtransmission/clients.c +++ b/libtransmission/clients.c @@ -22,7 +22,7 @@ #include "utils.h" /* tr_snprintf(), tr_strlcpy() */ static int -charint( char ch ) +charint( uint8_t ch ) { if( '0' <= ch && ch <= '9' ) return ch - '0'; if( 'A' <= ch && ch <= 'Z' ) return 10 + ch - 'A'; @@ -31,7 +31,7 @@ charint( char ch ) } static int -getShadowInt( char ch, int * setme ) +getShadowInt( uint8_t ch, int * setme ) { const char * str = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.-"; const char * pch = strchr( str, ch ); @@ -51,7 +51,7 @@ strint( const void * pch, int span ) } static const char* -getMnemonicEnd( char ch ) +getMnemonicEnd( uint8_t ch ) { switch( ch ) { diff --git a/libtransmission/completion.h b/libtransmission/completion.h index 265798abe..1816ce613 100644 --- a/libtransmission/completion.h +++ b/libtransmission/completion.h @@ -92,7 +92,7 @@ static inline uint64_t tr_cpLeftUntilDone( const tr_completion * cp ) return tr_cpSizeWhenDone( cp ) - cp->sizeNow; } -static inline float tr_cpPercentComplete( const tr_completion * cp ) +static inline double tr_cpPercentComplete( const tr_completion * cp ) { const double ratio = tr_getRatio( cp->sizeNow, tr_torrentInfo(cp->tor)->totalSize ); if( (int)ratio == TR_RATIO_NA ) @@ -103,7 +103,7 @@ static inline float tr_cpPercentComplete( const tr_completion * cp ) return ratio; } -static inline float tr_cpPercentDone( const tr_completion * cp ) +static inline double tr_cpPercentDone( const tr_completion * cp ) { const double ratio = tr_getRatio( cp->sizeNow, tr_cpSizeWhenDone( cp ) ); const int iratio = (int)ratio; diff --git a/libtransmission/torrent-magnet.c b/libtransmission/torrent-magnet.c index 72ebebc86..d64167114 100644 --- a/libtransmission/torrent-magnet.c +++ b/libtransmission/torrent-magnet.c @@ -348,10 +348,10 @@ tr_torrentGetNextMetadataRequest( tr_torrent * tor, time_t now, int * setme_piec return have_request; } -float +double tr_torrentGetMetadataPercent( const tr_torrent * tor ) { - float ret; + double ret; if( tr_torrentHasMetadata( tor ) ) ret = 1.0; @@ -360,7 +360,7 @@ tr_torrentGetMetadataPercent( const tr_torrent * tor ) if( m == NULL ) ret = 0.0; else - ret = (m->pieceCount - m->piecesNeededCount) / (float)m->pieceCount; + ret = (m->pieceCount - m->piecesNeededCount) / (double)m->pieceCount; } return ret; diff --git a/libtransmission/torrent-magnet.h b/libtransmission/torrent-magnet.h index 52c4b016a..8de71c4fe 100644 --- a/libtransmission/torrent-magnet.h +++ b/libtransmission/torrent-magnet.h @@ -33,6 +33,6 @@ tr_bool tr_torrentGetNextMetadataRequest( tr_torrent * tor, time_t now, int * se void tr_torrentSetMetadataSizeHint( tr_torrent * tor, int metadata_size ); -float tr_torrentGetMetadataPercent( const tr_torrent * tor ); +double tr_torrentGetMetadataPercent( const tr_torrent * tor ); #endif diff --git a/libtransmission/torrent.c b/libtransmission/torrent.c index b253424df..ea9cb448b 100644 --- a/libtransmission/torrent.c +++ b/libtransmission/torrent.c @@ -1841,7 +1841,7 @@ static void setFileDND( tr_torrent * tor, tr_file_index_t fileIndex, int doDownload ) { tr_file * file; - const uint8_t dnd = !doDownload; + const int8_t dnd = !doDownload; tr_piece_index_t firstPiece, firstPieceDND; tr_piece_index_t lastPiece, lastPieceDND; tr_file_index_t i; diff --git a/libtransmission/torrent.h b/libtransmission/torrent.h index 0c221dfaf..04b90ae07 100644 --- a/libtransmission/torrent.h +++ b/libtransmission/torrent.h @@ -276,8 +276,10 @@ tr_torBlockPiece( const tr_torrent * tor, const tr_block_index_t block ) static inline uint16_t tr_torPieceCountBlocks( const tr_torrent * tor, const tr_piece_index_t piece ) { - return piece == tor->info.pieceCount - 1 ? tor->blockCountInLastPiece - : tor->blockCountInPiece; + if( piece + 1 == tor->info.pieceCount ) + return tor->blockCountInLastPiece; + else + return tor->blockCountInPiece; } /* how many bytes are in this piece? */ diff --git a/libtransmission/transmission.h b/libtransmission/transmission.h index 52a832b29..4c6a48a3a 100644 --- a/libtransmission/transmission.h +++ b/libtransmission/transmission.h @@ -63,7 +63,9 @@ extern "C" { typedef uint32_t tr_file_index_t; typedef uint32_t tr_piece_index_t; -typedef uint64_t tr_block_index_t; +/* assuming a 16 KiB block, a 32-bit block index gives us a maximum torrent size of 63 TiB. + * if we ever need to grow past that, change this to uint64_t ;) */ +typedef uint32_t tr_block_index_t; typedef uint16_t tr_port; typedef uint8_t tr_bool; @@ -1721,28 +1723,28 @@ typedef struct tr_stat verified. When it gets to 1, the verify process is done. Range is [0..1] @see tr_stat.status */ - float recheckProgress; + double recheckProgress; /** How much has been downloaded of the entire torrent. Range is [0..1] */ - float percentComplete; + double percentComplete; /** How much of the metadata the torrent has. For torrents added from a .torrent this will always be 1. For magnet links, this number will from from 0 to 1 as the metadata is downloaded. Range is [0..1] */ - float metadataPercentComplete; + double metadataPercentComplete; /** How much has been downloaded of the files the user wants. This differs from percentComplete if the user wants only some of the torrent's files. Range is [0..1] @see tr_stat.leftUntilDone */ - float percentDone; + double percentDone; /** How much has been uploaded to satisfy the seed ratio. This is 1 if the ratio is reached or the torrent is set to seed forever. Range is [0..1] */ - float seedRatioPercentDone; + double seedRatioPercentDone; /** Speed all data being sent for this torrent. (KiB/s) This includes piece data, protocol messages, and TCP overhead */ diff --git a/libtransmission/utils.c b/libtransmission/utils.c index 2af98c52f..54d45d4a8 100644 --- a/libtransmission/utils.c +++ b/libtransmission/utils.c @@ -866,13 +866,13 @@ tr_strlcpy( char * dst, ***/ double -tr_getRatio( double numerator, double denominator ) +tr_getRatio( uint64_t numerator, uint64_t denominator ) { double ratio; - if( fabs(denominator) > 0.01 ) - ratio = numerator / denominator; - else if( fabs(numerator) > 0.01 ) + if( denominator > 0 ) + ratio = numerator / (double)denominator; + else if( numerator > 0 ) ratio = TR_RATIO_INF; else ratio = TR_RATIO_NA; diff --git a/libtransmission/utils.h b/libtransmission/utils.h index bd605dd7a..5b223dc2a 100644 --- a/libtransmission/utils.h +++ b/libtransmission/utils.h @@ -464,7 +464,7 @@ int tr_urlParse( const char * url, /** @brief return TR_RATIO_NA, TR_RATIO_INF, or a number in [0..1] @return TR_RATIO_NA, TR_RATIO_INF, or a number in [0..1] */ -double tr_getRatio( double numerator, double denominator ); +double tr_getRatio( uint64_t numerator, uint64_t denominator ); /** * @brief Given a string like "1-4" or "1-4,6,9,14-51", this returns a