Changeset 9580


Ignore:
Timestamp:
Nov 26, 2009, 4:06:49 AM (13 years ago)
Author:
charles
Message:

(trunk gtk) #2110 "allow adding torrents with no trackers" - don't crash when sorting or filtering by tracker. (Reported by Rolcol and jch)

Location:
trunk/gtk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/gtk/tr-core.c

    r9550 r9580  
    394394                  gpointer       user_data UNUSED )
    395395{
    396     const tr_torrent *ta, *tb;
     396    const tr_torrent * ta;
     397    const tr_torrent * tb;
     398    const tr_info * aInf;
     399    const tr_info * bInf;
     400    const char * aTracker;
     401    const char * bTracker;
    397402
    398403    gtk_tree_model_get( model, a, MC_TORRENT_RAW, &ta, -1 );
    399404    gtk_tree_model_get( model, b, MC_TORRENT_RAW, &tb, -1 );
    400     return strcmp( tr_torrentInfo( ta )->trackers[0].announce,
    401                    tr_torrentInfo( tb )->trackers[0].announce );
     405
     406    aInf = tr_torrentInfo( ta );
     407    bInf = tr_torrentInfo( tb );
     408    aTracker = aInf->trackerCount > 0 ? aInf->trackers[0].announce : NULL;
     409    bTracker = bInf->trackerCount > 0 ? bInf->trackers[0].announce : NULL;
     410
     411    if( !aTracker && !bTracker ) return 0;
     412    if( !aTracker ) return -1;
     413    if( !bTracker ) return 1;
     414    return strcmp( aTracker, bTracker );
    402415}
    403416
  • trunk/gtk/tr-window.c

    r9107 r9580  
    366366static int
    367367checkFilterText( filter_text_mode_t    filter_text_mode,
    368                  const tr_info       * torInfo,
     368                 const tr_info       * inf,
    369369                 const char          * text )
    370370{
     
    376376    {
    377377        case FILTER_TEXT_MODE_FILES:
    378             for( i = 0; i < torInfo->fileCount && !ret; ++i )
     378            for( i = 0; i < inf->fileCount && !ret; ++i )
    379379            {
    380                 pch = g_utf8_casefold( torInfo->files[i].name, -1 );
     380                pch = g_utf8_casefold( inf->files[i].name, -1 );
    381381                ret = !text || strstr( pch, text ) != NULL;
    382382                g_free( pch );
     
    385385
    386386        case FILTER_TEXT_MODE_TRACKER:
    387             pch = g_utf8_casefold( torInfo->trackers[0].announce, -1 );
    388             ret = !text || ( strstr( pch, text ) != NULL );
    389             g_free( pch );
     387            if( inf->trackerCount > 0 )
     388            {
     389                pch = g_utf8_casefold( inf->trackers[0].announce, -1 );
     390                ret = !text || ( strstr( pch, text ) != NULL );
     391                g_free( pch );
     392            }
    390393            break;
    391394
    392395        default: /* NAME */
    393             pch = g_utf8_casefold( torInfo->name, -1 );
     396            pch = g_utf8_casefold( inf->name, -1 );
    394397            ret = !text || ( strstr( pch, text ) != NULL );
    395398            g_free( pch );
Note: See TracChangeset for help on using the changeset viewer.