From dbed40ff5a0ea3d9e018218ec2fee9690d0055c2 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 14 Oct 2010 04:21:14 +0000 Subject: [PATCH] (trunk libT) #3631 "crash in tr_ioFindFileLocation" -- add tracer messages to try & smoke out the error --- libtransmission/inout.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/libtransmission/inout.c b/libtransmission/inout.c index f9ee10d29..54e2ff857 100644 --- a/libtransmission/inout.c +++ b/libtransmission/inout.c @@ -167,8 +167,7 @@ readOrWriteBytes( tr_session * session, } static int -compareOffsetToFile( const void * a, - const void * b ) +compareOffsetToFile( const void * a, const void * b ) { const uint64_t offset = *(const uint64_t*)a; const tr_file * file = b; @@ -188,10 +187,26 @@ tr_ioFindFileLocation( const tr_torrent * tor, const uint64_t offset = tr_pieceOffset( tor, pieceIndex, pieceOffset, 0 ); const tr_file * file; + assert( tr_isTorrent( tor ) ); + assert( offset < tor->info.totalSize ); + file = bsearch( &offset, tor->info.files, tor->info.fileCount, sizeof( tr_file ), compareOffsetToFile ); +if( file == NULL ) { +unsigned int i; +fprintf( stderr, "%s", "transmission error\n" ); +fprintf( stderr, "pieceIndex %d\n", (int)pieceIndex ); +fprintf( stderr, "pieceOffset %d\n", (int)pieceOffset ); +fprintf( stderr, "couldn't find file matching offset %"PRIu64"\n", offset ); +fprintf( stderr, "total torrent size %"PRIu64"\n", tor->info.totalSize ); +fprintf( stderr, "%u files\n", (unsigned int)tor->info.fileCount ); +for( i=0; iinfo.fileCount; ++i ) fprintf( stderr, "file #%u offset %"PRIu64" length %"PRIu64"\n", i, tor->info.files[i].offset, tor->info.files[i].length ); +} + + assert( file != NULL ); + *fileIndex = file - tor->info.files; *fileOffset = offset - file->offset;