diff --git a/libtransmission/inout.c b/libtransmission/inout.c index 3cb6eaa18..83e26ad89 100644 --- a/libtransmission/inout.c +++ b/libtransmission/inout.c @@ -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; diff --git a/libtransmission/resume.c b/libtransmission/resume.c index 441524566..89f43189e 100644 --- a/libtransmission/resume.c +++ b/libtransmission/resume.c @@ -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 ); } }