From 5fbd24fda56a11bf5eb4cba734e78305f5d5eb45 Mon Sep 17 00:00:00 2001 From: Jordan Lee Date: Tue, 29 Mar 2016 03:04:54 +0000 Subject: [PATCH] fix a handful of minor compiler warnings, mostly in the unit tests, eg field width shortening or implicit signed/unsigned conversions --- libtransmission/crypto-test.c | 32 +++++------ libtransmission/file-test.c | 66 +++++++++++------------ libtransmission/json-test.c | 2 +- libtransmission/libtransmission-test.c | 18 +++++-- libtransmission/libtransmission-test.h | 14 +++-- libtransmission/move-test.c | 25 ++++----- libtransmission/net.h | 6 +-- libtransmission/platform.h | 2 +- libtransmission/ptrarray.h | 4 +- libtransmission/quark-test.c | 12 ++--- libtransmission/rename-test.c | 54 +++++++++---------- libtransmission/rpc-test.c | 2 +- libtransmission/session-test.c | 2 +- libtransmission/session.h | 2 +- libtransmission/tr-utp.h | 6 +-- libtransmission/transmission.h | 75 +++++++++++++++----------- libtransmission/utils-test.c | 12 ++--- libtransmission/utils.h | 24 ++++----- libtransmission/variant-test.c | 22 ++++---- libtransmission/watchdir-test.c | 8 +-- 20 files changed, 210 insertions(+), 178 deletions(-) diff --git a/libtransmission/crypto-test.c b/libtransmission/crypto-test.c index 05296dfd5..e2a145e56 100644 --- a/libtransmission/crypto-test.c +++ b/libtransmission/crypto-test.c @@ -22,7 +22,7 @@ test_torrent_hash (void) { tr_crypto a; uint8_t hash[SHA_DIGEST_LENGTH]; - int i; + uint8_t i; for (i = 0; i < SHA_DIGEST_LENGTH; ++i) hash[i] = i; @@ -70,7 +70,7 @@ test_encrypt_decrypt (void) int i; for (i = 0; i < SHA_DIGEST_LENGTH; ++i) - hash[i] = i; + hash[i] = (uint8_t)i; tr_cryptoConstruct (&a, hash, false); tr_cryptoConstruct_ (&b, hash, true); @@ -215,59 +215,59 @@ test_base64 (void) { size_t len; char * in, * out; - int i; + size_t i; out = tr_base64_encode_str ("YOYO!", &len); - check_int_eq (strlen (out), len); + check_uint_eq (strlen (out), len); check (base64_eq ("WU9ZTyE=", out)); in = tr_base64_decode_str (out, &len); - check_int_eq (5, len); + check_uint_eq (5, len); check_streq ("YOYO!", in); tr_free (in); tr_free (out); out = tr_base64_encode ("", 0, &len); - check_int_eq (0, len); + check_uint_eq (0, len); check_streq ("", out); tr_free (out); out = tr_base64_decode ("", 0, &len); - check_int_eq (0, len); + check_uint_eq (0, len); check_streq ("", out); tr_free (out); out = tr_base64_encode (NULL, 0, &len); - check_int_eq (0, len); + check_uint_eq (0, len); check (out == NULL); out = tr_base64_decode (NULL, 0, &len); - check_int_eq (0, len); + check_uint_eq (0, len); check (out == NULL); #define MAX_BUF_SIZE 1024 for (i = 1; i <= MAX_BUF_SIZE; ++i) { - int j; + size_t j; char buf[MAX_BUF_SIZE + 1]; for (j = 0; j < i; ++j) - buf[j] = tr_rand_int_weak (256); + buf[j] = (char) tr_rand_int_weak (256); out = tr_base64_encode (buf, j, &len); - check_int_eq (strlen (out), len); + check_uint_eq (strlen (out), len); in = tr_base64_decode (out, len, &len); - check_int_eq (j, len); + check_uint_eq (j, len); check (memcmp (in, buf, len) == 0); tr_free (in); tr_free (out); for (j = 0; j < i; ++j) - buf[j] = 1 + tr_rand_int_weak (255); + buf[j] = (char)(1 + tr_rand_int_weak (255)); buf[j] = '\0'; out = tr_base64_encode_str (buf, &len); - check_int_eq (strlen (out), len); + check_uint_eq (strlen (out), len); in = tr_base64_decode_str (out, &len); - check_int_eq (j, len); + check_uint_eq (j, len); check_streq (in, buf); tr_free (in); tr_free (out); diff --git a/libtransmission/file-test.c b/libtransmission/file-test.c index b98bfade5..dc82b5a14 100644 --- a/libtransmission/file-test.c +++ b/libtransmission/file-test.c @@ -120,7 +120,7 @@ path_contains_no_symlinks (const char * path) if (slashPos == NULL) slashPos = p + strlen (p) - 1; - pathPart = tr_strndup (path, slashPos - path + 1); + pathPart = tr_strndup (path, (size_t)(slashPos - path + 1)); if (!tr_sys_path_get_info (pathPart, TR_SYS_PATH_NO_FOLLOW, &info, NULL) || (info.type != TR_SYS_PATH_IS_FILE && info.type != TR_SYS_PATH_IS_DIRECTORY)) @@ -183,7 +183,7 @@ test_get_info (void) check (tr_sys_path_get_info (path1, 0, &info, &err)); check (err == NULL); check_int_eq (TR_SYS_PATH_IS_FILE, info.type); - check_int_eq (4, info.size); + check_uint_eq (4, info.size); check (info.last_modified_at >= t && info.last_modified_at <= time (NULL)); /* Good file info (by handle) */ @@ -192,7 +192,7 @@ test_get_info (void) check (tr_sys_file_get_info (fd, &info, &err)); check (err == NULL); check_int_eq (TR_SYS_PATH_IS_FILE, info.type); - check_int_eq (4, info.size); + check_uint_eq (4, info.size); check (info.last_modified_at >= t && info.last_modified_at <= time (NULL)); tr_sys_file_close (fd, NULL); @@ -224,7 +224,7 @@ test_get_info (void) check (tr_sys_path_get_info (path1, 0, &info, &err)); check (err == NULL); check_int_eq (TR_SYS_PATH_IS_FILE, info.type); - check_int_eq (4, info.size); + check_uint_eq (4, info.size); check (info.last_modified_at >= t && info.last_modified_at <= time (NULL)); /* Good file info (by handle) */ @@ -233,7 +233,7 @@ test_get_info (void) check (tr_sys_file_get_info (fd, &info, &err)); check (err == NULL); check_int_eq (TR_SYS_PATH_IS_FILE, info.type); - check_int_eq (4, info.size); + check_uint_eq (4, info.size); check (info.last_modified_at >= t && info.last_modified_at <= time (NULL)); tr_sys_file_close (fd, NULL); @@ -1010,30 +1010,30 @@ test_file_open (void) check (err != NULL); tr_error_clear (&err); tr_sys_path_get_info (path1, TR_SYS_PATH_NO_FOLLOW, &info, NULL); - check_int_eq (4, info.size); + check_uint_eq (4, info.size); /* Pointer is at the end of file */ tr_sys_path_get_info (path1, TR_SYS_PATH_NO_FOLLOW, &info, NULL); - check_int_eq (4, info.size); + check_uint_eq (4, info.size); fd = tr_sys_file_open (path1, TR_SYS_FILE_WRITE | TR_SYS_FILE_APPEND, 0600, &err); check (fd != TR_BAD_SYS_FILE); check (err == NULL); tr_sys_file_write (fd, "s", 1, NULL, NULL); /* On *NIX, pointer is positioned on each write but not initially */ tr_sys_file_seek (fd, 0, TR_SEEK_CUR, &n, NULL); - check_int_eq (5, n); + check_uint_eq (5, n); tr_sys_file_close (fd, NULL); /* File gets truncated */ tr_sys_path_get_info (path1, TR_SYS_PATH_NO_FOLLOW, &info, NULL); - check_int_eq (5, info.size); + check_uint_eq (5, info.size); fd = tr_sys_file_open (path1, TR_SYS_FILE_WRITE | TR_SYS_FILE_TRUNCATE, 0600, &err); check (fd != TR_BAD_SYS_FILE); check (err == NULL); tr_sys_file_get_info (fd, &info, NULL); - check_int_eq (0, info.size); + check_uint_eq (0, info.size); tr_sys_file_close (fd, NULL); tr_sys_path_get_info (path1, TR_SYS_PATH_NO_FOLLOW, &info, NULL); - check_int_eq (0, info.size); + check_uint_eq (0, info.size); /* TODO: symlink and hardlink tests */ @@ -1061,69 +1061,69 @@ test_file_read_write_seek (void) check (tr_sys_file_seek (fd, 0, TR_SEEK_CUR, &n, &err)); check (err == NULL); - check_int_eq (0, n); + check_uint_eq (0, n); check (tr_sys_file_write (fd, "test", 4, &n, &err)); check (err == NULL); - check_int_eq (4, n); + check_uint_eq (4, n); check (tr_sys_file_seek (fd, 0, TR_SEEK_CUR, &n, &err)); check (err == NULL); - check_int_eq (4, n); + check_uint_eq (4, n); check (tr_sys_file_seek (fd, 0, TR_SEEK_SET, &n, &err)); check (err == NULL); - check_int_eq (0, n); + check_uint_eq (0, n); check (tr_sys_file_read (fd, buf, sizeof (buf), &n, &err)); check (err == NULL); - check_int_eq (4, n); + check_uint_eq (4, n); check_int_eq (0, memcmp (buf, "test", 4)); check (tr_sys_file_seek (fd, -3, TR_SEEK_CUR, &n, &err)); check (err == NULL); - check_int_eq (1, n); + check_uint_eq (1, n); check (tr_sys_file_write (fd, "E", 1, &n, &err)); check (err == NULL); - check_int_eq (1, n); + check_uint_eq (1, n); check (tr_sys_file_seek (fd, -2, TR_SEEK_CUR, &n, &err)); check (err == NULL); - check_int_eq (0, n); + check_uint_eq (0, n); check (tr_sys_file_read (fd, buf, sizeof (buf), &n, &err)); check (err == NULL); - check_int_eq (4, n); + check_uint_eq (4, n); check_int_eq (0, memcmp (buf, "tEst", 4)); check (tr_sys_file_seek (fd, 0, TR_SEEK_END, &n, &err)); check (err == NULL); - check_int_eq (4, n); + check_uint_eq (4, n); check (tr_sys_file_write (fd, " ok", 3, &n, &err)); check (err == NULL); - check_int_eq (3, n); + check_uint_eq (3, n); check (tr_sys_file_seek (fd, 0, TR_SEEK_SET, &n, &err)); check (err == NULL); - check_int_eq (0, n); + check_uint_eq (0, n); check (tr_sys_file_read (fd, buf, sizeof (buf), &n, &err)); check (err == NULL); - check_int_eq (7, n); + check_uint_eq (7, n); check_int_eq (0, memcmp (buf, "tEst ok", 7)); check (tr_sys_file_write_at (fd, "-", 1, 4, &n, &err)); check (err == NULL); - check_int_eq (1, n); + check_uint_eq (1, n); check (tr_sys_file_read_at (fd, buf, 5, 2, &n, &err)); check (err == NULL); - check_int_eq (5, n); + check_uint_eq (5, n); check_int_eq (0, memcmp (buf, "st-ok", 5)); @@ -1153,17 +1153,17 @@ test_file_truncate (void) check (tr_sys_file_truncate (fd, 10, &err)); check (err == NULL); tr_sys_file_get_info (fd, &info, NULL); - check_int_eq (10, info.size); + check_uint_eq (10, info.size); check (tr_sys_file_truncate (fd, 20, &err)); check (err == NULL); tr_sys_file_get_info (fd, &info, NULL); - check_int_eq (20, info.size); + check_uint_eq (20, info.size); check (tr_sys_file_truncate (fd, 0, &err)); check (err == NULL); tr_sys_file_get_info (fd, &info, NULL); - check_int_eq (0, info.size); + check_uint_eq (0, info.size); check (tr_sys_file_truncate (fd, 50, &err)); check (err == NULL); @@ -1171,7 +1171,7 @@ test_file_truncate (void) tr_sys_file_close (fd, NULL); tr_sys_path_get_info (path1, 0, &info, NULL); - check_int_eq (50, info.size); + check_uint_eq (50, info.size); fd = tr_sys_file_open (path1, TR_SYS_FILE_WRITE | TR_SYS_FILE_CREATE, 0600, NULL); @@ -1181,7 +1181,7 @@ test_file_truncate (void) tr_sys_file_close (fd, NULL); tr_sys_path_get_info (path1, 0, &info, NULL); - check_int_eq (25, info.size); + check_uint_eq (25, info.size); tr_sys_path_remove (path1, NULL); @@ -1208,7 +1208,7 @@ test_file_preallocate (void) { check (err == NULL); tr_sys_file_get_info (fd, &info, NULL); - check_int_eq (50, info.size); + check_uint_eq (50, info.size); } else { @@ -1227,7 +1227,7 @@ test_file_preallocate (void) { check (err == NULL); tr_sys_file_get_info (fd, &info, NULL); - check_int_eq (500 * 1024 * 1024, info.size); + check_uint_eq (500 * 1024 * 1024, info.size); } else { diff --git a/libtransmission/json-test.c b/libtransmission/json-test.c index 0fef59f0e..b7c2ae46e 100644 --- a/libtransmission/json-test.c +++ b/libtransmission/json-test.c @@ -161,7 +161,7 @@ test1 (void) check (tr_variantIsDict (args)); check ((ids = tr_variantDictFind (args, TR_KEY_ids))); check (tr_variantIsList (ids)); - check_int_eq (2, tr_variantListSize (ids)); + check_uint_eq (2, tr_variantListSize (ids)); check (tr_variantGetInt (tr_variantListChild (ids, 0), &i)); check_int_eq (7, i); check (tr_variantGetInt (tr_variantListChild (ids, 1), &i)); diff --git a/libtransmission/libtransmission-test.c b/libtransmission/libtransmission-test.c index aed179963..efe6d982e 100644 --- a/libtransmission/libtransmission-test.c +++ b/libtransmission/libtransmission-test.c @@ -89,6 +89,21 @@ check_int_eq_impl (const char * file, int line, int64_t expected, int64_t actual return pass; } +bool +check_uint_eq_impl (const char * file, int line, uint64_t expected, uint64_t actual) +{ + const bool pass = expected == actual; + + if (should_print (pass)) { + if (pass) + fprintf (stderr, "PASS %s:%d\n", file, line); + else + fprintf (stderr, "FAIL %s:%d, expected \"%"PRIu64"\", got \"%"PRIu64"\"\n", file, line, expected, actual); + } + + return pass; +} + bool check_ptr_eq_impl (const char * file, int line, const void * expected, const void * actual) { @@ -194,21 +209,18 @@ libtest_sandbox_destroy (const char * sandbox) ***/ #define MEM_K 1024 -#define MEM_B_STR "B" #define MEM_K_STR "KiB" #define MEM_M_STR "MiB" #define MEM_G_STR "GiB" #define MEM_T_STR "TiB" #define DISK_K 1000 -#define DISK_B_STR "B" #define DISK_K_STR "kB" #define DISK_M_STR "MB" #define DISK_G_STR "GB" #define DISK_T_STR "TB" #define SPEED_K 1000 -#define SPEED_B_STR "B/s" #define SPEED_K_STR "kB/s" #define SPEED_M_STR "MB/s" #define SPEED_G_STR "GB/s" diff --git a/libtransmission/libtransmission-test.h b/libtransmission/libtransmission-test.h index 2876f7834..a3cdca362 100644 --- a/libtransmission/libtransmission-test.h +++ b/libtransmission/libtransmission-test.h @@ -25,9 +25,10 @@ extern bool verbose; bool should_print (bool pass); bool check_condition_impl (const char * file, int line, bool condition); -bool check_int_eq_impl (const char * file, int line, int64_t expected, int64_t actual); -bool check_ptr_eq_impl (const char * file, int line, const void * expected, const void * actual); -bool check_streq_impl (const char * file, int line, const char * expected, const char * actual); +bool check_int_eq_impl (const char * file, int line, int64_t expected, int64_t actual); +bool check_uint_eq_impl (const char * file, int line, uint64_t expected, uint64_t actual); +bool check_ptr_eq_impl (const char * file, int line, const void * expected, const void * actual); +bool check_streq_impl (const char * file, int line, const char * expected, const char * actual); /*** **** @@ -54,6 +55,13 @@ bool check_streq_impl (const char * file, int line, const char * expected, const return current_test; \ } while (0) +#define check_uint_eq(expected, actual) \ + do { \ + ++current_test; \ + if (!check_uint_eq_impl (__FILE__, __LINE__, (expected), (actual))) \ + return current_test; \ + } while (0) + #define check_ptr_eq(expected, actual) \ do { \ ++current_test; \ diff --git a/libtransmission/move-test.c b/libtransmission/move-test.c index 3a91c5da0..07f3ed150 100644 --- a/libtransmission/move-test.c +++ b/libtransmission/move-test.c @@ -68,7 +68,7 @@ test_incomplete_dir_threadfunc (void * vdata) static int test_incomplete_dir_impl (const char * incomplete_dir, const char * download_dir) { - size_t i; + tr_file_index_t file_index; tr_session * session; tr_torrent * tor; tr_completeness completeness; @@ -93,13 +93,14 @@ test_incomplete_dir_impl (const char * incomplete_dir, const char * download_dir check (tr_torrentStat(tor)->leftUntilDone == tor->info.pieceSize); check_file_location (tor, 0, tr_strdup_printf("%s/%s.part", incomplete_dir, tor->info.files[0].name)); check_file_location (tor, 1, tr_buildPath(incomplete_dir, tor->info.files[1].name, NULL)); - check_int_eq (tor->info.pieceSize, tr_torrentStat(tor)->leftUntilDone); + check_uint_eq (tor->info.pieceSize, tr_torrentStat(tor)->leftUntilDone); completeness = completeness_unset; tr_torrentSetCompletenessCallback (tor, zeroes_completeness_func, &completeness); /* now finish writing it */ { + tr_block_index_t block_index; tr_block_index_t first, last; char * zero_block = tr_new0 (char, tor->blockSize); struct test_incomplete_dir_data data; @@ -110,10 +111,10 @@ test_incomplete_dir_impl (const char * incomplete_dir, const char * download_dir data.buf = evbuffer_new (); tr_torGetPieceBlockRange (tor, data.pieceIndex, &first, &last); - for (i=first; i<=last; ++i) + for (block_index=first; block_index<=last; ++block_index) { evbuffer_add (data.buf, zero_block, tor->blockSize); - data.block = i; + data.block = block_index; data.done = false; data.offset = data.block * tor->blockSize; tr_runInEventThread (session, test_incomplete_dir_threadfunc, &data); @@ -125,14 +126,14 @@ test_incomplete_dir_impl (const char * incomplete_dir, const char * download_dir } libttest_blockingTorrentVerify (tor); - check_int_eq (0, tr_torrentStat(tor)->leftUntilDone); + check_uint_eq (0, tr_torrentStat(tor)->leftUntilDone); while ((completeness==completeness_unset) && (time(NULL)<=deadline)) tr_wait_msec (50); check_int_eq (TR_SEED, completeness); - for (i=0; iinfo.fileCount; ++i) - check_file_location (tor, i, tr_buildPath (download_dir, tor->info.files[i].name, NULL)); + for (file_index=0; file_indexinfo.fileCount; ++file_index) + check_file_location (tor, file_index, tr_buildPath (download_dir, tor->info.files[file_index].name, NULL)); /* cleanup */ tr_torrentRemove (tor, true, tr_sys_path_remove); @@ -167,7 +168,7 @@ test_incomplete_dir (void) static int test_set_location (void) { - size_t i; + tr_file_index_t file_index; int state; char * target_dir; tr_torrent * tor; @@ -183,7 +184,7 @@ test_set_location (void) tor = libttest_zero_torrent_init (session); libttest_zero_torrent_populate (tor, true); libttest_blockingTorrentVerify (tor); - check_int_eq (0, tr_torrentStat(tor)->leftUntilDone); + check_uint_eq (0, tr_torrentStat(tor)->leftUntilDone); /* now move it */ state = -1; @@ -194,12 +195,12 @@ test_set_location (void) /* confirm the torrent is still complete after being moved */ libttest_blockingTorrentVerify (tor); - check_int_eq (0, tr_torrentStat(tor)->leftUntilDone); + check_uint_eq (0, tr_torrentStat(tor)->leftUntilDone); /* confirm the filest really got moved */ libttest_sync (); - for (i=0; iinfo.fileCount; ++i) - check_file_location (tor, i, tr_buildPath (target_dir, tor->info.files[i].name, NULL)); + for (file_index=0; file_indexinfo.fileCount; ++file_index) + check_file_location (tor, file_index, tr_buildPath (target_dir, tor->info.files[file_index].name, NULL)); /* cleanup */ tr_free (target_dir); diff --git a/libtransmission/net.h b/libtransmission/net.h index 5407de82d..d987a5b91 100644 --- a/libtransmission/net.h +++ b/libtransmission/net.h @@ -26,8 +26,8 @@ #error only libtransmission should #include this header. #endif -#ifndef _TR_NET_H_ -#define _TR_NET_H_ +#ifndef TR_NET_H +#define TR_NET_H #ifdef _WIN32 #include @@ -174,4 +174,4 @@ char* tr_net_strerror (char * buf, size_t buflen, int err); const unsigned char *tr_globalIPv6 (void); -#endif /* _TR_NET_H_ */ +#endif /* TR_NET_H */ diff --git a/libtransmission/platform.h b/libtransmission/platform.h index b9abd1b73..d9cf6fd33 100644 --- a/libtransmission/platform.h +++ b/libtransmission/platform.h @@ -54,7 +54,7 @@ tr_thread* tr_threadNew (void (*func)(void *), void * arg); /** @brief Return nonzero if this function is being called from `thread' @param thread the thread being tested */ -bool tr_amInThread (const tr_thread *); +bool tr_amInThread (const tr_thread * thread); /*** **** diff --git a/libtransmission/ptrarray.h b/libtransmission/ptrarray.h index 0a9571ee2..8bc5c0b37 100644 --- a/libtransmission/ptrarray.h +++ b/libtransmission/ptrarray.h @@ -11,8 +11,8 @@ #error only libtransmission should #include this header. #endif -#ifndef _TR_PTR_ARRAY_H_ -#define _TR_PTR_ARRAY_H_ +#ifndef TR_PTR_ARRAY_H +#define TR_PTR_ARRAY_H #include diff --git a/libtransmission/quark-test.c b/libtransmission/quark-test.c index a189db5f6..aaafd8b2d 100644 --- a/libtransmission/quark-test.c +++ b/libtransmission/quark-test.c @@ -24,10 +24,10 @@ test_static_quarks (void) size_t len; const char * str; - str = tr_quark_get_string (i, &len); - check_int_eq (strlen(str), len); + str = tr_quark_get_string ((tr_quark)i, &len); + check_uint_eq (strlen(str), len); check (tr_quark_lookup (str, len, &q)); - check_int_eq (i, q); + check_int_eq (i, (int)q); } for (i=0; i+1activity); \ - check_int_eq (TR_STAT_OK, st->error); \ - check_int_eq (totalSize, st->sizeWhenDone); \ - check_int_eq (totalSize, st->leftUntilDone); \ - check_int_eq (totalSize, tor->info.totalSize); \ - check_int_eq (0, st->haveValid); \ + const tr_stat * tst = tr_torrentStat(tor); \ + check_int_eq (TR_STATUS_STOPPED, tst->activity); \ + check_int_eq (TR_STAT_OK, tst->error); \ + check_uint_eq (totalSize, tst->sizeWhenDone); \ + check_uint_eq (totalSize, tst->leftUntilDone); \ + check_uint_eq (totalSize, tor->info.totalSize); \ + check_uint_eq (0, tst->haveValid); \ } while (0) static bool @@ -157,11 +157,11 @@ test_single_filename_torrent (void) st = tr_torrentStat (tor); check_int_eq (TR_STATUS_STOPPED, st->activity); check_int_eq (TR_STAT_OK, st->error); - check_int_eq (0, st->leftUntilDone); - check_int_eq (0, st->haveUnchecked); - check_int_eq (0, st->desiredAvailable); - check_int_eq (totalSize, st->sizeWhenDone); - check_int_eq (totalSize, st->haveValid); + check_uint_eq (0, st->leftUntilDone); + check_uint_eq (0, st->haveUnchecked); + check_uint_eq (0, st->desiredAvailable); + check_uint_eq (totalSize, st->sizeWhenDone); + check_uint_eq (totalSize, st->haveValid); /** *** okay! we've finally put together all the scaffolding to test @@ -297,8 +297,8 @@ test_multifile_torrent (void) /* sanity check the info */ check_streq (tor->info.name, "Felidae"); - check_int_eq (totalSize, tor->info.totalSize); - check_int_eq (4, tor->info.fileCount); + check_uint_eq (totalSize, tor->info.totalSize); + check_uint_eq (4, tor->info.fileCount); for (i=0; i<4; ++i) check_streq (expected_files[i], files[i].name); @@ -314,11 +314,11 @@ test_multifile_torrent (void) st = tr_torrentStat (tor); check_int_eq (TR_STATUS_STOPPED, st->activity); check_int_eq (TR_STAT_OK, st->error); - check_int_eq (0, st->leftUntilDone); - check_int_eq (0, st->haveUnchecked); - check_int_eq (0, st->desiredAvailable); - check_int_eq (totalSize, st->sizeWhenDone); - check_int_eq (totalSize, st->haveValid); + check_uint_eq (0, st->leftUntilDone); + check_uint_eq (0, st->haveUnchecked); + check_uint_eq (0, st->desiredAvailable); + check_uint_eq (totalSize, st->sizeWhenDone); + check_uint_eq (totalSize, st->haveValid); /** @@ -506,22 +506,22 @@ test_partial_file (void) ***/ tor = libttest_zero_torrent_init (session); - check_int_eq (totalSize, tor->info.totalSize); - check_int_eq (pieceSize, tor->info.pieceSize); - check_int_eq (pieceCount, tor->info.pieceCount); + check_uint_eq (totalSize, tor->info.totalSize); + check_uint_eq (pieceSize, tor->info.pieceSize); + check_uint_eq (pieceCount, tor->info.pieceCount); check_streq ("files-filled-with-zeroes/1048576", tor->info.files[0].name); check_streq ("files-filled-with-zeroes/4096", tor->info.files[1].name); check_streq ("files-filled-with-zeroes/512", tor->info.files[2].name); libttest_zero_torrent_populate (tor, false); fst = tr_torrentFiles (tor, NULL); - check_int_eq (length[0] - pieceSize, fst[0].bytesCompleted); - check_int_eq (length[1], fst[1].bytesCompleted); - check_int_eq (length[2], fst[2].bytesCompleted); + check_uint_eq (length[0] - pieceSize, fst[0].bytesCompleted); + check_uint_eq (length[1], fst[1].bytesCompleted); + check_uint_eq (length[2], fst[2].bytesCompleted); tr_torrentFilesFree (fst, tor->info.fileCount); st = tr_torrentStat (tor); - check_int_eq (totalSize, st->sizeWhenDone); - check_int_eq (pieceSize, st->leftUntilDone); + check_uint_eq (totalSize, st->sizeWhenDone); + check_uint_eq (pieceSize, st->leftUntilDone); /*** **** diff --git a/libtransmission/rpc-test.c b/libtransmission/rpc-test.c index 2f3f0b73c..a02506f51 100644 --- a/libtransmission/rpc-test.c +++ b/libtransmission/rpc-test.c @@ -46,7 +46,7 @@ test_list (void) tr_rpc_parse_list_str (&top, "asdf", TR_BAD_SIZE); check (tr_variantIsString (&top)); check (tr_variantGetStr (&top, &str, &len)); - check_int_eq (4, len); + check_uint_eq (4, len); check_streq ("asdf", str); tr_variantFree (&top); diff --git a/libtransmission/session-test.c b/libtransmission/session-test.c index d4f52fb29..0bda2c058 100644 --- a/libtransmission/session-test.c +++ b/libtransmission/session-test.c @@ -36,7 +36,7 @@ testPeerId (void) for (j = 8; j < PEER_ID_LEN; ++j) { - char tmp[2] = { peer_id[j], '\0' }; + char tmp[2] = { (char)peer_id[j], '\0' }; val += strtoul (tmp, NULL, 36); } diff --git a/libtransmission/session.h b/libtransmission/session.h index 41dfa202a..c84c2c9d1 100644 --- a/libtransmission/session.h +++ b/libtransmission/session.h @@ -303,7 +303,7 @@ toSpeedKBps (unsigned int Bps) { return Bps / (double)tr_speed_K; } static inline uint64_t toMemBytes (unsigned int MB) { uint64_t B = tr_mem_K * tr_mem_K; B *= MB; return B; } static inline int -toMemMB (uint64_t B) { return B / (tr_mem_K * tr_mem_K); } +toMemMB (uint64_t B) { return (int)(B / (tr_mem_K * tr_mem_K)); } /** **/ diff --git a/libtransmission/tr-utp.h b/libtransmission/tr-utp.h index 9f17d2589..dc095b947 100644 --- a/libtransmission/tr-utp.h +++ b/libtransmission/tr-utp.h @@ -25,8 +25,8 @@ THE SOFTWARE. #error only libtransmission should #include this header. #endif -#ifndef _TR_UTP_H_ -#define _TR_UTP_H_ +#ifndef TR_UTP_H +#define TR_UTP_H int tr_utpPacket (const unsigned char *buf, size_t buflen, const struct sockaddr *from, socklen_t fromlen, @@ -37,4 +37,4 @@ void tr_utpClose (tr_session *); void tr_utpSendTo (void *closure, const unsigned char *buf, size_t buflen, const struct sockaddr *to, socklen_t tolen); -#endif /* #ifndef _TR_UTP_H_ */ +#endif /* #ifndef TR_UTP_H */ diff --git a/libtransmission/transmission.h b/libtransmission/transmission.h index 4f76adfd6..3f77b5543 100644 --- a/libtransmission/transmission.h +++ b/libtransmission/transmission.h @@ -20,6 +20,14 @@ extern "C" { #endif +#if defined(__GNUC__) + #define TR_DEPRECATED __attribute__((deprecated)) +#elif defined(__clang__) + #define TR_DEPRECATED __attribute__((gnu::deprecated)) +#else + #define TR_DEPRECATED +#endif + /*** **** **** Basic Types @@ -145,23 +153,24 @@ const char* tr_getDefaultDownloadDir (void); * tr_variantFree (&settings); * @endcode * - * @param initme pointer to a tr_variant dictionary + * @param setme_dictionary pointer to a tr_variant dictionary * @see tr_sessionLoadSettings () * @see tr_sessionInit () * @see tr_getDefaultConfigDir () */ -void tr_sessionGetDefaultSettings (struct tr_variant * dictionary); +void tr_sessionGetDefaultSettings (struct tr_variant * setme_dictionary); /** * Add the session's current configuration settings to the benc dictionary. * * FIXME: this probably belongs in libtransmissionapp * - * @param session - * @param dictionary + * @param session the session to query + * @param setme_dictionary the dictionary to populate * @see tr_sessionGetDefaultSettings () */ -void tr_sessionGetSettings (tr_session *, struct tr_variant * dictionary); +void tr_sessionGetSettings (tr_session * session, + struct tr_variant * setme_dictionary); /** * Load settings from the configuration directory's settings.json file, @@ -187,13 +196,14 @@ bool tr_sessionLoadSettings (struct tr_variant * dictionary, * * FIXME: this belongs in libtransmissionapp * - * @param session - * @param dictionary + * @param session the session to save + * @param configDir the directory to write to + * @param dictionary the dictionary to save * @see tr_sessionLoadSettings () */ void tr_sessionSaveSettings (tr_session * session, const char * configDir, - const struct tr_variant * dictonary); + const struct tr_variant * dictionary); /** * @brief Initialize a libtransmission session. @@ -355,8 +365,8 @@ tr_port tr_sessionGetRPCPort (const tr_session * session); /** * @brief Specify which base URL to use. * - * @detail The RPC API is accessible under /rpc, the web interface under - * /web. + * @param session the session to set + * @param url the base url to use. The RPC API is accessible under /rpc, the web interface under * /web. * * @see tr_sessionGetRPCUrl */ @@ -895,8 +905,9 @@ typedef enum tr_ctorMode; /** @brief Create a torrent constructor object used to instantiate a tr_torrent - @param session the tr_session. This is required if you're going to call - tr_torrentNew (), but you can use NULL for tr_torrentParse (). + @param session_or_NULL the tr_session. + This is required if you're going to call tr_torrentNew (), + but you can use NULL for tr_torrentParse (). @see tr_torrentNew (), tr_torrentParse () */ tr_ctor* tr_ctorNew (const tr_session * session_or_NULL); @@ -1012,9 +1023,9 @@ tr_parse_result; * TR_PARSE_OK if parsing succeeded and it's not a duplicate; * TR_PARSE_DUPLICATE if parsing succeeded but it's a duplicate. * - * @param setme_info If parsing is successful and setme_info is non-NULL, - * the parsed metainfo is stored there and sould be freed - * by calling tr_metainfoFree () when no longer needed. + * @param setme_info_or_NULL If parsing is successful and setme_info is non-NULL, + * the parsed metainfo is stored there and sould be freed + * by calling tr_metainfoFree () when no longer needed. * * Notes: * @@ -1038,12 +1049,12 @@ void tr_metainfoFree (tr_info * inf); * * Returns a pointer to the torrent on success, or NULL on failure. * - * @param setme_error: TR_PARSE_ERR if the parsing failed; - * TR_PARSE_OK if parsing succeeded and it's not a duplicate; - * TR_PARSE_DUPLICATE if parsing succeeded but it's a duplicate. - * - * @param setme_duplicate_id: when setmeError is TR_PARSE_DUPLICATE, - * this field is set to the duplicate torrent's id. + * @param ctor the builder struct + * @param setme_error TR_PARSE_ERR if the parsing failed; + * TR_PARSE_OK if parsing succeeded and it's not a duplicate; + * TR_PARSE_DUPLICATE if parsing succeeded but it's a duplicate. + * @param setme_duplicate_id when setmeError is TR_PARSE_DUPLICATE, + * this field is set to the duplicate torrent's id. */ tr_torrent * tr_torrentNew (const tr_ctor * ctor, int * setme_error, @@ -1082,11 +1093,11 @@ typedef void (*tr_torrent_rename_done_func)(tr_torrent * torrent, /** * @brief Rename a file or directory in a torrent. * - * @tor: the torrent whose path will be renamed. - * @oldpath: the path to the file or folder that will be renamed - * @newname: the file or folder's new name - * @callback: the callback invoked when the renaming finishes, or NULL - * @callback_data: the pointer to pass in the callback's user_data arg + * @param tor the torrent whose path will be renamed + * @param oldpath the path to the file or folder that will be renamed + * @param newname the file or folder's new name + * @param callback the callback invoked when the renaming finishes, or NULL + * @param callback_data the pointer to pass in the callback's user_data arg * * As a special case, renaming the root file in a torrent will also * update tr_info.name. @@ -1124,7 +1135,7 @@ void tr_torrentRenamePath (tr_torrent * tor, const char * oldpath, const char * newname, tr_torrent_rename_done_func callback, - void * callback_user_data); + void * callback_data); enum { @@ -1180,7 +1191,7 @@ const char* tr_torrentName (const tr_torrent *); * @param tor the torrent whose file we're looking for * @param fileNum the fileIndex, in [0...tr_info.fileCount) */ -char* tr_torrentFindFile (const tr_torrent * tor, tr_file_index_t fileNo); +char* tr_torrentFindFile (const tr_torrent * tor, tr_file_index_t fileNum); /*** @@ -1710,7 +1721,7 @@ void tr_torrentAmountFinished (const tr_torrent * torrent, * @param aborted true if the verify ended prematurely for some reason, * such as tr_torrentStop() or tr_torrentSetLocation() * being called during verification. - * @param callback_data the user-defined pointer from tr_torrentVerify() + * @param user_data the user-defined pointer from tr_torrentVerify() */ typedef void (*tr_verify_done_func)(tr_torrent * torrent, bool aborted, @@ -2030,14 +2041,14 @@ const tr_stat * tr_torrentStatCached (tr_torrent * torrent); /** @deprecated */ void tr_torrentSetAddedDate (tr_torrent * torrent, - time_t addedDate); + time_t addedDate) TR_DEPRECATED; /** @deprecated */ void tr_torrentSetActivityDate (tr_torrent * torrent, - time_t activityDate); + time_t activityDate) TR_DEPRECATED; /** @deprecated */ -void tr_torrentSetDoneDate (tr_torrent * torrent, time_t doneDate); +void tr_torrentSetDoneDate (tr_torrent * torrent, time_t doneDate) TR_DEPRECATED; /** @} */ diff --git a/libtransmission/utils-test.c b/libtransmission/utils-test.c index e028cc80d..83d7a74a9 100644 --- a/libtransmission/utils-test.c +++ b/libtransmission/utils-test.c @@ -301,19 +301,19 @@ test_hex (void) static int test_array (void) { - int i; - int array[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; - int n = sizeof (array) / sizeof (array[0]); + size_t i; + size_t array[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + size_t n = sizeof (array) / sizeof (array[0]); - tr_removeElementFromArray (array, 5u, sizeof (int), n--); + tr_removeElementFromArray (array, 5u, sizeof (size_t), n--); for (i=0; i