From 51aff87443140f0da3038f3445f47e9c9ca76413 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Mon, 11 Aug 2008 19:05:02 +0000 Subject: [PATCH] lots of C correctness tweaks suggested by sparse/cgcc --- cli/cli.c | 4 ++-- daemon/daemon.c | 2 +- daemon/remote.c | 2 +- gtk/actions.c | 11 +++++------ gtk/actions.h | 2 ++ gtk/details.c | 2 +- gtk/main.c | 6 ++++-- gtk/tr-core.c | 2 +- gtk/tr-prefs.c | 8 ++++++-- gtk/tr-torrent.c | 2 +- gtk/tr-window.c | 6 +++--- gtk/ui.h | 2 +- libtransmission/bencode-test.c | 2 +- libtransmission/bencode.c | 5 ++++- libtransmission/blocklist.c | 2 +- libtransmission/clients.c | 1 + libtransmission/fdlimit.c | 1 + libtransmission/handshake.c | 2 +- libtransmission/json-test.c | 2 +- libtransmission/json.c | 1 + libtransmission/makemeta.c | 2 +- libtransmission/peer-msgs.c | 8 -------- libtransmission/ptrarray.c | 2 +- libtransmission/rpc-test.c | 2 +- libtransmission/rpc.c | 2 +- libtransmission/stats.c | 3 ++- libtransmission/tracker.c | 8 +++++--- libtransmission/transmission.h | 1 + libtransmission/utils-test.c | 2 +- 29 files changed, 52 insertions(+), 43 deletions(-) diff --git a/cli/cli.c b/cli/cli.c index d35e95180..0e5ac1a30 100644 --- a/cli/cli.c +++ b/cli/cli.c @@ -65,7 +65,7 @@ static const char * comment = NULL; static int parseCommandLine ( int argc, const char ** argv ); static void sigHandler ( int signal ); -char* +static char* tr_strlratio( char * buf, double ratio, size_t buflen ) { if( (int)ratio == TR_RATIO_NA ) @@ -437,7 +437,7 @@ getUsage( void ) "Usage: "MY_NAME" [options] "; } -const struct tr_option options[] = { +static const struct tr_option options[] = { { 'a', "announce", "Set the new torrent's announce URL", "a", 1, "" }, { 'b', "blocklist", "Enable peer blocklists", "b", 0, NULL }, { 'B', "no-blocklist", "Disable peer blocklists", "B", 0, NULL }, diff --git a/daemon/daemon.c b/daemon/daemon.c index 296a1c29b..81cb9ee3f 100644 --- a/daemon/daemon.c +++ b/daemon/daemon.c @@ -231,7 +231,7 @@ getUsage( void ) "Usage: "MY_NAME" [options]"; } -const struct tr_option options[] = { +static const struct tr_option options[] = { { 'a', "acl", "Access Control List. (Default: "TR_DEFAULT_RPC_ACL")", "a", 1, "" }, { 'b', "blocklist", "Enable peer blocklists", "b", 0, NULL }, { 'B', "no-blocklist", "Disable peer blocklists", "B", 0, NULL }, diff --git a/daemon/remote.c b/daemon/remote.c index f9ccf4028..1022ace97 100644 --- a/daemon/remote.c +++ b/daemon/remote.c @@ -682,8 +682,8 @@ printFileList( tr_benc * top ) { char sizestr[64]; double percent = (double)have / length; - strlsize( sizestr, length, sizeof( sizestr ) ); const char * pristr; + strlsize( sizestr, length, sizeof( sizestr ) ); switch( priority ) { case TR_PRI_LOW: pristr = "Low"; break; case TR_PRI_HIGH: pristr = "High"; break; diff --git a/gtk/actions.c b/gtk/actions.c index ec55802e7..bf793fc2b 100644 --- a/gtk/actions.c +++ b/gtk/actions.c @@ -14,6 +14,7 @@ #include #include #include +#include "actions.h" #include "conf.h" #include "tr-core.h" #include "tr-prefs.h" @@ -22,11 +23,9 @@ #define UNUSED G_GNUC_UNUSED -extern void doAction (const char * action_name, gpointer user_data ); +static TrCore * myCore = NULL; -static TrCore * myCore = 0; - -static GtkActionGroup * myGroup = 0; +static GtkActionGroup * myGroup = NULL; static void action_cb ( GtkAction * a, gpointer user_data ) @@ -140,7 +139,7 @@ typedef struct } BuiltinIconInfo; -const BuiltinIconInfo my_fallback_icons [] = +static const BuiltinIconInfo my_fallback_icons [] = { { tr_icon_logo, "transmission" }, { tr_icon_lock, "transmission-lock" } @@ -165,7 +164,7 @@ register_my_icons ( void ) GdkPixbuf * p; GtkIconSet * icon_set; - p = gdk_pixbuf_new_from_inline( -1, my_fallback_icons[i].raw, FALSE, 0 ); + p = gdk_pixbuf_new_from_inline( -1, my_fallback_icons[i].raw, FALSE, NULL ); width = gdk_pixbuf_get_width( p ); icon_set = gtk_icon_set_new_from_pixbuf( p ); gtk_icon_theme_add_builtin_icon( name, width, p ); diff --git a/gtk/actions.h b/gtk/actions.h index f590636fe..75ffddd5b 100644 --- a/gtk/actions.h +++ b/gtk/actions.h @@ -28,4 +28,6 @@ void action_toggle ( const char * name, gboolean b ); GtkWidget* action_get_widget ( const char * path ); +void doAction( const char * action_name, gpointer user_data ); + #endif diff --git a/gtk/details.c b/gtk/details.c index 0f2be5c0f..bba621b11 100644 --- a/gtk/details.c +++ b/gtk/details.c @@ -1165,7 +1165,7 @@ struct tracker_page GtkWidget * manual_announce_countdown_lb; }; -GtkWidget* +static GtkWidget* tracker_page_new( TrTorrent * gtor ) { GtkWidget * t; diff --git a/gtk/main.c b/gtk/main.c index 8498aa695..5dec78b9f 100644 --- a/gtk/main.c +++ b/gtk/main.c @@ -410,6 +410,8 @@ main( int argc, char ** argv ) if( didlock && ( didinit || cf_init( configDir, &err ) ) ) { + GtkWindow * win; + tr_handle * h = tr_sessionInitFull( configDir, "gtk", @@ -444,7 +446,7 @@ main( int argc, char ** argv ) cbdata->core = tr_core_new( h ); /* create main window now to be a parent to any error dialogs */ - GtkWindow * win = GTK_WINDOW( tr_window_new( myUIManager, cbdata->core ) ); + win = GTK_WINDOW( tr_window_new( myUIManager, cbdata->core ) ); g_signal_connect( win, "window-state-event", G_CALLBACK(windowStateChanged), cbdata ); g_signal_connect( win, "size-allocate", G_CALLBACK(onMainWindowSizeAllocated), cbdata ); @@ -1047,7 +1049,7 @@ g_message( "setting encryption to %d", encryption ); } } -gboolean +static gboolean updatemodel( gpointer gdata ) { struct cbdata *data = gdata; diff --git a/gtk/tr-core.c b/gtk/tr-core.c index aebacee07..58a9b3123 100644 --- a/gtk/tr-core.c +++ b/gtk/tr-core.c @@ -1039,10 +1039,10 @@ maybeInhibitHibernation( TrCore * core ) { gboolean allowHibernation; tr_handle * session = tr_core_handle( core ); + tr_torrent * tor = NULL; /* allow hibernation unless we have active torrents */ allowHibernation = TRUE; - tr_torrent * tor = NULL; while(( tor = tr_torrentNext( session, tor ))) { if( tr_torrentGetStatus( tor ) != TR_STATUS_STOPPED ) { allowHibernation = FALSE; diff --git a/gtk/tr-prefs.c b/gtk/tr-prefs.c index 9e4ac31d9..8105b7a14 100644 --- a/gtk/tr-prefs.c +++ b/gtk/tr-prefs.c @@ -270,9 +270,12 @@ testing_port_begin( gpointer gdata ) static void testing_port_cb( GtkWidget * unused UNUSED, gpointer l ) { + struct test_port_data * data; + gtk_label_set_markup( GTK_LABEL( l ), _( "Testing port..." ) ); + /* wait three seconds to give the port forwarding time to kick in */ - struct test_port_data * data = g_new0( struct test_port_data, 1 ); + data = g_new0( struct test_port_data, 1 ); data->label = l; data->alive = g_object_get_data( G_OBJECT( l ), "alive" ); g_timeout_add( 3000, testing_port_begin, data ); @@ -418,11 +421,12 @@ got_blocklist( tr_handle * handle UNUSED, } if( ok && !data->abortFlag ) { + char * cmd; filename2 = g_strdup_printf( "%s.txt", filename ); g_snprintf( data->secondary, sizeof( data->secondary ), _( "Uncompressing blocklist..." ) ); g_idle_add( blocklistDialogSetSecondary, data ); - char * cmd = g_strdup_printf( "zcat %s > %s ", filename, filename2 ); + cmd = g_strdup_printf( "zcat %s > %s ", filename, filename2 ); tr_dbg( "%s", cmd ); system( cmd ); g_free( cmd ); diff --git a/gtk/tr-torrent.c b/gtk/tr-torrent.c index 4b3cb9787..97baf7907 100644 --- a/gtk/tr-torrent.c +++ b/gtk/tr-torrent.c @@ -227,7 +227,7 @@ tr_torrent_new_ctor( tr_handle * handle, char * tr_torrent_status_str ( TrTorrent * gtor ) { - char * top = 0; + char * top = NULL; const tr_stat * st = tr_torrent_stat( gtor ); diff --git a/gtk/tr-window.c b/gtk/tr-window.c index 412909ae7..230b1e56c 100644 --- a/gtk/tr-window.c +++ b/gtk/tr-window.c @@ -101,7 +101,7 @@ PrivateData; #define FILTER_TEXT_MODE_KEY "tr-filter-text-mode" #define FILTER_TOGGLES_KEY "tr-filter-toggles" -PrivateData* +static PrivateData* get_private_data( TrWindow * w ) { return g_object_get_data (G_OBJECT(w), PRIVATE_DATA_KEY); @@ -224,7 +224,7 @@ static void onYinYangReleased( GtkWidget * w UNUSED, GdkEventButton * button UNUSED, gpointer vprivate ) { PrivateData * p = vprivate; - gtk_menu_popup( GTK_MENU( p->status_menu ), 0, 0, 0, 0, 0, gtk_get_current_event_time( ) ); + gtk_menu_popup( GTK_MENU( p->status_menu ), NULL, NULL, NULL, NULL, 0, gtk_get_current_event_time( ) ); } #define STATS_MODE "stats-mode" @@ -401,7 +401,7 @@ entry_icon_released( SexyIconEntry * entry UNUSED, gpointer menu ) { if ( icon_pos == SEXY_ICON_ENTRY_PRIMARY ) - gtk_menu_popup ( GTK_MENU( menu ), 0, 0, 0, 0, 0, gtk_get_current_event_time( ) ); + gtk_menu_popup ( GTK_MENU( menu ), NULL, NULL, NULL, NULL, 0, gtk_get_current_event_time( ) ); } /*** diff --git a/gtk/ui.h b/gtk/ui.h index 179492872..52120a830 100644 --- a/gtk/ui.h +++ b/gtk/ui.h @@ -1,4 +1,4 @@ -const char * fallback_ui_file = +static const char * fallback_ui_file = "\n" " \n" " \n" diff --git a/libtransmission/bencode-test.c b/libtransmission/bencode-test.c index 24cf975a7..3839de669 100644 --- a/libtransmission/bencode-test.c +++ b/libtransmission/bencode-test.c @@ -7,7 +7,7 @@ #define VERBOSE 0 -int test = 0; +static int test = 0; #define check(A) { \ ++test; \ diff --git a/libtransmission/bencode.c b/libtransmission/bencode.c index d0b5a0407..ca71d1005 100644 --- a/libtransmission/bencode.c +++ b/libtransmission/bencode.c @@ -317,11 +317,14 @@ tr_bencParse( const void * buf, tr_benc * top, const uint8_t ** setme_end ) { + int err; tr_ptrArray * parentStack = tr_ptrArrayNew( ); + top->type = 0; /* not initialized yet */ - const int err = tr_bencParseImpl( buf, end, top, parentStack, setme_end ); + err = tr_bencParseImpl( buf, end, top, parentStack, setme_end ); if( err ) tr_bencFree( top ); + tr_ptrArrayFree( parentStack, NULL ); return err; } diff --git a/libtransmission/blocklist.c b/libtransmission/blocklist.c index daf4b10a3..7897a5b13 100644 --- a/libtransmission/blocklist.c +++ b/libtransmission/blocklist.c @@ -80,7 +80,7 @@ blocklistLoad( tr_blocklist * b ) return; } - b->rules = mmap( 0, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0 ); + b->rules = mmap( NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0 ); if( !b->rules ) { tr_err( err_fmt, b->filename, tr_strerror(errno) ); close( fd ); diff --git a/libtransmission/clients.c b/libtransmission/clients.c index 65f78a164..cd280242b 100644 --- a/libtransmission/clients.c +++ b/libtransmission/clients.c @@ -20,6 +20,7 @@ #include /* evbuffer */ #include "transmission.h" +#include "clients.h" #include "utils.h" static int diff --git a/libtransmission/fdlimit.c b/libtransmission/fdlimit.c index 2da77d3f3..315b24547 100644 --- a/libtransmission/fdlimit.c +++ b/libtransmission/fdlimit.c @@ -47,6 +47,7 @@ #include #include "transmission.h" +#include "fdlimit.h" #include "list.h" #include "net.h" #include "platform.h" /* tr_lock */ diff --git a/libtransmission/handshake.c b/libtransmission/handshake.c index 96af0ea33..ad79436ff 100644 --- a/libtransmission/handshake.c +++ b/libtransmission/handshake.c @@ -969,7 +969,7 @@ fireDoneFunc( tr_handshake * handshake, int isConnected ) handshake->doneUserData ); } -void +static void tr_handshakeDone( tr_handshake * handshake, int isOK ) { dbgmsg( handshake, "handshakeDone: %s", isOK ? "connected" : "aborting" ); diff --git a/libtransmission/json-test.c b/libtransmission/json-test.c index d82f623a9..3cabd76f2 100644 --- a/libtransmission/json-test.c +++ b/libtransmission/json-test.c @@ -6,7 +6,7 @@ #define VERBOSE 0 -int test = 0; +static int test = 0; #define check(A) { \ ++test; \ diff --git a/libtransmission/json.c b/libtransmission/json.c index 5076baeb3..af40327aa 100644 --- a/libtransmission/json.c +++ b/libtransmission/json.c @@ -21,6 +21,7 @@ #include "transmission.h" #include "bencode.h" +#include "json.h" #include "ptrarray.h" #include "utils.h" diff --git a/libtransmission/makemeta.c b/libtransmission/makemeta.c index 222abbbe9..fa59742c4 100644 --- a/libtransmission/makemeta.c +++ b/libtransmission/makemeta.c @@ -382,7 +382,7 @@ tr_realMakeMetaInfo ( tr_metainfo_builder * builder ) if( builder->comment && *builder->comment ) tr_bencDictAddStr( &top, "comment", builder->comment ); tr_bencDictAddStr( &top, "created by", TR_NAME "/" LONG_VERSION_STRING ); - tr_bencDictAddInt( &top, "creation date", time(0) ); + tr_bencDictAddInt( &top, "creation date", time(NULL) ); tr_bencDictAddStr( &top, "encoding", "UTF-8" ); makeInfoDict( tr_bencDictAddDict( &top, "info", 666 ), builder ); } diff --git a/libtransmission/peer-msgs.c b/libtransmission/peer-msgs.c index 601c77389..0113839b4 100644 --- a/libtransmission/peer-msgs.c +++ b/libtransmission/peer-msgs.c @@ -1974,14 +1974,6 @@ tr_peerMsgsFree( tr_peermsgs* msgs ) } } -tr_publisher_tag -tr_peerMsgsSubscribe( tr_peermsgs * peer, - tr_delivery_func func, - void * userData ) -{ - return tr_publisherSubscribe( peer->publisher, func, userData ); -} - void tr_peerMsgsUnsubscribe( tr_peermsgs * peer, tr_publisher_tag tag ) diff --git a/libtransmission/ptrarray.c b/libtransmission/ptrarray.c index 4c3e2602f..085ed0f6d 100644 --- a/libtransmission/ptrarray.c +++ b/libtransmission/ptrarray.c @@ -182,7 +182,7 @@ tr_ptrArrayErase( tr_ptrArray * t, int begin, int end ) *** **/ -int +static int tr_ptrArrayLowerBound( const tr_ptrArray * t, const void * ptr, int compare( const void *,const void * ), diff --git a/libtransmission/rpc-test.c b/libtransmission/rpc-test.c index 0ef8afdcf..00f3b8d4c 100644 --- a/libtransmission/rpc-test.c +++ b/libtransmission/rpc-test.c @@ -7,7 +7,7 @@ #define VERBOSE 0 -int test = 0; +static int test = 0; #define check(A) { \ ++test; \ diff --git a/libtransmission/rpc.c b/libtransmission/rpc.c index 191bf0520..ca36d776f 100644 --- a/libtransmission/rpc.c +++ b/libtransmission/rpc.c @@ -642,7 +642,7 @@ sessionGet( tr_handle * h, tr_benc * args_in UNUSED, tr_benc * args_out ) typedef const char* (handler)( tr_handle*, tr_benc*, tr_benc* ); -struct method { +static struct method { const char * name; handler * func; } methods[] = { diff --git a/libtransmission/stats.c b/libtransmission/stats.c index 1e77c2b1d..6c5fbe901 100644 --- a/libtransmission/stats.c +++ b/libtransmission/stats.c @@ -15,6 +15,7 @@ #include "transmission.h" #include "bencode.h" #include "platform.h" /* tr_sessionGetConfigDir() */ +#include "stats.h" #include "utils.h" /* tr_buildPath */ /*** @@ -169,8 +170,8 @@ tr_sessionGetCumulativeStats( const tr_handle * handle, tr_session_stats * setme ) { const struct tr_stats_handle * stats = getStats( handle ); - assert( stats ); tr_session_stats current; + assert( stats ); tr_sessionGetStats( handle, ¤t ); addStats( setme, &stats->old, ¤t ); } diff --git a/libtransmission/tracker.c b/libtransmission/tracker.c index d72485792..759252bbf 100644 --- a/libtransmission/tracker.c +++ b/libtransmission/tracker.c @@ -154,7 +154,7 @@ trackerSupportsScrape( tr_tracker * t, const tr_torrent * tor ) **** ***/ -tr_tracker * +static tr_tracker * findTracker( tr_session * session, const uint8_t * hash ) { tr_torrent * torrent = tr_torrentFindFromHash( session, hash ); @@ -322,7 +322,8 @@ onTrackerResponse( tr_session * session, if( responseCode == HTTP_OK ) { tr_benc benc; - const int bencLoaded = !tr_bencLoad( response, responseLen, &benc, 0 ); + const int bencLoaded = !tr_bencLoad( response, responseLen, + &benc, NULL ); publishErrorClear( t ); if( bencLoaded && tr_bencIsDict( &benc ) ) { @@ -466,7 +467,8 @@ onScrapeResponse( tr_session * session, if( responseCode == HTTP_OK ) { tr_benc benc, *files; - const int bencLoaded = !tr_bencLoad( response, responseLen, &benc, 0 ); + const int bencLoaded = !tr_bencLoad( response, responseLen, + &benc, NULL ); if( bencLoaded && tr_bencDictFindDict( &benc, "files", &files ) ) { int i; diff --git a/libtransmission/transmission.h b/libtransmission/transmission.h index b4c3fa81f..4e8876430 100644 --- a/libtransmission/transmission.h +++ b/libtransmission/transmission.h @@ -432,6 +432,7 @@ int tr_sessionIsProxyAuthEnabled ( const tr_session * ); const char* tr_sessionGetProxy ( const tr_session * ); int tr_sessionGetProxyPort ( const tr_session * ); tr_proxy_type tr_sessionGetProxyType ( const tr_session * ); +const char* tr_sessionGetProxyUsername ( const tr_session * ); const char* tr_sessionGetProxyPassword ( const tr_session * ); void tr_sessionSetProxyEnabled ( tr_session *, int isEnabled ); void tr_sessionSetProxyAuthEnabled ( tr_session *, int isEnabled ); diff --git a/libtransmission/utils-test.c b/libtransmission/utils-test.c index 2f231f10d..be4266785 100644 --- a/libtransmission/utils-test.c +++ b/libtransmission/utils-test.c @@ -14,7 +14,7 @@ #define NUM_LOOPS 200 #endif -int test = 0; +static int test = 0; #define check(A) { \ ++test; \ -- 2.40.0