Changeset 6625


Ignore:
Timestamp:
Aug 22, 2008, 3:13:01 PM (13 years ago)
Author:
charles
Message:

(libT) say goodbye to the last `ii' variable in libT

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/bencode.c

    r6615 r6625  
    150150}
    151151
    152 /* setting to 1 to help expose bugs with tr_bencListAdd and tr_bencDictAdd */
     152/* set to 1 to help expose bugs with tr_bencListAdd and tr_bencDictAdd */
    153153#define LIST_SIZE 8 /* number of items to increment list/dict buffer by */
    154154
     
    321321    tr_ptrArray * parentStack = tr_ptrArrayNew( );
    322322
    323     top->type = 0; /* not initialized yet */
     323    top->type = 0; /* set to `uninitialized' */
    324324    err = tr_bencParseImpl( buf, end, top, parentStack, setme_end );
    325325    if( err )
     
    349349
    350350static int
    351 dictIndexOf( tr_benc * val, const char * key )
    352 {
    353     int len, ii;
    354 
    355     if( !tr_bencIsDict( val ) )
    356         return -1;
    357 
    358     len = strlen( key );
    359    
    360     for( ii = 0; ii + 1 < val->val.l.count; ii += 2 )
     351dictIndexOf( const tr_benc * val, const char * key )
     352{
     353    if( tr_bencIsDict( val ) )
    361354    {
    362         if( TYPE_STR  != val->val.l.vals[ii].type ||
    363             len       != val->val.l.vals[ii].val.s.i ||
    364             0 != memcmp( val->val.l.vals[ii].val.s.s, key, len ) )
     355        int i;
     356        const int len = strlen( key );
     357
     358        for( i=0; (i+1)<val->val.l.count; i+=2 )
    365359        {
    366             continue;
    367         }
    368         return ii;
     360            const tr_benc * child = val->val.l.vals + i;
     361
     362            if( ( child->type == TYPE_STR )
     363                    && ( child->val.s.i == len )
     364                    && !memcmp( child->val.s.s, key, len ) )
     365                return i;
     366        }
    369367    }
    370368
     
    383381{
    384382    tr_benc * ret = tr_bencDictFind( val, key );
    385     return ret && ret->type == type ? ret : NULL;
     383    return ( ret && ( ret->type == type ) ) ? ret : NULL;
    386384}
    387385
     
    986984printStringFunc( const tr_benc * val, void * vdata )
    987985{
    988     int ii;
     986    int i;
    989987    struct WalkPrint * data = vdata;
    990988    printLeadingSpaces( data );
    991989    fprintf( data->out, "string:  " );
    992     for( ii = 0; val->val.s.i > ii; ii++ )
     990    for( i=0; i<val->val.s.i; ++i )
    993991    {
    994         if( '\\' == val->val.s.s[ii] ) {
     992        if( '\\' == val->val.s.s[i] ) {
    995993            putc( '\\', data->out );
    996994            putc( '\\', data->out );
    997         } else if( isprint( val->val.s.s[ii] ) ) {
    998             putc( val->val.s.s[ii], data->out );
     995        } else if( isprint( val->val.s.s[i] ) ) {
     996            putc( val->val.s.s[i], data->out );
    999997        } else {
    1000             fprintf( data->out, "\\x%02x", val->val.s.s[ii] );
     998            fprintf( data->out, "\\x%02x", val->val.s.s[i] );
    1001999        }
    10021000    }
Note: See TracChangeset for help on using the changeset viewer.