1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2025-03-12 07:03:44 +00:00

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

This commit is contained in:
Charles Kerr 2010-06-30 16:40:19 +00:00
parent 77a2cf02f1
commit 254a1f15cb
13 changed files with 67 additions and 72 deletions

View file

@ -65,8 +65,7 @@ isSomething( const tr_benc * val )
}
static void
tr_bencInit( tr_benc * val,
int type )
tr_bencInit( tr_benc * val, char type )
{
memset( val, 0, sizeof( *val ) );
val->type = type;
@ -468,10 +467,9 @@ tr_bencGetInt( const tr_benc * val,
}
tr_bool
tr_bencGetStr( const tr_benc * val,
const char ** setme )
tr_bencGetStr( const tr_benc * val, const char ** setme )
{
const int success = tr_bencIsString( val );
const tr_bool success = tr_bencIsString( val );
if( success )
*setme = getStr( val );

View file

@ -186,7 +186,7 @@ tr_cpSetHaveAll( tr_completion * cp )
tr_bool
tr_cpBlockBitfieldSet( tr_completion * cp, tr_bitfield * blockBitfield )
{
int success = FALSE;
tr_bool success = FALSE;
assert( cp );
assert( blockBitfield );
@ -198,7 +198,7 @@ tr_cpBlockBitfieldSet( tr_completion * cp, tr_bitfield * blockBitfield )
tr_block_index_t b = 0;
tr_piece_index_t p = 0;
uint32_t pieceBlock = 0;
uint32_t completeBlocksInPiece = 0;
uint16_t completeBlocksInPiece = 0;
tr_block_index_t completeBlocksInTorrent = 0;
uint32_t blocksInCurrentPiece = tr_torPieceCountBlocks( cp->tor, p );

View file

@ -368,12 +368,12 @@ tr_cryptoRandBuf( void * buf, size_t len )
char*
tr_ssha1( const void * plaintext )
{
enum { saltval_len = 8,
salter_len = 64 };
static const char * salter = "0123456789"
"abcdefghijklmnopqrstuvwxyz"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"./";
const size_t salter_len = 64;
const size_t saltval_len = 8;
size_t i;
char salt[saltval_len];

View file

@ -99,6 +99,8 @@ enum
#define HANDSHAKE_SET_EXTPREF( reserved, val ) ( ( reserved )[5] |= 0x03 &\
( val ) )
typedef uint8_t handshake_state_t;
struct tr_handshake
{
tr_bool haveReadAnythingFromPeer;
@ -108,7 +110,7 @@ struct tr_handshake
tr_crypto * crypto;
tr_session * session;
uint8_t mySecret[KEY_LEN];
uint8_t state;
handshake_state_t state;
tr_encryption_mode encryptionMode;
uint16_t pad_c_len;
uint16_t pad_d_len;
@ -155,7 +157,7 @@ enum
} while( 0 )
static const char*
getStateName( short state )
getStateName( const handshake_state_t state )
{
const char * str = "f00!";
@ -198,16 +200,14 @@ getStateName( short state )
}
static void
setState( tr_handshake * handshake,
short state )
setState( tr_handshake * handshake, handshake_state_t state )
{
dbgmsg( handshake, "setting to state [%s]", getStateName( state ) );
handshake->state = state;
}
static void
setReadState( tr_handshake * handshake,
int state )
setReadState( tr_handshake * handshake, handshake_state_t state )
{
setState( handshake, state );
}
@ -588,8 +588,7 @@ readPadD( tr_handshake * handshake,
tr_peerIoReadBytes( handshake->io, inbuf, tmp, needlen );
tr_free( tmp );
tr_peerIoSetEncryption( handshake->io,
handshake->crypto_select );
tr_peerIoSetEncryption( handshake->io, handshake->crypto_select );
setState( handshake, AWAITING_HANDSHAKE );
return READ_NOW;
@ -725,7 +724,7 @@ static int
readPeerId( tr_handshake * handshake,
struct evbuffer * inbuf )
{
int peerIsGood;
tr_bool peerIsGood;
char client[128];
tr_torrent * tor;
const uint8_t * tor_peer_id;
@ -746,7 +745,7 @@ readPeerId( tr_handshake * handshake,
tor = tr_torrentFindFromHash( handshake->session, tr_peerIoGetTorrentHash( handshake->io ) );
tor_peer_id = tor && tor->peer_id ? tor->peer_id : tr_getPeerId( );
peerIsGood = memcmp( peer_id, tor_peer_id, PEER_ID_LEN ) != 0;
dbgmsg( handshake, "isPeerGood == %d", peerIsGood );
dbgmsg( handshake, "isPeerGood == %d", (int)peerIsGood );
return tr_handshakeDone( handshake, peerIsGood );
}
@ -965,7 +964,7 @@ readIA( tr_handshake * handshake,
* PadD is reserved for future extensions to the handshake...
* standard practice at this time is for it to be zero-length */
{
const int len = 0;
const uint16_t len = 0;
tr_peerIoWriteUint16( handshake->io, outbuf, len );
}
@ -1096,19 +1095,18 @@ canRead( struct tr_peerIo * io, void * arg, size_t * piece )
return ret;
}
static int
fireDoneFunc( tr_handshake * handshake,
tr_bool isConnected )
static tr_bool
fireDoneFunc( tr_handshake * handshake, tr_bool isConnected )
{
const uint8_t * peer_id = isConnected && handshake->havePeerID
? tr_peerIoGetPeersId( handshake->io )
: NULL;
const int success = ( *handshake->doneCB )( handshake,
handshake->io,
handshake->haveReadAnythingFromPeer,
isConnected,
peer_id,
handshake->doneUserData );
const tr_bool success = ( *handshake->doneCB )( handshake,
handshake->io,
handshake->haveReadAnythingFromPeer,
isConnected,
peer_id,
handshake->doneUserData );
return success;
}

View file

@ -634,7 +634,7 @@ tr_peerIoClear( tr_peerIo * io )
int
tr_peerIoReconnect( tr_peerIo * io )
{
int pendingEvents;
short int pendingEvents;
tr_session * session;
assert( tr_isPeerIo( io ) );
@ -745,8 +745,7 @@ tr_peerIoGetWriteBufferSpace( const tr_peerIo * io, uint64_t now )
**/
void
tr_peerIoSetEncryption( tr_peerIo * io,
int encryptionMode )
tr_peerIoSetEncryption( tr_peerIo * io, uint32_t encryptionMode )
{
assert( tr_isPeerIo( io ) );
assert( encryptionMode == PEER_ENCRYPTION_NONE

View file

@ -77,11 +77,11 @@ typedef struct tr_peerIo
tr_priority_t priority;
int pendingEvents;
short int pendingEvents;
int magicNumber;
uint8_t encryptionMode;
uint32_t encryptionMode;
tr_bool isSeed;
tr_port port;
@ -276,10 +276,10 @@ typedef enum
}
EncryptionMode;
void tr_peerIoSetEncryption( tr_peerIo * io,
int encryptionMode );
void tr_peerIoSetEncryption( tr_peerIo * io, uint32_t encryptionMode );
static inline tr_bool tr_peerIoIsEncrypted( const tr_peerIo * io )
static inline tr_bool
tr_peerIoIsEncrypted( const tr_peerIo * io )
{
return ( io != NULL ) && ( io->encryptionMode == PEER_ENCRYPTION_RC4 );
}

View file

@ -370,7 +370,7 @@ onTrackerResponse( tr_torrent * tor, const tr_tracker_event * event, void * unus
case TR_TRACKER_PEERS:
{
size_t i, n;
const int seedProbability = event->seedProbability;
const int8_t seedProbability = event->seedProbability;
const tr_bool allAreSeeds = seedProbability == 100;
tr_pex * pex = tr_peerMgrArrayToPex( event->compact,
event->compactLen, &n );
@ -416,9 +416,8 @@ onTrackerResponse( tr_torrent * tor, const tr_tracker_event * event, void * unus
****
***/
static int
getBytePiece( const tr_info * info,
uint64_t byteOffset )
static tr_piece_index_t
getBytePiece( const tr_info * info, uint64_t byteOffset )
{
assert( info );
assert( info->pieceSize != 0 );
@ -456,7 +455,7 @@ calculatePiecePriority( const tr_torrent * tor,
int fileHint )
{
tr_file_index_t i;
int priority = TR_PRI_LOW;
tr_priority_t priority = TR_PRI_LOW;
/* find the first file that has data in this piece */
if( fileHint >= 0 ) {
@ -567,7 +566,7 @@ torrentInitFromInfo( tr_torrent * tor )
tor->blockSize = tr_getBlockSize( info->pieceSize );
if( info->pieceSize )
tor->lastPieceSize = info->totalSize % info->pieceSize;
tor->lastPieceSize = (uint32_t)(info->totalSize % info->pieceSize);
if( !tor->lastPieceSize )
tor->lastPieceSize = info->pieceSize;
@ -983,9 +982,7 @@ tr_torrentStat( tr_torrent * tor )
s->sizeWhenDone = tr_cpSizeWhenDone ( &tor->completion );
s->recheckProgress = s->activity == TR_STATUS_CHECK
? 1.0 -
( tr_torrentCountUncheckedPieces( tor ) /
(double) tor->info.pieceCount )
? 1.0 - ( tr_torrentCountUncheckedPieces( tor ) / (float) tor->info.pieceCount )
: 0.0;
s->activityDate = tor->activityDate;
@ -1844,7 +1841,7 @@ static void
setFileDND( tr_torrent * tor, tr_file_index_t fileIndex, int doDownload )
{
tr_file * file;
const int dnd = !doDownload;
const uint8_t dnd = !doDownload;
tr_piece_index_t firstPiece, firstPieceDND;
tr_piece_index_t lastPiece, lastPieceDND;
tr_file_index_t i;

View file

@ -185,8 +185,8 @@ struct tr_torrent
uint32_t lastBlockSize;
uint32_t lastPieceSize;
uint32_t blockCountInPiece;
uint32_t blockCountInLastPiece;
uint16_t blockCountInPiece;
uint16_t blockCountInLastPiece;
struct tr_completion completion;
@ -273,7 +273,7 @@ tr_torBlockPiece( const tr_torrent * tor, const tr_block_index_t block )
}
/* how many blocks are in this piece? */
static inline uint32_t
static inline uint16_t
tr_torPieceCountBlocks( const tr_torrent * tor, const tr_piece_index_t piece )
{
return piece == tor->info.pieceCount - 1 ? tor->blockCountInLastPiece

View file

@ -511,7 +511,7 @@ static int tr_lpdConsiderAnnounce( tr_pex* peer, const char* const msg )
return 0;
/* determine announced peer port, refuse if value too large */
if( sscanf( value, "%u", &peerPort ) != 1 || peerPort > (in_port_t)-1 )
if( sscanf( value, "%d", &peerPort ) != 1 || peerPort > (in_port_t)-1 )
return 0;
peer->port = htons( peerPort );

View file

@ -771,20 +771,22 @@ void tr_sessionSetTorrentDoneScript( tr_session *, const char * scriptFilename )
** Message Logging
*/
enum
typedef enum
{
TR_MSG_ERR = 1,
TR_MSG_INF = 2,
TR_MSG_DBG = 3
};
void tr_setMessageLevel( int );
}
tr_msg_level;
int tr_getMessageLevel( void );
void tr_setMessageLevel( tr_msg_level );
tr_msg_level tr_getMessageLevel( void );
typedef struct tr_msg_list
{
/* TR_MSG_ERR, TR_MSG_INF, or TR_MSG_DBG */
uint8_t level;
tr_msg_level level;
/* The line number in the source file where this message originated */
int line;

View file

@ -56,7 +56,7 @@
time_t transmission_now = 0;
int messageLevel = TR_MSG_INF;
tr_msg_level messageLevel = TR_MSG_INF;
static tr_lock * messageLock = NULL;
static tr_bool messageQueuing = FALSE;
static tr_msg_list * messageQueue = NULL;
@ -114,12 +114,12 @@ tr_getLog( void )
}
void
tr_setMessageLevel( int level )
tr_setMessageLevel( tr_msg_level level )
{
messageLevel = MAX( 0, level );
messageLevel = level;
}
int
tr_msg_level
tr_getMessageLevel( void )
{
return messageLevel;
@ -255,7 +255,8 @@ tr_deepLog( const char * file,
void
tr_msg( const char * file, int line,
int level, const char * name,
tr_msg_level level,
const char * name,
const char * fmt, ... )
{
const int err = errno; /* message logging shouldn't affect errno */
@ -463,7 +464,7 @@ tr_loadFile( const char * path,
struct stat sb;
int fd;
ssize_t n;
const char * err_fmt = _( "Couldn't read \"%1$s\": %2$s" );
const char * const err_fmt = _( "Couldn't read \"%1$s\": %2$s" );
/* try to stat the file */
errno = 0;
@ -500,7 +501,7 @@ tr_loadFile( const char * path,
errno = err;
return NULL;
}
n = read( fd, buf, sb.st_size );
n = read( fd, buf, (size_t)sb.st_size );
if( n == -1 )
{
const int err = errno;
@ -1391,7 +1392,7 @@ tr_moveFile( const char * oldpath, const char * newpath, tr_bool * renamed )
char * buf;
struct stat st;
off_t bytesLeft;
const off_t buflen = 1024 * 128; /* 128 KiB buffer */
const size_t buflen = 1024 * 128; /* 128 KiB buffer */
/* make sure the old file exists */
if( stat( oldpath, &st ) ) {

View file

@ -118,15 +118,15 @@ void tr_msgInit( void );
#define TR_MAX_MSG_LOG 10000
extern int messageLevel;
extern tr_msg_level messageLevel;
static inline tr_bool tr_msgLoggingIsActive( int level )
static inline tr_bool tr_msgLoggingIsActive( tr_msg_level level )
{
return messageLevel >= level;
}
void tr_msg( const char * file, int line,
int level,
tr_msg_level level,
const char * torrent,
const char * fmt, ... ) TR_GNUC_PRINTF( 5, 6 );

View file

@ -60,7 +60,7 @@ verifyTorrent( tr_torrent * tor, tr_bool * stopFlag )
tr_piece_index_t pieceIndex = 0;
const time_t begin = tr_time( );
time_t end;
const int64_t buflen = 1024 * 128; /* 128 KiB buffer */
const size_t buflen = 1024 * 128; /* 128 KiB buffer */
uint8_t * buffer = tr_valloc( buflen );
tr_torrentUncheck( tor );
@ -69,9 +69,9 @@ verifyTorrent( tr_torrent * tor, tr_bool * stopFlag )
while( !*stopFlag && ( pieceIndex < tor->info.pieceCount ) )
{
int64_t leftInPiece;
int64_t leftInFile;
int64_t bytesThisPass;
uint32_t leftInPiece;
uint32_t bytesThisPass;
uint64_t leftInFile;
const tr_file * file = &tor->info.files[fileIndex];
/* if we're starting a new piece... */
@ -101,7 +101,7 @@ verifyTorrent( tr_torrent * tor, tr_bool * stopFlag )
/* read a bit */
if( fd >= 0 ) {
const ssize_t numRead = tr_pread( fd, buffer, bytesThisPass, filePos );
if( numRead == bytesThisPass )
if( numRead == (ssize_t)bytesThisPass )
SHA1_Update( &sha, buffer, numRead );
if( numRead > 0 ) {
pieceBytesRead += numRead;