mirror of
https://github.com/transmission/transmission
synced 2024-12-26 01:27:28 +00:00
(libT) extra assertions and safeguards for #1523: crash in tr_fdFileCheckout() when starting daemon
This commit is contained in:
parent
761d7dba8e
commit
181b9ed905
2 changed files with 8 additions and 8 deletions
|
@ -81,6 +81,7 @@ readOrWriteBytes( const tr_torrent * tor,
|
|||
int err;
|
||||
int fileExists;
|
||||
|
||||
assert( tor->downloadDir && *tor->downloadDir );
|
||||
assert( fileIndex < info->fileCount );
|
||||
assert( !file->length || ( fileOffset < file->length ) );
|
||||
assert( fileOffset + buflen <= file->length );
|
||||
|
@ -171,11 +172,9 @@ readOrWritePiece( const tr_torrent * tor,
|
|||
while( buflen && !err )
|
||||
{
|
||||
const tr_file * file = &info->files[fileIndex];
|
||||
const uint64_t bytesThisPass = MIN( buflen,
|
||||
file->length - fileOffset );
|
||||
const uint64_t bytesThisPass = MIN( buflen, file->length - fileOffset );
|
||||
|
||||
err = readOrWriteBytes( tor, ioMode,
|
||||
fileIndex, fileOffset, buf, bytesThisPass );
|
||||
err = readOrWriteBytes( tor, ioMode, fileIndex, fileOffset, buf, bytesThisPass );
|
||||
buf += bytesThisPass;
|
||||
buflen -= bytesThisPass;
|
||||
++fileIndex;
|
||||
|
|
|
@ -461,7 +461,8 @@ loadFromFile( tr_torrent * tor,
|
|||
}
|
||||
|
||||
if( ( fieldsToLoad & ( TR_FR_PROGRESS | TR_FR_DOWNLOAD_DIR ) )
|
||||
&& tr_bencDictFindStr( &top, KEY_DOWNLOAD_DIR, &str ) )
|
||||
&& ( tr_bencDictFindStr( &top, KEY_DOWNLOAD_DIR, &str ) )
|
||||
&& ( str && *str ) )
|
||||
{
|
||||
tr_free( tor->downloadDir );
|
||||
tor->downloadDir = tr_strdup( str );
|
||||
|
@ -561,12 +562,12 @@ setFromCtor( tr_torrent * tor,
|
|||
|
||||
if( fields & TR_FR_DOWNLOAD_DIR )
|
||||
{
|
||||
const char * downloadDir;
|
||||
if( !tr_ctorGetDownloadDir( ctor, mode, &downloadDir ) )
|
||||
const char * path;
|
||||
if( !tr_ctorGetDownloadDir( ctor, mode, &path ) && path && *path )
|
||||
{
|
||||
ret |= TR_FR_DOWNLOAD_DIR;
|
||||
tr_free( tor->downloadDir );
|
||||
tor->downloadDir = tr_strdup( downloadDir );
|
||||
tor->downloadDir = tr_strdup( path );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue