(trunk libT) fix warnings in fileset_get_empty_slot() found by llvm's static-build analyzer.

static-build found a potential NULL pointer dereference. The circumstances where this could get triggered don't seem very likely, but doesn't hurt to fix the warning.
This commit is contained in:
Jordan Lee 2011-12-14 05:42:15 +00:00
parent 206b1a9a5f
commit 0d13057111
1 changed files with 17 additions and 11 deletions

View File

@ -478,19 +478,25 @@ fileset_lookup( struct tr_fileset * set, int torrent_id, tr_file_index_t i )
static struct tr_cached_file *
fileset_get_empty_slot( struct tr_fileset * set )
{
struct tr_cached_file * o;
struct tr_cached_file * cull;
struct tr_cached_file * cull = NULL;
/* try to find an unused slot */
for( o=set->begin; o!=set->end; ++o )
if( !cached_file_is_open( o ) )
return o;
if( set->begin != NULL )
{
struct tr_cached_file * o;
/* try to find an unused slot */
for( o=set->begin; o!=set->end; ++o )
if( !cached_file_is_open( o ) )
return o;
/* all slots are full... recycle the least recently used */
for( cull=NULL, o=set->begin; o!=set->end; ++o )
if( !cull || o->used_at < cull->used_at )
cull = o;
cached_file_close( cull );
}
/* all slots are full... recycle the least recently used */
for( cull=NULL, o=set->begin; o!=set->end; ++o )
if( !cull || o->used_at < cull->used_at )
cull = o;
cached_file_close( cull );
return cull;
}