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

This commit is contained in:
Charles Kerr 2010-10-17 22:28:28 +00:00
parent ad613b05f7
commit 0a323ac019
1 changed files with 12 additions and 26 deletions

View File

@ -294,39 +294,25 @@ getFileInfo( const char * topFile,
tr_benc * uninitialized_length,
tr_benc * uninitialized_path )
{
const char * pch, *prev;
size_t topLen;
int n;
size_t offset;
/* get the file size */
tr_bencInitInt( uninitialized_length, file->size );
/* how much of file->filename to walk past */
topLen = strlen( topFile );
if( topLen>0 && topFile[topLen-1]!=TR_PATH_DELIMITER )
++topLen; /* +1 for the path delimiter */
offset = strlen( topFile );
if( offset>0 && topFile[offset-1]!=TR_PATH_DELIMITER )
++offset; /* +1 for the path delimiter */
/* build the path list */
n = 1;
for( pch = file->filename + topLen; *pch; ++pch )
if( *pch == TR_PATH_DELIMITER )
++n;
tr_bencInitList( uninitialized_path, n );
for( prev = pch = file->filename + topLen; ; ++pch )
{
char buf[TR_PATH_MAX];
if( *pch && *pch != TR_PATH_DELIMITER )
continue;
memcpy( buf, prev, pch - prev );
buf[pch - prev] = '\0';
tr_bencListAddStr( uninitialized_path, buf );
prev = pch + 1;
if( !*pch )
break;
tr_bencInitList( uninitialized_path, 0 );
if( strlen(file->filename) > offset ) {
char * filename = tr_strdup( file->filename + offset );
char * walk = filename;
const char * token;
while(( token = strsep( &walk, TR_PATH_DELIMITER_STR )))
tr_bencListAddStr( uninitialized_path, token );
tr_free( filename );
}
}