(libT) change benc's integral type from int to size_t, squashing a couple of minor warnings

This commit is contained in:
Charles Kerr 2008-09-04 14:42:32 +00:00
parent 628d05d220
commit 419242e36f
9 changed files with 56 additions and 57 deletions

View File

@ -1272,15 +1272,15 @@ tr_prefs_dialog_new( GObject * core, GtkWindow * parent )
gtk_notebook_append_page( GTK_NOTEBOOK( n ),
peerPage( core ),
gtk_label_new (_("Peers")) );
gtk_notebook_append_page( GTK_NOTEBOOK( n ),
networkPage( core ),
gtk_label_new (_("Network")) );
gtk_notebook_append_page( GTK_NOTEBOOK( n ),
trackerPage( core ),
gtk_label_new (_("Trackers")) );
gtk_notebook_append_page( GTK_NOTEBOOK( n ),
bandwidthPage( core ),
gtk_label_new (_("Bandwidth")) );
gtk_notebook_append_page( GTK_NOTEBOOK( n ),
networkPage( core ),
gtk_label_new (_("Network")) );
gtk_notebook_append_page( GTK_NOTEBOOK( n ),
webPage( core ),
gtk_label_new (_("Web")) );

View File

@ -153,7 +153,7 @@ tr_bencParseStr( const uint8_t * buf,
#define LIST_SIZE 8 /* number of items to increment list/dict buffer by */
static int
makeroom( tr_benc * val, int count )
makeroom( tr_benc * val, size_t count )
{
assert( TYPE_LIST == val->type || TYPE_DICT == val->type );
@ -331,7 +331,7 @@ tr_bencParse( const void * buf,
int
tr_bencLoad( const void * buf_in,
int buflen,
size_t buflen,
tr_benc * setme_benc,
char ** setme_end )
{
@ -352,8 +352,8 @@ dictIndexOf( const tr_benc * val, const char * key )
{
if( tr_bencIsDict( val ) )
{
int i;
const int len = strlen( key );
size_t i;
const size_t len = strlen( key );
for( i=0; (i+1)<val->val.l.count; i+=2 )
{
@ -383,17 +383,17 @@ tr_bencDictFindType( tr_benc * val, const char * key, int type )
return ( ret && ( ret->type == type ) ) ? ret : NULL;
}
int
size_t
tr_bencListSize( const tr_benc * list )
{
return tr_bencIsList( list ) ? list->val.l.count : 0;
}
tr_benc*
tr_bencListChild( tr_benc * val, int i )
tr_bencListChild( tr_benc * val, size_t i )
{
tr_benc * ret = NULL;
if( tr_bencIsList( val ) && ( i >= 0 ) && ( i < val->val.l.count ) )
if( tr_bencIsList( val ) && ( i < val->val.l.count ) )
ret = val->val.l.vals + i;
return ret;
}
@ -524,31 +524,31 @@ tr_bencInitInt( tr_benc * val, int64_t num )
}
int
tr_bencInitList( tr_benc * val, int reserveCount )
tr_bencInitList( tr_benc * val, size_t reserveCount )
{
tr_bencInit( val, TYPE_LIST );
return tr_bencListReserve( val, reserveCount );
}
int
tr_bencListReserve( tr_benc * val, int count )
tr_bencListReserve( tr_benc * val, size_t count )
{
assert( tr_bencIsList( val ) );
return makeroom( val, count );
}
int
tr_bencInitDict( tr_benc * val, int reserveCount )
tr_bencInitDict( tr_benc * val, size_t reserveCount )
{
tr_bencInit( val, TYPE_DICT );
return tr_bencDictReserve( val, reserveCount );
}
int
tr_bencDictReserve( tr_benc * val, int count )
tr_bencDictReserve( tr_benc * val, size_t reserveCount )
{
assert( tr_bencIsDict( val ) );
return makeroom( val, count * 2 );
return makeroom( val, reserveCount * 2 );
}
tr_benc *
@ -584,14 +584,14 @@ tr_bencListAddStr( tr_benc * list, const char * val )
return node;
}
tr_benc*
tr_bencListAddList( tr_benc * list, int reserveCount )
tr_bencListAddList( tr_benc * list, size_t reserveCount )
{
tr_benc * child = tr_bencListAdd( list );
tr_bencInitList( child, reserveCount );
return child;
}
tr_benc*
tr_bencListAddDict( tr_benc * list, int reserveCount )
tr_bencListAddDict( tr_benc * list, size_t reserveCount )
{
tr_benc * child = tr_bencListAdd( list );
tr_bencInitDict( child, reserveCount );
@ -638,14 +638,14 @@ tr_bencDictAddDouble( tr_benc * dict, const char * key, double d )
return tr_bencDictAddStr( dict, key, buf );
}
tr_benc*
tr_bencDictAddList( tr_benc * dict, const char * key, int reserveCount )
tr_bencDictAddList( tr_benc * dict, const char * key, size_t reserveCount )
{
tr_benc * child = tr_bencDictAdd( dict, key );
tr_bencInitList( child, reserveCount );
return child;
}
tr_benc*
tr_bencDictAddDict( tr_benc * dict, const char * key, int reserveCount )
tr_bencDictAddDict( tr_benc * dict, const char * key, size_t reserveCount )
{
tr_benc * child = tr_bencDictAdd( dict, key );
tr_bencInitDict( child, reserveCount );
@ -881,7 +881,7 @@ static void
saveStringFunc( const tr_benc * val, void * vevbuf )
{
struct evbuffer * evbuf = vevbuf;
evbuffer_add_printf( evbuf, "%d:", val->val.s.i );
evbuffer_add_printf( evbuf, "%lu:", (unsigned long)val->val.s.i );
evbuffer_add( evbuf, val->val.s.s, val->val.s.i );
}
static void
@ -1167,7 +1167,7 @@ jsonDictBeginFunc( const tr_benc * val, void * vdata )
static void
jsonListBeginFunc( const tr_benc * val, void * vdata )
{
const int nChildren = tr_bencListSize( val );
const size_t nChildren = tr_bencListSize( val );
struct jsonWalk * data = vdata;
jsonPushParent( data, val );
evbuffer_add_printf( data->out, "[" );

View File

@ -31,13 +31,13 @@ typedef struct tr_benc
int64_t i;
struct
{
int i;
size_t i;
char * s;
} s;
struct
{
int alloc;
int count;
size_t alloc;
size_t count;
struct tr_benc * vals;
} l;
} val;
@ -53,7 +53,7 @@ int tr_bencParse( const void * buf,
const uint8_t ** setme_end );
int tr_bencLoad( const void * buf,
int buflen,
size_t buflen,
tr_benc * setme_benc,
char ** setme_end );
@ -74,35 +74,35 @@ int tr_bencSaveJSONFile ( const char * filename, const tr_benc * );
void tr_bencInitStr( tr_benc *, const void * str, int str_len );
void tr_bencInitRaw( tr_benc *, const void * raw, size_t raw_len );
void tr_bencInitInt( tr_benc *, int64_t num );
int tr_bencInitDict( tr_benc *, int reserveCount );
int tr_bencInitList( tr_benc *, int reserveCount );
int tr_bencInitDict( tr_benc *, size_t reserveCount );
int tr_bencInitList( tr_benc *, size_t reserveCount );
/***
****
***/
int tr_bencListReserve( tr_benc *, int count );
int tr_bencListReserve( tr_benc *, size_t reserveCount );
tr_benc * tr_bencListAdd( tr_benc * );
tr_benc * tr_bencListAddInt( tr_benc *, int64_t val );
tr_benc * tr_bencListAddStr( tr_benc *, const char * val );
tr_benc * tr_bencListAddList( tr_benc *, int reserveCount );
tr_benc * tr_bencListAddDict( tr_benc *, int reserveCount );
tr_benc * tr_bencListAddList( tr_benc *, size_t reserveCount );
tr_benc * tr_bencListAddDict( tr_benc *, size_t reserveCount );
int tr_bencListSize( const tr_benc * list );
tr_benc * tr_bencListChild( tr_benc * list, int n );
size_t tr_bencListSize( const tr_benc * list );
tr_benc * tr_bencListChild( tr_benc * list, size_t n );
/***
****
***/
int tr_bencDictReserve( tr_benc *, int count );
int tr_bencDictReserve( tr_benc *, size_t reserveCount );
int tr_bencDictRemove( tr_benc *, const char * key );
tr_benc * tr_bencDictAdd( tr_benc *, const char * key );
tr_benc * tr_bencDictAddDouble( tr_benc *, const char * key, double d );
tr_benc * tr_bencDictAddInt( tr_benc *, const char * key, int64_t val );
tr_benc * tr_bencDictAddStr( tr_benc *, const char * key, const char * val );
tr_benc * tr_bencDictAddList( tr_benc *, const char * key, int reserveCount );
tr_benc * tr_bencDictAddDict( tr_benc *, const char * key, int reserveCount );
tr_benc * tr_bencDictAddList( tr_benc *, const char * key, size_t reserve );
tr_benc * tr_bencDictAddDict( tr_benc *, const char * key, size_t reserve );
tr_benc * tr_bencDictAddRaw( tr_benc *, const char * key,
const void *, size_t len );

View File

@ -168,7 +168,7 @@ tr_ptrArrayErase( tr_ptrArray * t, int begin, int end )
{
assert( begin >= 0 );
if( end < 0 ) end = t->n_items;
assert( end > begin );
assert( end - begin > 0 );
assert( end <= t->n_items );
memmove( t->items + begin,

View File

@ -122,7 +122,7 @@ loadDND( tr_benc * dict, tr_torrent * tor )
tr_benc * list = NULL;
if( tr_bencDictFindList( dict, KEY_DND, &list )
&& ( list->val.l.count == (int)n ) )
&& ( tr_bencListSize( list ) == n ) )
{
int64_t tmp;
tr_file_index_t * dl = tr_new( tr_file_index_t, n );
@ -130,7 +130,7 @@ loadDND( tr_benc * dict, tr_torrent * tor )
tr_file_index_t i, dlCount=0, dndCount=0;
for( i=0; i<n; ++i ) {
if( tr_bencGetInt( &list->val.l.vals[i], &tmp ) && tmp )
if( tr_bencGetInt( tr_bencListChild( list, i ), &tmp ) && tmp )
dnd[dndCount++] = i;
else
dl[dlCount++] = i;
@ -151,8 +151,8 @@ loadDND( tr_benc * dict, tr_torrent * tor )
}
else
{
tr_tordbg( tor, "Couldn't load DND flags. dnd list (%p) has %d children; torrent has %d files",
list, ( list ? list->val.l.count : -1 ), (int)n );
tr_tordbg( tor, "Couldn't load DND flags. dnd list (%p) has %zu children; torrent has %d files",
list, tr_bencListSize( list ), (int)n );
}
return ret;
@ -184,12 +184,12 @@ loadPriorities( tr_benc * dict, tr_torrent * tor )
tr_benc * list;
if( tr_bencDictFindList( dict, KEY_PRIORITY, &list )
&& ( list->val.l.count == (int)n ) )
&& ( tr_bencListSize( list ) == n ) )
{
int64_t tmp;
tr_file_index_t i;
for( i=0; i<n; ++i )
if( tr_bencGetInt( &list->val.l.vals[i], &tmp ) )
if( tr_bencGetInt( tr_bencListChild( list, i ), &tmp ) )
inf->files[i].priority = tmp;
ret = TR_FR_PRIORITY;
}
@ -245,8 +245,7 @@ loadSpeedLimits( tr_benc * dict, tr_torrent * tor )
static void
saveProgress( tr_benc * dict, const tr_torrent * tor )
{
int i;
int n;
size_t i, n;
time_t * mtimes;
tr_benc * p;
tr_benc * m;
@ -284,26 +283,26 @@ loadProgress( tr_benc * dict, tr_torrent * tor )
const uint8_t * raw;
size_t rawlen;
tr_benc * m;
int n;
size_t n;
time_t * curMTimes = tr_torrentGetMTimes( tor, &n );
if( tr_bencDictFindList( p, KEY_PROGRESS_MTIMES, &m )
&& ( m->val.l.count == (int64_t)tor->info.fileCount )
&& ( m->val.l.count == n ) )
&& ( n == tor->info.fileCount )
&& ( n == tr_bencListSize( m ) ) )
{
int i;
size_t i;
for( i=0; i<n; ++i )
{
int64_t tmp;
if( !tr_bencGetInt( &m->val.l.vals[i], &tmp ) ) {
tr_tordbg( tor, "File #%d needs to be verified - couldn't find benc entry", i );
if( !tr_bencGetInt( tr_bencListChild( m, i ), &tmp ) ) {
tr_tordbg( tor, "File #%zu needs to be verified - couldn't find benc entry", i );
tr_torrentSetFileChecked( tor, i, FALSE );
} else {
const time_t t = (time_t) tmp;
if( t == curMTimes[i] )
tr_torrentSetFileChecked( tor, i, TRUE );
else {
tr_tordbg( tor, "File #%d needs to be verified - times %lu and %lu don't match", i, t, curMTimes[i] );
tr_tordbg( tor, "File #%zu needs to be verified - times %lu and %lu don't match", i, t, curMTimes[i] );
tr_torrentSetFileChecked( tor, i, FALSE );
}
}

View File

@ -1534,10 +1534,10 @@ tr_torrentCountUncheckedPieces( const tr_torrent * tor )
}
time_t*
tr_torrentGetMTimes( const tr_torrent * tor, int * setme_n )
tr_torrentGetMTimes( const tr_torrent * tor, size_t * setme_n )
{
int i;
const int n = tor->info.fileCount;
size_t i;
const size_t n = tor->info.fileCount;
time_t * m = tr_new0( time_t, n );
for( i=0; i<n; ++i ) {

View File

@ -105,7 +105,7 @@ void tr_torrentUncheck ( tr_torrent * );
int tr_torrentPromoteTracker ( tr_torrent *, int trackerIndex );
time_t* tr_torrentGetMTimes ( const tr_torrent *, int * setmeCount );
time_t* tr_torrentGetMTimes ( const tr_torrent *, size_t * setmeCount );
typedef enum
{

View File

@ -474,7 +474,7 @@ onScrapeResponse( tr_session * session,
&benc, NULL );
if( bencLoaded && tr_bencDictFindDict( &benc, "files", &files ) )
{
int i;
size_t i;
for( i=0; i<files->val.l.count; i+=2 )
{
int64_t itmp;

View File

@ -73,7 +73,7 @@ processCompletedTasks( tr_web * web )
if( easy ) {
struct tr_web_task * task;
long response_code;
curl_easy_getinfo( easy, CURLINFO_PRIVATE, &task );
curl_easy_getinfo( easy, CURLINFO_PRIVATE, (void*)&task );
curl_easy_getinfo( easy, CURLINFO_RESPONSE_CODE, &response_code );
--web->remain;
dbgmsg( "task #%lu done (%d remain)", task->tag, web->remain );