Changeset 10912


Ignore:
Timestamp:
Jun 30, 2010, 4:40:19 PM (12 years ago)
Author:
charles
Message:

(trunk libT) down the rabbit hole: various minor type correctness changes unearthed by -Wconversion

Location:
trunk/libtransmission
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/bencode.c

    r10816 r10912  
    6666
    6767static void
    68 tr_bencInit( tr_benc * val,
    69              int       type )
     68tr_bencInit( tr_benc * val, char type )
    7069{
    7170    memset( val, 0, sizeof( *val ) );
     
    469468
    470469tr_bool
    471 tr_bencGetStr( const tr_benc * val,
    472                const char **   setme )
    473 {
    474     const int success = tr_bencIsString( val );
     470tr_bencGetStr( const tr_benc * val, const char ** setme )
     471{
     472    const tr_bool success = tr_bencIsString( val );
    475473
    476474    if( success )
  • trunk/libtransmission/completion.c

    r10387 r10912  
    187187tr_cpBlockBitfieldSet( tr_completion * cp, tr_bitfield * blockBitfield )
    188188{
    189     int success = FALSE;
     189    tr_bool success = FALSE;
    190190
    191191    assert( cp );
     
    199199        tr_piece_index_t p = 0;
    200200        uint32_t pieceBlock = 0;
    201         uint32_t completeBlocksInPiece = 0;
     201        uint16_t completeBlocksInPiece = 0;
    202202        tr_block_index_t completeBlocksInTorrent = 0;
    203203        uint32_t blocksInCurrentPiece = tr_torPieceCountBlocks( cp->tor, p );
  • trunk/libtransmission/crypto.c

    r10662 r10912  
    369369tr_ssha1( const void * plaintext )
    370370{
     371    enum { saltval_len = 8,
     372           salter_len  = 64 };
    371373    static const char * salter = "0123456789"
    372374                                 "abcdefghijklmnopqrstuvwxyz"
    373375                                 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    374376                                 "./";
    375     const size_t salter_len = 64;
    376     const size_t saltval_len = 8;
    377377
    378378    size_t i;
  • trunk/libtransmission/handshake.c

    r10814 r10912  
    100100                                                                    ( val ) )
    101101
     102typedef uint8_t handshake_state_t;
     103
    102104struct tr_handshake
    103105{
     
    109111    tr_session *          session;
    110112    uint8_t               mySecret[KEY_LEN];
    111     uint8_t               state;
     113    handshake_state_t     state;
    112114    tr_encryption_mode    encryptionMode;
    113115    uint16_t              pad_c_len;
     
    156158
    157159static const char*
    158 getStateName( short state )
     160getStateName( const handshake_state_t state )
    159161{
    160162    const char * str = "f00!";
     
    199201
    200202static void
    201 setState( tr_handshake * handshake,
    202           short          state )
     203setState( tr_handshake * handshake, handshake_state_t state )
    203204{
    204205    dbgmsg( handshake, "setting to state [%s]", getStateName( state ) );
     
    207208
    208209static void
    209 setReadState( tr_handshake * handshake,
    210               int            state )
     210setReadState( tr_handshake * handshake, handshake_state_t state )
    211211{
    212212    setState( handshake, state );
     
    589589    tr_free( tmp );
    590590
    591     tr_peerIoSetEncryption( handshake->io,
    592                             handshake->crypto_select );
     591    tr_peerIoSetEncryption( handshake->io, handshake->crypto_select );
    593592
    594593    setState( handshake, AWAITING_HANDSHAKE );
     
    726725            struct evbuffer * inbuf )
    727726{
    728     int peerIsGood;
     727    tr_bool peerIsGood;
    729728    char client[128];
    730729    tr_torrent * tor;
     
    747746    tor_peer_id = tor && tor->peer_id ? tor->peer_id : tr_getPeerId( );
    748747    peerIsGood = memcmp( peer_id, tor_peer_id, PEER_ID_LEN ) != 0;
    749     dbgmsg( handshake, "isPeerGood == %d", peerIsGood );
     748    dbgmsg( handshake, "isPeerGood == %d", (int)peerIsGood );
    750749    return tr_handshakeDone( handshake, peerIsGood );
    751750}
     
    966965     * standard practice at this time is for it to be zero-length */
    967966    {
    968         const int len = 0;
     967        const uint16_t len = 0;
    969968        tr_peerIoWriteUint16( handshake->io, outbuf, len );
    970969    }
     
    10971096}
    10981097
    1099 static int
    1100 fireDoneFunc( tr_handshake * handshake,
    1101               tr_bool        isConnected )
     1098static tr_bool
     1099fireDoneFunc( tr_handshake * handshake, tr_bool isConnected )
    11021100{
    11031101    const uint8_t * peer_id = isConnected && handshake->havePeerID
    11041102                            ? tr_peerIoGetPeersId( handshake->io )
    11051103                            : NULL;
    1106     const int success = ( *handshake->doneCB )( handshake,
    1107                                                 handshake->io,
    1108                                                 handshake->haveReadAnythingFromPeer,
    1109                                                 isConnected,
    1110                                                 peer_id,
    1111                                                 handshake->doneUserData );
     1104    const tr_bool success = ( *handshake->doneCB )( handshake,
     1105                                                    handshake->io,
     1106                                                    handshake->haveReadAnythingFromPeer,
     1107                                                    isConnected,
     1108                                                    peer_id,
     1109                                                    handshake->doneUserData );
    11121110
    11131111    return success;
  • trunk/libtransmission/peer-io.c

    r10694 r10912  
    635635tr_peerIoReconnect( tr_peerIo * io )
    636636{
    637     int pendingEvents;
     637    short int pendingEvents;
    638638    tr_session * session;
    639639
     
    746746
    747747void
    748 tr_peerIoSetEncryption( tr_peerIo * io,
    749                         int         encryptionMode )
     748tr_peerIoSetEncryption( tr_peerIo * io, uint32_t encryptionMode )
    750749{
    751750    assert( tr_isPeerIo( io ) );
  • trunk/libtransmission/peer-io.h

    r10671 r10912  
    7878    tr_priority_t         priority;
    7979
    80     int                   pendingEvents;
     80    short int             pendingEvents;
    8181
    8282    int                   magicNumber;
    8383
    84     uint8_t               encryptionMode;
     84    uint32_t              encryptionMode;
    8585    tr_bool               isSeed;
    8686
     
    277277EncryptionMode;
    278278
    279 void      tr_peerIoSetEncryption( tr_peerIo * io,
    280                                   int         encryptionMode );
    281 
    282 static inline tr_bool tr_peerIoIsEncrypted( const tr_peerIo * io )
     279void tr_peerIoSetEncryption( tr_peerIo * io, uint32_t encryptionMode );
     280
     281static inline tr_bool
     282tr_peerIoIsEncrypted( const tr_peerIo * io )
    283283{
    284284    return ( io != NULL ) && ( io->encryptionMode == PEER_ENCRYPTION_RC4 );
  • trunk/libtransmission/torrent.c

    r10851 r10912  
    371371        {
    372372            size_t i, n;
    373             const int seedProbability = event->seedProbability;
     373            const int8_t seedProbability = event->seedProbability;
    374374            const tr_bool allAreSeeds = seedProbability == 100;
    375375            tr_pex * pex = tr_peerMgrArrayToPex( event->compact,
     
    417417***/
    418418
    419 static int
    420 getBytePiece( const tr_info * info,
    421               uint64_t        byteOffset )
     419static tr_piece_index_t
     420getBytePiece( const tr_info * info, uint64_t byteOffset )
    422421{
    423422    assert( info );
     
    457456{
    458457    tr_file_index_t i;
    459     int            priority = TR_PRI_LOW;
     458    tr_priority_t priority = TR_PRI_LOW;
    460459
    461460    /* find the first file that has data in this piece */
     
    568567
    569568    if( info->pieceSize )
    570         tor->lastPieceSize = info->totalSize % info->pieceSize;
     569        tor->lastPieceSize = (uint32_t)(info->totalSize % info->pieceSize);
    571570
    572571    if( !tor->lastPieceSize )
     
    984983
    985984    s->recheckProgress = s->activity == TR_STATUS_CHECK
    986                        ? 1.0 -
    987                          ( tr_torrentCountUncheckedPieces( tor ) /
    988                            (double) tor->info.pieceCount )
     985                       ? 1.0 - ( tr_torrentCountUncheckedPieces( tor ) / (float) tor->info.pieceCount )
    989986                       : 0.0;
    990987
     
    18451842{
    18461843    tr_file *        file;
    1847     const int        dnd = !doDownload;
     1844    const uint8_t    dnd = !doDownload;
    18481845    tr_piece_index_t firstPiece, firstPieceDND;
    18491846    tr_piece_index_t lastPiece, lastPieceDND;
  • trunk/libtransmission/torrent.h

    r10848 r10912  
    186186    uint32_t                   lastPieceSize;
    187187
    188     uint32_t                   blockCountInPiece;
    189     uint32_t                   blockCountInLastPiece;
     188    uint16_t                   blockCountInPiece;
     189    uint16_t                   blockCountInLastPiece;
    190190
    191191    struct tr_completion       completion;
     
    274274
    275275/* how many blocks are in this piece? */
    276 static inline uint32_t
     276static inline uint16_t
    277277tr_torPieceCountBlocks( const tr_torrent * tor, const tr_piece_index_t piece )
    278278{
  • trunk/libtransmission/tr-lpd.c

    r10714 r10912  
    512512
    513513        /* determine announced peer port, refuse if value too large */
    514         if( sscanf( value, "%u", &peerPort ) != 1 || peerPort > (in_port_t)-1 )
     514        if( sscanf( value, "%d", &peerPort ) != 1 || peerPort > (in_port_t)-1 )
    515515            return 0;
    516516
  • trunk/libtransmission/transmission.h

    r10851 r10912  
    772772*/
    773773
    774 enum
     774typedef enum
    775775{
    776776    TR_MSG_ERR = 1,
    777777    TR_MSG_INF = 2,
    778778    TR_MSG_DBG = 3
    779 };
    780 void tr_setMessageLevel( int );
    781 
    782 int  tr_getMessageLevel( void );
     779}
     780tr_msg_level;
     781
     782void tr_setMessageLevel( tr_msg_level );
     783
     784tr_msg_level tr_getMessageLevel( void );
    783785
    784786typedef struct tr_msg_list
    785787{
    786788    /* TR_MSG_ERR, TR_MSG_INF, or TR_MSG_DBG */
    787     uint8_t level;
     789    tr_msg_level level;
    788790
    789791    /* The line number in the source file where this message originated */
  • trunk/libtransmission/utils.c

    r10911 r10912  
    5757time_t transmission_now = 0;
    5858
    59 int                  messageLevel = TR_MSG_INF;
     59tr_msg_level messageLevel = TR_MSG_INF;
    6060static tr_lock *      messageLock = NULL;
    6161static tr_bool        messageQueuing = FALSE;
     
    115115
    116116void
    117 tr_setMessageLevel( int level )
    118 {
    119     messageLevel = MAX( 0, level );
    120 }
    121 
    122 int
     117tr_setMessageLevel( tr_msg_level level )
     118{
     119    messageLevel = level;
     120}
     121
     122tr_msg_level
    123123tr_getMessageLevel( void )
    124124{
     
    256256void
    257257tr_msg( const char * file, int line,
    258         int level, const char * name,
     258        tr_msg_level level,
     259        const char * name,
    259260        const char * fmt, ... )
    260261{
     
    464465    int fd;
    465466    ssize_t n;
    466     const char * err_fmt = _( "Couldn't read \"%1$s\": %2$s" );
     467    const char * const err_fmt = _( "Couldn't read \"%1$s\": %2$s" );
    467468
    468469    /* try to stat the file */
     
    501502        return NULL;
    502503    }
    503     n = read( fd, buf, sb.st_size );
     504    n = read( fd, buf, (size_t)sb.st_size );
    504505    if( n == -1 )
    505506    {
     
    13921393    struct stat st;
    13931394    off_t bytesLeft;
    1394     const off_t buflen = 1024 * 128; /* 128 KiB buffer */
     1395    const size_t buflen = 1024 * 128; /* 128 KiB buffer */
    13951396
    13961397    /* make sure the old file exists */
  • trunk/libtransmission/utils.h

    r10909 r10912  
    119119#define TR_MAX_MSG_LOG 10000
    120120
    121 extern int messageLevel;
    122 
    123 static inline tr_bool tr_msgLoggingIsActive( int level )
     121extern tr_msg_level messageLevel;
     122
     123static inline tr_bool tr_msgLoggingIsActive( tr_msg_level level )
    124124{
    125125    return messageLevel >= level;
     
    127127
    128128void tr_msg( const char * file, int line,
    129              int level,
     129             tr_msg_level level,
    130130             const char * torrent,
    131131             const char * fmt, ... ) TR_GNUC_PRINTF( 5, 6 );
  • trunk/libtransmission/verify.c

    r10904 r10912  
    6161    const time_t begin = tr_time( );
    6262    time_t end;
    63     const int64_t buflen = 1024 * 128; /* 128 KiB buffer */
     63    const size_t buflen = 1024 * 128; /* 128 KiB buffer */
    6464    uint8_t * buffer = tr_valloc( buflen );
    6565
     
    7070    while( !*stopFlag && ( pieceIndex < tor->info.pieceCount ) )
    7171    {
    72         int64_t leftInPiece;
    73         int64_t leftInFile;
    74         int64_t bytesThisPass;
     72        uint32_t leftInPiece;
     73        uint32_t bytesThisPass;
     74        uint64_t leftInFile;
    7575        const tr_file * file = &tor->info.files[fileIndex];
    7676
     
    102102        if( fd >= 0 ) {
    103103            const ssize_t numRead = tr_pread( fd, buffer, bytesThisPass, filePos );
    104             if( numRead == bytesThisPass )
     104            if( numRead == (ssize_t)bytesThisPass )
    105105                SHA1_Update( &sha, buffer, numRead );
    106106            if( numRead > 0 ) {
Note: See TracChangeset for help on using the changeset viewer.