1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2025-03-03 18:25:35 +00:00

(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

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 * static struct tr_cached_file *
fileset_get_empty_slot( struct tr_fileset * set ) fileset_get_empty_slot( struct tr_fileset * set )
{ {
struct tr_cached_file * o; struct tr_cached_file * cull = NULL;
struct tr_cached_file * cull;
/* try to find an unused slot */ if( set->begin != NULL )
for( o=set->begin; o!=set->end; ++o ) {
if( !cached_file_is_open( o ) ) struct tr_cached_file * o;
return 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; return cull;
} }