Changeset 11334


Ignore:
Timestamp:
Oct 17, 2010, 10:28:28 PM (11 years ago)
Author:
charles
Message:

(trunk libT) #3584 "minor valgrind warning in makemeta.c" -- fixed.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/makemeta.c

    r11272 r11334  
    295295             tr_benc *                        uninitialized_path )
    296296{
    297     const char * pch, *prev;
    298     size_t       topLen;
    299     int          n;
     297    size_t offset;
    300298
    301299    /* get the file size */
     
    303301
    304302    /* how much of file->filename to walk past */
    305     topLen = strlen( topFile );
    306     if( topLen>0 && topFile[topLen-1]!=TR_PATH_DELIMITER )
    307         ++topLen; /* +1 for the path delimiter */
     303    offset = strlen( topFile );
     304    if( offset>0 && topFile[offset-1]!=TR_PATH_DELIMITER )
     305        ++offset; /* +1 for the path delimiter */
    308306
    309307    /* build the path list */
    310     n = 1;
    311     for( pch = file->filename + topLen; *pch; ++pch )
    312         if( *pch == TR_PATH_DELIMITER )
    313             ++n;
    314     tr_bencInitList( uninitialized_path, n );
    315     for( prev = pch = file->filename + topLen; ; ++pch )
    316     {
    317         char buf[TR_PATH_MAX];
    318 
    319         if( *pch && *pch != TR_PATH_DELIMITER )
    320             continue;
    321 
    322         memcpy( buf, prev, pch - prev );
    323         buf[pch - prev] = '\0';
    324 
    325         tr_bencListAddStr( uninitialized_path, buf );
    326 
    327         prev = pch + 1;
    328         if( !*pch )
    329             break;
     308    tr_bencInitList( uninitialized_path, 0 );
     309    if( strlen(file->filename) > offset ) {
     310        char * filename = tr_strdup( file->filename + offset );
     311        char * walk = filename;
     312        const char * token;
     313        while(( token = strsep( &walk, TR_PATH_DELIMITER_STR )))
     314            tr_bencListAddStr( uninitialized_path, token );
     315        tr_free( filename );
    330316    }
    331317}
Note: See TracChangeset for help on using the changeset viewer.