From 13c22f88ff392024d27aa97c63c785f1a0a2f7c2 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Fri, 23 Jan 2009 18:44:15 +0000 Subject: [PATCH] (trunk libT) fix some code that the newly-added gcc warnings didn't like --- libtransmission/bencode-test.c | 22 +++++++++++++------- libtransmission/blocklist-test.c | 31 ++++++++++++++++++----------- libtransmission/clients-test.c | 23 +++++++++++++-------- libtransmission/json-test.c | 22 +++++++++++++------- libtransmission/peer-msgs-test.c | 23 +++++++++++++-------- libtransmission/request-list-test.c | 22 +++++++++++++------- libtransmission/rpc-test.c | 23 +++++++++++++-------- libtransmission/rpcimpl.c | 2 +- libtransmission/test-peer-id.c | 23 +++++++++++++-------- libtransmission/tr-getopt.c | 2 +- libtransmission/tr-getopt.h | 8 ++++---- libtransmission/utils-test.c | 28 ++++++++++++++++---------- 12 files changed, 147 insertions(+), 82 deletions(-) diff --git a/libtransmission/bencode-test.c b/libtransmission/bencode-test.c index 3ec6fef5d..4637d665f 100644 --- a/libtransmission/bencode-test.c +++ b/libtransmission/bencode-test.c @@ -10,23 +10,31 @@ #include "json.h" #include "utils.h" /* tr_free */ -#define VERBOSE 0 +#undef VERBOSE static int test = 0; -#define check( A ) \ +#ifdef VERBOSE + #define check( A ) \ { \ ++test; \ if( A ){ \ - if( VERBOSE ) \ - fprintf( stderr, "PASS test #%d (%s, %d)\n", test, __FILE__,\ - __LINE__ );\ + fprintf( stderr, "PASS test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \ } else { \ - fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__,\ - __LINE__ ); \ + fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \ return test; \ } \ } +#else + #define check( A ) \ + { \ + ++test; \ + if( !( A ) ){ \ + fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \ + return test; \ + } \ + } +#endif static int testInt( void ) diff --git a/libtransmission/blocklist-test.c b/libtransmission/blocklist-test.c index cec181309..b62acb1b0 100644 --- a/libtransmission/blocklist-test.c +++ b/libtransmission/blocklist-test.c @@ -6,22 +6,29 @@ #include "net.h" #include "utils.h" -#define VERBOSE 0 +#undef VERBOSE -#define check( A ) \ +#ifdef VERBOSE + #define check( A ) \ { \ ++test; \ if( A ){ \ - if( VERBOSE ) \ - fprintf( stderr, "PASS test #%d (%s, %d)\n", test, __FILE__,\ - __LINE__ );\ + fprintf( stderr, "PASS test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \ } else { \ - if( VERBOSE ) \ - fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__,\ - __LINE__ );\ + fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \ return test; \ } \ } +#else + #define check( A )\ + { \ + ++test; \ + if( !( A ) ){ \ + fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \ + return test; \ + } \ + } +#endif static void createTestBlocklist( const char * tmpfile ) @@ -45,11 +52,11 @@ int main( void ) { #ifndef WIN32 - char * tmpfile_txt = "/tmp/transmission-blocklist-test.txt"; - char * tmpfile_bin = "/tmp/transmission-blocklist-test.bin"; + const char * tmpfile_txt = "/tmp/transmission-blocklist-test.txt"; + const char * tmpfile_bin = "/tmp/transmission-blocklist-test.bin"; #else - char * tmpfile_txt = "transmission-blocklist-test.txt"; - char * tmpfile_bin = "transmission-blocklist-test.bin"; + const char * tmpfile_txt = "transmission-blocklist-test.txt"; + const char * tmpfile_bin = "transmission-blocklist-test.bin"; #endif struct tr_address addr; int test = 0; diff --git a/libtransmission/clients-test.c b/libtransmission/clients-test.c index caf9d13e8..374cbab95 100644 --- a/libtransmission/clients-test.c +++ b/libtransmission/clients-test.c @@ -4,22 +4,29 @@ #include "transmission.h" #include "clients.h" -#define VERBOSE 0 +#undef VERBOSE -#define check( A ) \ +#ifdef VERBOSE + #define check( A ) \ { \ ++test; \ if( A ){ \ - if( VERBOSE ) \ - fprintf( stderr, "PASS test #%d (%s, %d)\n", test, __FILE__,\ - __LINE__ );\ + fprintf( stderr, "PASS test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \ } else { \ - if( VERBOSE ) \ - fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__,\ - __LINE__ );\ + fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \ return test; \ } \ } +#else + #define check( A ) \ + { \ + ++test; \ + if( !( A ) ){ \ + fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \ + return test; \ + } \ + } +#endif #define TEST_CLIENT( A, B ) \ tr_clientForId( buf, sizeof( buf ), A ); \ diff --git a/libtransmission/json-test.c b/libtransmission/json-test.c index d7516c21c..1c6474e5e 100644 --- a/libtransmission/json-test.c +++ b/libtransmission/json-test.c @@ -5,23 +5,31 @@ #include "json.h" #include "utils.h" /* tr_free */ -#define VERBOSE 0 +#undef VERBOSE static int test = 0; -#define check( A ) \ +#ifdef VERBOSE + #define check( A ) \ { \ ++test; \ if( A ){ \ - if( VERBOSE ) \ - fprintf( stderr, "PASS test #%d (%s, %d)\n", test, __FILE__,\ - __LINE__ );\ + fprintf( stderr, "PASS test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \ } else { \ - fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__,\ - __LINE__ ); \ + fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \ return test; \ } \ } +#else + #define check( A ) \ + { \ + ++test; \ + if( !( A ) ){ \ + fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \ + return test; \ + } \ + } +#endif #include "ConvertUTF.h" diff --git a/libtransmission/peer-msgs-test.c b/libtransmission/peer-msgs-test.c index 136e8bec8..37598b956 100644 --- a/libtransmission/peer-msgs-test.c +++ b/libtransmission/peer-msgs-test.c @@ -4,22 +4,29 @@ #include "peer-msgs.h" #include "utils.h" -#define VERBOSE 0 +#undef VERBOSE -#define check( A ) \ +#ifdef VERBOSE + #define check( A ) \ { \ ++test; \ if( A ){ \ - if( VERBOSE ) \ - fprintf( stderr, "PASS test #%d (%s, %d)\n", test, __FILE__,\ - __LINE__ );\ + fprintf( stderr, "PASS test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \ } else { \ - if( VERBOSE ) \ - fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__,\ - __LINE__ );\ + fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \ return test; \ } \ } +#else + #define check( A ) \ + { \ + ++test; \ + if( !( A ) ){ \ + fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \ + return test; \ + } \ + } +#endif int main( void ) diff --git a/libtransmission/request-list-test.c b/libtransmission/request-list-test.c index 2dd972105..c9e62ddea 100644 --- a/libtransmission/request-list-test.c +++ b/libtransmission/request-list-test.c @@ -2,23 +2,31 @@ #include "transmission.h" #include "request-list.h" -#define VERBOSE 0 +#undef VERBOSE static int test = 0; -#define check( A ) \ +#ifdef VERBOSE + #define check( A ) \ { \ ++test; \ if( A ){ \ - if( VERBOSE ) \ - fprintf( stderr, "PASS test #%d (%s, %d)\n", test, __FILE__,\ - __LINE__ );\ + fprintf( stderr, "PASS test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \ } else { \ - fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__,\ - __LINE__ ); \ + fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \ return test; \ } \ } +#else + #define check( A ) \ + { \ + ++test; \ + if( !( A ) ){ \ + fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \ + return test; \ + } \ + } +#endif static int testFoo( void ) diff --git a/libtransmission/rpc-test.c b/libtransmission/rpc-test.c index c9e8eab03..180aef873 100644 --- a/libtransmission/rpc-test.c +++ b/libtransmission/rpc-test.c @@ -5,24 +5,31 @@ #include "rpcimpl.h" #include "utils.h" -#define VERBOSE 0 +#undef VERBOSE static int test = 0; -#define check( A ) \ +#ifdef VERBOSE + #define check( A ) \ { \ ++test; \ if( A ){ \ - if( VERBOSE ) \ - fprintf( stderr, "PASS test #%d (%s, %d)\n", test, __FILE__,\ - __LINE__ );\ + fprintf( stderr, "PASS test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \ } else { \ - if( VERBOSE ) \ - fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__,\ - __LINE__ );\ + fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \ return test; \ } \ } +#else + #define check( A ) \ + { \ + ++test; \ + if( !( A ) ){ \ + fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \ + return test; \ + } \ + } +#endif static int test_list( void ) diff --git a/libtransmission/rpcimpl.c b/libtransmission/rpcimpl.c index b9d3f8e34..243edbbf6 100644 --- a/libtransmission/rpcimpl.c +++ b/libtransmission/rpcimpl.c @@ -510,7 +510,7 @@ torrentGet( tr_session * session, tr_torrent ** torrents = getTorrents( session, args_in, &torrentCount ); tr_benc * list = tr_bencDictAddList( args_out, "torrents", torrentCount ); tr_benc * fields; - char * msg = NULL; + const char * msg = NULL; assert( idle_data == NULL ); diff --git a/libtransmission/test-peer-id.c b/libtransmission/test-peer-id.c index 23e4d6bf4..75d3050b5 100644 --- a/libtransmission/test-peer-id.c +++ b/libtransmission/test-peer-id.c @@ -5,22 +5,29 @@ #include "session.h" #include "utils.h" -#define VERBOSE 0 +#undef VERBOSE -#define check( A ) \ +#ifdef VERBOSE + #define check( A ) \ { \ ++test; \ if( A ){ \ - if( VERBOSE ) \ - fprintf( stderr, "PASS test #%d (%s, %d)\n", test, __FILE__,\ - __LINE__ );\ + fprintf( stderr, "PASS test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \ } else { \ - if( VERBOSE ) \ - fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__,\ - __LINE__ );\ + fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \ return test; \ } \ } +#else + #define check( A ) \ + { \ + ++test; \ + if( !( A ) ){ \ + fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \ + return test; \ + } \ + } +#endif int main( void ) diff --git a/libtransmission/tr-getopt.c b/libtransmission/tr-getopt.c index 80281c461..ce8a03205 100644 --- a/libtransmission/tr-getopt.c +++ b/libtransmission/tr-getopt.c @@ -25,7 +25,7 @@ int tr_optind = 1; static const char* getArgName( const tr_option * opt ) { - char * arg; + const char * arg; if( !opt->has_arg ) arg = ""; diff --git a/libtransmission/tr-getopt.h b/libtransmission/tr-getopt.h index dd32f65e4..d6db8b433 100644 --- a/libtransmission/tr-getopt.h +++ b/libtransmission/tr-getopt.h @@ -30,11 +30,11 @@ extern int tr_optind; typedef struct tr_option { int val; /* the value to return from tr_getopt() */ - char * longName; /* --long-form */ - char * description; /* option's description for tr_getopt_usage() */ - char * shortName; /* short form */ + const char * longName; /* --long-form */ + const char * description; /* option's description for tr_getopt_usage() */ + const char * shortName; /* short form */ int has_arg; /* 0 for no argument, 1 for argument */ - char * argName; /* argument's description for tr_getopt_usage() */ + const char * argName; /* argument's description for tr_getopt_usage() */ } tr_option; diff --git a/libtransmission/utils-test.c b/libtransmission/utils-test.c index f053dac2e..048fcf334 100644 --- a/libtransmission/utils-test.c +++ b/libtransmission/utils-test.c @@ -6,32 +6,39 @@ #include "utils.h" #include "crypto.h" -#define VERBOSE 0 +#undef VERBOSE #define NUM_LOOPS 1 #define SPEED_TEST 0 #if SPEED_TEST - #undef VERBOSE - #define VERBOSE 0 + #define VERBOSE #undef NUM_LOOPS #define NUM_LOOPS 200 #endif static int test = 0; -#define check( A ) \ +#ifdef VERBOSE + #define check( A ) \ { \ ++test; \ if( A ){ \ - if( VERBOSE ) \ - fprintf( stderr, "PASS test #%d (%s, %d)\n", test, __FILE__,\ - __LINE__ );\ + fprintf( stderr, "PASS test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \ } else { \ - fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__,\ - __LINE__ ); \ + fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \ return test; \ } \ } +#else + #define check( A ) \ + { \ + ++test; \ + if( !( A ) ){ \ + fprintf( stderr, "FAIL test #%d (%s, %d)\n", test, __FILE__, __LINE__ ); \ + return test; \ + } \ + } +#endif static int test_bitfields( void ) @@ -187,8 +194,7 @@ main( void ) int l; /* base64 */ - in = "YOYO!"; - out = tr_base64_encode( in, -1, &len ); + out = tr_base64_encode( "YOYO!", -1, &len ); check( out ); check( !strcmp( out, "WU9ZTyE=\n" ) ); check( len == 9 );