Changeset 13110


Ignore:
Timestamp:
Dec 14, 2011, 5:42:15 AM (10 years ago)
Author:
jordan
Message:

(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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/fdlimit.c

    r12582 r13110  
    479479fileset_get_empty_slot( struct tr_fileset * set )
    480480{
    481     struct tr_cached_file * o;
    482     struct tr_cached_file * cull;
    483 
    484     /* try to find an unused slot */
    485     for( o=set->begin; o!=set->end; ++o )
    486         if( !cached_file_is_open( o ) )
    487             return o;
    488 
    489     /* all slots are full... recycle the least recently used */
    490     for( cull=NULL, o=set->begin; o!=set->end; ++o )
    491         if( !cull || o->used_at < cull->used_at )
    492             cull = o;
    493     cached_file_close( cull );
     481    struct tr_cached_file * cull = NULL;
     482
     483    if( set->begin != NULL )
     484    {
     485        struct tr_cached_file * o;
     486
     487        /* try to find an unused slot */
     488        for( o=set->begin; o!=set->end; ++o )
     489            if( !cached_file_is_open( o ) )
     490                return o;
     491
     492        /* all slots are full... recycle the least recently used */
     493        for( cull=NULL, o=set->begin; o!=set->end; ++o )
     494            if( !cull || o->used_at < cull->used_at )
     495                cull = o;
     496
     497        cached_file_close( cull );
     498    }
     499
    494500    return cull;
    495501}
Note: See TracChangeset for help on using the changeset viewer.