(trunk libT) #2110: "allow adding torrents with no trackers" -- fix crash in tr_torrentSetAnnounceList() when the new number of trackers is 0. Reported by Rolcol.
This commit is contained in:
parent
f585379bed
commit
04011d212b
|
@ -2116,10 +2116,6 @@ tr_torrentSetAnnounceList( tr_torrent * tor,
|
|||
/* save to the .torrent file */
|
||||
if( !tr_bencLoadFile( &metainfo, TR_FMT_BENC, tor->info.torrent ) )
|
||||
{
|
||||
int i;
|
||||
int prevTier = -1;
|
||||
tr_benc * tier = NULL;
|
||||
tr_benc * announceList;
|
||||
tr_info tmpInfo;
|
||||
|
||||
/* remove the old fields */
|
||||
|
@ -2127,8 +2123,17 @@ tr_torrentSetAnnounceList( tr_torrent * tor,
|
|||
tr_bencDictRemove( &metainfo, "announce-list" );
|
||||
|
||||
/* add the new fields */
|
||||
if( trackerCount > 0 )
|
||||
{
|
||||
tr_bencDictAddStr( &metainfo, "announce", trackers[0].announce );
|
||||
announceList = tr_bencDictAddList( &metainfo, "announce-list", 0 );
|
||||
}
|
||||
if( trackerCount > 1 )
|
||||
{
|
||||
int i;
|
||||
int prevTier = -1;
|
||||
tr_benc * tier = NULL;
|
||||
tr_benc * announceList = tr_bencDictAddList( &metainfo, "announce-list", 0 );
|
||||
|
||||
for( i=0; i<trackerCount; ++i ) {
|
||||
if( prevTier != trackers[i].tier ) {
|
||||
prevTier = trackers[i].tier;
|
||||
|
@ -2136,6 +2141,7 @@ tr_torrentSetAnnounceList( tr_torrent * tor,
|
|||
}
|
||||
tr_bencListAddStr( tier, trackers[i].announce );
|
||||
}
|
||||
}
|
||||
|
||||
/* try to parse it back again, to make sure it's good */
|
||||
memset( &tmpInfo, 0, sizeof( tr_info ) );
|
||||
|
|
Loading…
Reference in New Issue