From e4eb716d2688f5c2d4615d79ad5f4f1eb50a9343 Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Fri, 3 Apr 2026 01:40:39 +0200 Subject: turn all int offsets into size_t --- opentracker.c | 11 ++++++----- ot_accesslist.c | 12 ++++++------ ot_clean.c | 6 +++--- ot_fullscrape.c | 6 +++--- ot_http.c | 18 ++++++++++-------- ot_http.h | 2 +- ot_iovec.c | 21 ++++++++++----------- ot_iovec.h | 12 ++++++------ ot_mutex.c | 12 ++++++------ ot_mutex.h | 4 ++-- ot_stats.c | 29 +++++++++++++---------------- ot_sync.c | 8 ++++---- ot_vector.c | 8 ++++---- ot_vector.h | 2 +- proxy.c | 6 +++--- trackerlogic.c | 16 ++++++++-------- trackerlogic.h | 2 +- 17 files changed, 87 insertions(+), 88 deletions(-) diff --git a/opentracker.c b/opentracker.c index 14e9989..f63db72 100644 --- a/opentracker.c +++ b/opentracker.c @@ -281,7 +281,8 @@ static void *server_mainloop(void *args) { struct ot_workstruct ws; time_t next_timeout_check = g_now_seconds + OT_CLIENT_TIMEOUT_CHECKINTERVAL; struct iovec *iovector; - int iovec_entries, is_partial; + size_t iovec_entries; + int is_partial; (void)args; @@ -444,7 +445,7 @@ int parse_configfile(char *config_filename) { #if defined(WANT_RESTRICT_STATS) || defined(WANT_IP_FROM_PROXY) || defined(WANT_SYNC_LIVE) ot_net tmpnet; #endif - int bound = 0; + int bound = 0; accesslist_filehandle = fopen(config_filename, "r"); @@ -566,15 +567,15 @@ void load_state(const char *const state_filename) { /* We do ignore anything that is not of the form "^[:xdigit:]:\d+:\d+" */ while (fgets(inbuf, sizeof(inbuf), state_filehandle)) { - int i; - for (i = 0; i < (int)sizeof(ot_hash); ++i) { + size_t i; + for (i = 0; i < sizeof(ot_hash); ++i) { int eger = 16 * scan_fromhex(inbuf[2 * i]) + scan_fromhex(inbuf[1 + 2 * i]); if (eger < 0) continue; infohash[i] = eger; } - if (i != (int)sizeof(ot_hash)) + if (i != sizeof(ot_hash)) continue; i *= 2; diff --git a/ot_accesslist.c b/ot_accesslist.c index 4b88c40..253fe95 100644 --- a/ot_accesslist.c +++ b/ot_accesslist.c @@ -129,8 +129,8 @@ static void accesslist_readfile(void) { /* We do ignore anything that is not of the form "^[:xdigit:]{40}[^:xdigit:].*" */ while (read_offs <= map_end) { - int i; - for (i = 0; i < (int)sizeof(ot_hash); ++i) { + size_t i; + for (i = 0; i < sizeof(ot_hash); ++i) { int eger1 = scan_fromhex((unsigned char)read_offs[2 * i]); int eger2 = scan_fromhex((unsigned char)read_offs[1 + 2 * i]); if (eger1 < 0 || eger2 < 0) @@ -262,7 +262,7 @@ static void *accesslist_adddel_worker(char *fifoname, ot_accesslist *_Atomic while ((linelen = getline(&line, &linecap, fifo)) > 0) { ot_hash info_hash; - int i; + size_t i; printf("Got line %*s", (int)linelen, line); /* We do ignore anything that is not of the form "^[:xdigit:]{40}[^:xdigit:].*" @@ -270,7 +270,7 @@ static void *accesslist_adddel_worker(char *fifoname, ot_accesslist *_Atomic if (linelen < 41) continue; - for (i = 0; i < (int)sizeof(ot_hash); ++i) { + for (i = 0; i < sizeof(ot_hash); ++i) { int eger1 = scan_fromhex((unsigned char)line[2 * i]); int eger2 = scan_fromhex((unsigned char)line[1 + 2 * i]); if (eger1 < 0 || eger2 < 0) @@ -511,7 +511,7 @@ int proxylist_check_proxy(const ot_ip6 proxy, const ot_ip6 address) { static ot_net g_admin_nets[OT_ADMINIP_MAX]; static ot_permissions g_admin_nets_permissions[OT_ADMINIP_MAX]; -static unsigned int g_admin_nets_count = 0; +static size_t g_admin_nets_count = 0; int accesslist_bless_net(ot_net *net, ot_permissions permissions) { if (g_admin_nets_count >= OT_ADMINIP_MAX) @@ -553,7 +553,7 @@ int accesslist_bless_net(ot_net *net, ot_permissions permissions) { } int accesslist_is_blessed(ot_ip6 ip, ot_permissions permissions) { - unsigned int i; + size_t i; for (i = 0; i < g_admin_nets_count; ++i) if (address_in_net(ip, g_admin_nets + i) && (g_admin_nets_permissions[i] & permissions)) return 1; diff --git a/ot_clean.c b/ot_clean.c index 291b847..825290d 100644 --- a/ot_clean.c +++ b/ot_clean.c @@ -20,7 +20,7 @@ #include "trackerlogic.h" /* Returns amount of removed peers */ -static ssize_t clean_single_bucket(ot_peer *peers, size_t peer_count, size_t peer_size, time_t timedout, int *removed_seeders) { +static ssize_t clean_single_bucket(ot_peer *peers, size_t peer_count, size_t peer_size, time_t timedout, size_t *removed_seeders) { ot_peer *last_peer = peers + peer_count * peer_size, *insert_point; /* Two scan modes: unless there is one peer removed, just increase ot_peertime */ @@ -50,7 +50,7 @@ static ssize_t clean_single_bucket(ot_peer *peers, size_t peer_count, size_t pee int clean_single_peer_list(ot_peerlist *peer_list, size_t peer_size) { ot_vector *peer_vector = &peer_list->peers; time_t timedout = (time_t)(g_now_minutes - peer_list->base); - int num_buckets = 1, removed_seeders = 0; + size_t num_buckets = 1, removed_seeders = 0; /* No need to clean empty torrent */ if (!timedout) @@ -111,7 +111,7 @@ int clean_single_torrent(ot_torrent *torrent) { static void *clean_worker(void *args) { (void)args; while (1) { - int bucket = OT_BUCKET_COUNT; + size_t bucket = OT_BUCKET_COUNT; while (bucket--) { ot_vector *torrents_list = mutex_bucket_lock(bucket); size_t toffs; diff --git a/ot_fullscrape.c b/ot_fullscrape.c index 6fd6d1c..7a8cca6 100644 --- a/ot_fullscrape.c +++ b/ot_fullscrape.c @@ -149,8 +149,8 @@ static char * fullscrape_write_one( ot_tasktype mode, char *r, ot_torrent *torre } static void fullscrape_make(int taskid, ot_tasktype mode) { - int bucket; - char *r, *re; + size_t bucket; + char *r, *re; struct iovec iovector = {NULL, 0}; /* Setup return vector... */ @@ -212,7 +212,7 @@ static void fullscrape_make(int taskid, ot_tasktype mode) { #ifdef WANT_COMPRESSION_GZIP static void fullscrape_make_gzip(int taskid, ot_tasktype mode) { - int bucket; + size_t bucket; char *r; struct iovec iovector = {NULL, 0}; int zres; diff --git a/ot_http.c b/ot_http.c index a87a02e..a789f0d 100644 --- a/ot_http.c +++ b/ot_http.c @@ -141,13 +141,12 @@ ssize_t http_issue_error(const int64 sock, struct ot_workstruct *ws, int code) { return ws->reply_size = -2; } -ssize_t http_sendiovecdata(const int64 sock, struct ot_workstruct *ws, int iovec_entries, struct iovec *iovector, int is_partial) { +ssize_t http_sendiovecdata(const int64 sock, struct ot_workstruct *ws, size_t iovec_entries, struct iovec *iovector, int is_partial) { struct http_data *cookie = io_getcookie(sock); io_batch *current; char *header; const char *encoding = ""; - int i; - size_t header_size, size = iovec_length(&iovec_entries, (const struct iovec **)&iovector); + size_t i, header_size, size = iovec_length(&iovec_entries, (const struct iovec **)&iovector); tai6464 t; /* No cookie? Bad socket. Leave. */ @@ -203,7 +202,7 @@ ssize_t http_sendiovecdata(const int64 sock, struct ot_workstruct *ws, int iovec iob_addbuf_free(current, header, header_size); /* Split huge iovectors into separate io_batches */ - for (i = 0; i < iovec_entries; ++i) { + for (i = 0; i < (size_t)iovec_entries; ++i) { /* If the current batch's limit is reached, try to reallocate a new batch to work on */ if (current->bytesleft > OT_BATCH_LIMIT) { io_batch *new_batch = realloc(cookie->batch, (cookie->batches + 1) * sizeof(io_batch)); @@ -426,8 +425,9 @@ static ssize_t http_handle_fullscrape(const int64 sock, struct ot_workstruct *ws static ssize_t http_handle_scrape(const int64 sock, struct ot_workstruct *ws, char *read_ptr) { static const ot_keywords keywords_scrape[] = {{"info_hash", 1}, {NULL, -3}}; - ot_hash *multiscrape_buf = (ot_hash *)ws->request; - int scanon = 1, numwant = 0; + ot_hash *multiscrape_buf = (ot_hash *)ws->request; + int scanon = 1; + size_t numwant = 0; /* This is to hack around stupid clients that send "scrape ?info_hash" */ if (read_ptr[-1] != '?') { @@ -502,7 +502,8 @@ static ot_keywords keywords_announce[] = {{"port", 1}, {"left", 2}, {"event", {"peer_id", 9}, {NULL, -3}}; static ot_keywords keywords_announce_event[] = {{"completed", 1}, {"stopped", 2}, {NULL, -3}}; static ssize_t http_handle_announce(const int64 sock, struct ot_workstruct *ws, char *read_ptr) { - int numwant, tmp, scanon; + size_t numwant; + int tmp, scanon; unsigned short port = 0; char *write_ptr; ssize_t len; @@ -578,8 +579,9 @@ static ssize_t http_handle_announce(const int64 sock, struct ot_workstruct * break; case 4: /* matched "numwant" */ len = scan_urlencoded_query(&read_ptr, write_ptr = read_ptr, SCAN_SEARCHPATH_VALUE); - if ((len <= 0) || scan_fixed_int(write_ptr, len, &numwant)) + if ((len <= 0) || scan_fixed_int(write_ptr, len, &tmp)) HTTPERROR_400_PARAM; + numwant = tmp; if (numwant < 0) numwant = 50; if (numwant > 200) diff --git a/ot_http.h b/ot_http.h index b5ae9ff..8980682 100644 --- a/ot_http.h +++ b/ot_http.h @@ -24,7 +24,7 @@ struct http_data { }; ssize_t http_handle_request(const int64 s, struct ot_workstruct *ws); -ssize_t http_sendiovecdata(const int64 s, struct ot_workstruct *ws, int iovec_entries, struct iovec *iovector, int is_partial); +ssize_t http_sendiovecdata(const int64 s, struct ot_workstruct *ws, size_t iovec_entries, struct iovec *iovector, int is_partial); ssize_t http_issue_error(const int64 s, struct ot_workstruct *ws, int code); extern char *g_stats_path; diff --git a/ot_iovec.c b/ot_iovec.c index 8e94c52..e2cdd4b 100644 --- a/ot_iovec.c +++ b/ot_iovec.c @@ -14,9 +14,9 @@ /* Opentracker */ #include "ot_iovec.h" -void *iovec_increase(int *iovec_entries, struct iovec **iovector, size_t new_alloc) { +void *iovec_increase(size_t *iovec_entries, struct iovec **iovector, size_t new_alloc) { void *new_data; - int new_entries = 1 + *iovec_entries; + size_t new_entries = 1 + *iovec_entries; struct iovec *new_vec = realloc(*iovector, new_entries * sizeof(struct iovec)); if (!new_vec) @@ -35,8 +35,8 @@ void *iovec_increase(int *iovec_entries, struct iovec **iovector, size_t new_all return new_data; } -void *iovec_append(int *iovec_entries, struct iovec **iovector, struct iovec *append_iovector) { - int new_entries = *iovec_entries + 1; +void *iovec_append(size_t *iovec_entries, struct iovec **iovector, struct iovec *append_iovector) { + size_t new_entries = *iovec_entries + 1; struct iovec *new_vec = realloc(*iovector, new_entries * sizeof(struct iovec)); if (!new_vec) return NULL; @@ -54,15 +54,15 @@ void *iovec_append(int *iovec_entries, struct iovec **iovector, struct iovec *ap return new_vec; } -void iovec_free(int *iovec_entries, struct iovec **iovector) { - int i; +void iovec_free(size_t *iovec_entries, struct iovec **iovector) { + size_t i; for (i = 0; i < *iovec_entries; ++i) free(((*iovector)[i]).iov_base); *iovector = NULL; *iovec_entries = 0; } -void iovec_fixlast(int *iovec_entries, struct iovec **iovector, void *last_ptr) { +void iovec_fixlast(size_t *iovec_entries, struct iovec **iovector, void *last_ptr) { if (*iovec_entries) { char *base = (char *)((*iovector)[*iovec_entries - 1]).iov_base; size_t new_alloc = ((char *)last_ptr) - base; @@ -72,7 +72,7 @@ void iovec_fixlast(int *iovec_entries, struct iovec **iovector, void *last_ptr) } } -void *iovec_fix_increase_or_free(int *iovec_entries, struct iovec **iovector, void *last_ptr, size_t new_alloc) { +void *iovec_fix_increase_or_free(size_t *iovec_entries, struct iovec **iovector, void *last_ptr, size_t new_alloc) { void *new_data; iovec_fixlast(iovec_entries, iovector, last_ptr); @@ -83,9 +83,8 @@ void *iovec_fix_increase_or_free(int *iovec_entries, struct iovec **iovector, vo return new_data; } -size_t iovec_length(const int *iovec_entries, const struct iovec **iovector) { - size_t length = 0; - int i; +size_t iovec_length(const size_t *iovec_entries, const struct iovec **iovector) { + size_t i, length = 0; for (i = 0; i < *iovec_entries; ++i) length += ((*iovector)[i]).iov_len; return length; diff --git a/ot_iovec.h b/ot_iovec.h index 4317ab7..eb4365b 100644 --- a/ot_iovec.h +++ b/ot_iovec.h @@ -8,13 +8,13 @@ #include -void *iovec_increase(int *iovec_entries, struct iovec **iovector, size_t new_alloc); -void *iovec_append(int *iovec_entries, struct iovec **iovector, struct iovec *append_iovector); -void iovec_fixlast(int *iovec_entries, struct iovec **iovector, void *last_ptr); -void iovec_free(int *iovec_entries, struct iovec **iovector); +void *iovec_increase(size_t *iovec_entries, struct iovec **iovector, size_t new_alloc); +void *iovec_append(size_t *iovec_entries, struct iovec **iovector, struct iovec *append_iovector); +void iovec_fixlast(size_t *iovec_entries, struct iovec **iovector, void *last_ptr); +void iovec_free(size_t *iovec_entries, struct iovec **iovector); -size_t iovec_length(const int *iovec_entries, const struct iovec **iovector); +size_t iovec_length(const size_t *iovec_entries, const struct iovec **iovector); -void *iovec_fix_increase_or_free(int *iovec_entries, struct iovec **iovector, void *last_ptr, size_t new_alloc); +void *iovec_fix_increase_or_free(size_t *iovec_entries, struct iovec **iovector, void *last_ptr, size_t new_alloc); #endif diff --git a/ot_mutex.c b/ot_mutex.c index 3011987..a1dba1f 100644 --- a/ot_mutex.c +++ b/ot_mutex.c @@ -56,7 +56,7 @@ struct ot_task { ot_taskid taskid; ot_tasktype tasktype; int64 sock; - int iovec_entries; + size_t iovec_entries; struct iovec *iovec; struct ot_task *next; }; @@ -105,7 +105,7 @@ void mutex_workqueue_canceltask(int64 sock) { if ((*task)->sock == sock) { struct iovec *iovec = (*task)->iovec; struct ot_task *ptask = *task; - int i; + size_t i; /* Free task's iovec */ for (i = 0; i < (*task)->iovec_entries; ++i) @@ -167,7 +167,7 @@ void mutex_workqueue_pushsuccess(ot_taskid taskid) { pthread_mutex_unlock(&tasklist_mutex); } -int mutex_workqueue_pushresult(ot_taskid taskid, int iovec_entries, struct iovec *iovec) { +int mutex_workqueue_pushresult(ot_taskid taskid, size_t iovec_entries, struct iovec *iovec) { struct ot_task *task; const char byte = 'o'; @@ -219,7 +219,7 @@ int mutex_workqueue_pushchunked(ot_taskid taskid, struct iovec *iovec) { return task ? 0 : -1; } -int64 mutex_workqueue_popresult(int *iovec_entries, struct iovec **iovec, int *is_partial) { +int64 mutex_workqueue_popresult(size_t *iovec_entries, struct iovec **iovec, int *is_partial) { struct ot_task **task; int64 sock = -1; @@ -254,7 +254,7 @@ int64 mutex_workqueue_popresult(int *iovec_entries, struct iovec **iovec, int *i } void mutex_init() { - int i; + size_t i; pthread_mutex_init(&tasklist_mutex, NULL); pthread_cond_init(&tasklist_being_filled, NULL); for (i = 0; i < OT_BUCKET_COUNT; ++i) @@ -263,7 +263,7 @@ void mutex_init() { } void mutex_deinit() { - int i; + size_t i; for (i = 0; i < OT_BUCKET_COUNT; ++i) pthread_mutex_destroy(bucket_mutex + i); pthread_mutex_destroy(&tasklist_mutex); diff --git a/ot_mutex.h b/ot_mutex.h index cdfabc9..ab1cf59 100644 --- a/ot_mutex.h +++ b/ot_mutex.h @@ -73,8 +73,8 @@ int mutex_workqueue_pushtask(int64 sock, ot_tasktype tasktype) void mutex_workqueue_canceltask(int64 sock); void mutex_workqueue_pushsuccess(ot_taskid taskid); ot_taskid mutex_workqueue_poptask(ot_tasktype *tasktype); -int mutex_workqueue_pushresult(ot_taskid taskid, int iovec_entries, struct iovec *iovector); +int mutex_workqueue_pushresult(ot_taskid taskid, size_t iovec_entries, struct iovec *iovector); int mutex_workqueue_pushchunked(ot_taskid taskid, struct iovec *iovec); -int64 mutex_workqueue_popresult(int *iovec_entries, struct iovec **iovector, int *is_partial); +int64 mutex_workqueue_popresult(size_t *iovec_entries, struct iovec **iovector, int *is_partial); #endif diff --git a/ot_stats.c b/ot_stats.c index b2eaec9..3d64bce 100644 --- a/ot_stats.c +++ b/ot_stats.c @@ -38,7 +38,7 @@ #endif /* Forward declaration */ -static void stats_make(int *iovec_entries, struct iovec **iovector, ot_tasktype mode); +static void stats_make(size_t *iovec_entries, struct iovec **iovector, ot_tasktype mode); #define OT_STATS_TMPSIZE 8192 /* Clumsy counters... to be rethought */ @@ -113,7 +113,7 @@ static int stat_increase_network_count(stats_network_node **pnode, int depth, ui } static int stats_shift_down_network_count(stats_network_node **node, int depth, int shift) { - int i, rest = 0; + size_t i, rest = 0; if (!*node) return 0; @@ -134,8 +134,7 @@ static int stats_shift_down_network_count(stats_network_node **node, int depth, static size_t stats_get_highscore_networks(stats_network_node *node, int depth, ot_ip6 node_value, size_t *scores, ot_ip6 *networks, int network_count, int limit) { - size_t score = 0; - int i; + size_t i, score = 0; if (!node) return 0; @@ -195,7 +194,7 @@ static size_t stats_return_busy_networks(char *reply, stats_network_node *tree, ot_ip6 networks[amount]; ot_ip6 node_value; size_t scores[amount]; - int i; + size_t i; char *r = reply; memset(scores, 0, sizeof(scores)); @@ -225,8 +224,7 @@ static size_t stats_return_busy_networks(char *reply, stats_network_node *tree, static size_t stats_slash24s_txt(char *reply, size_t amount) { stats_network_node *slash24s_network_counters_root = NULL; char *r = reply; - int bucket; - size_t i, peer_size = OT_PEER_SIZE4; + size_t i, bucket, peer_size = OT_PEER_SIZE4; for (bucket = 0; bucket < OT_BUCKET_COUNT; ++bucket) { ot_vector *torrents_list = mutex_bucket_lock(bucket); @@ -318,11 +316,10 @@ typedef struct { } ot_record; /* Fetches stats from tracker */ -size_t stats_top_txt(char *reply, int amount) { - size_t j; +size_t stats_top_txt(char *reply, size_t amount) { + size_t j, idx, bucket; ot_record top100s[100], top100c[100], top100l[100]; char *r = reply, hex_out[42]; - int idx, bucket; if (amount > 100) amount = 100; @@ -368,15 +365,15 @@ size_t stats_top_txt(char *reply, int amount) { return 0; } - r += sprintf(r, "Top %d torrents by peers:\n", amount); + r += sprintf(r, "Top %zd torrents by peers:\n", amount); for (idx = 0; idx < amount; ++idx) if (top100c[idx].val) r += sprintf(r, "\t%zd\t%s\n", top100c[idx].val, to_hex(hex_out, top100c[idx].hash)); - r += sprintf(r, "Top %d torrents by seeds:\n", amount); + r += sprintf(r, "Top %zd torrents by seeds:\n", amount); for (idx = 0; idx < amount; ++idx) if (top100s[idx].val) r += sprintf(r, "\t%zd\t%s\n", top100s[idx].val, to_hex(hex_out, top100s[idx].hash)); - r += sprintf(r, "Top %d torrents by leechers:\n", amount); + r += sprintf(r, "Top %zd torrents by leechers:\n", amount); for (idx = 0; idx < amount; ++idx) if (top100l[idx].val) r += sprintf(r, "\t%zd\t%s\n", top100l[idx].val, to_hex(hex_out, top100l[idx].hash)); @@ -477,7 +474,7 @@ static size_t stats_return_numwants(char *reply) { #endif #ifdef WANT_FULLLOG_NETWORKS -static void stats_return_fulllog(int *iovec_entries, struct iovec **iovector, char *r) { +static void stats_return_fulllog(size_t *iovec_entries, struct iovec **iovector, char *r) { ot_log *loglist = g_logchain_first, *llnext; char *re = r + OT_STATS_TMPSIZE; @@ -591,7 +588,7 @@ size_t return_stats_for_tracker(char *reply, int mode, int format) { } } -static void stats_make(int *iovec_entries, struct iovec **iovector, ot_tasktype mode) { +static void stats_make(size_t *iovec_entries, struct iovec **iovector, ot_tasktype mode) { char *r; *iovec_entries = 0; @@ -757,7 +754,7 @@ void stats_cleanup() { } static void *stats_worker(void *args) { - int iovec_entries; + size_t iovec_entries; struct iovec *iovector; (void)args; diff --git a/ot_sync.c b/ot_sync.c index 293acf3..65a8170 100644 --- a/ot_sync.c +++ b/ot_sync.c @@ -72,9 +72,9 @@ int add_changeset_to_tracker(uint8_t *data, size_t len) { /* Proposed output format d4:syncd20:8*N:(xxxxyyyy)*Nee */ -static void sync_make(int *iovec_entries, struct iovec **iovector) { - int bucket; - char *r, *re; +static void sync_make(size_t *iovec_entries, struct iovec **iovector) { + size_t bucket; + char *r, *re; /* Setup return vector... */ *iovec_entries = 0; @@ -140,7 +140,7 @@ static void sync_make(int *iovec_entries, struct iovec **iovector) { It grabs tasks from mutex_tasklist and delivers results back */ static void *sync_worker(void *args) { - int iovec_entries; + size_t iovec_entries; struct iovec *iovector; args = args; diff --git a/ot_vector.c b/ot_vector.c index 2acfbef..d068999 100644 --- a/ot_vector.c +++ b/ot_vector.c @@ -45,7 +45,7 @@ void *binary_search(const void *const key, const void *base, const size_t member return (void *)base; } -static uint8_t vector_hash_peer(ot_peer const *peer, size_t compare_size, int bucket_count) { +static uint8_t vector_hash_peer(ot_peer const *peer, size_t compare_size, size_t bucket_count) { unsigned int hash = 5381; uint8_t *p = (uint8_t *)peer; while (compare_size--) @@ -172,7 +172,7 @@ void vector_remove_torrent(ot_vector *vector, ot_torrent *match) { } } -void vector_clean_list(ot_vector *vector, int num_buckets) { +void vector_clean_list(ot_vector *vector, size_t num_buckets) { while (num_buckets--) free(vector[num_buckets].data); free(vector); @@ -180,7 +180,7 @@ void vector_clean_list(ot_vector *vector, int num_buckets) { } void vector_redistribute_buckets(ot_peerlist *peer_list, size_t peer_size) { - int tmp, bucket, bucket_size_new, num_buckets_new, num_buckets_old = 1; + size_t tmp, bucket, bucket_size_new, num_buckets_new, num_buckets_old = 1; ot_vector *bucket_list_new, *bucket_list_old = &peer_list->peers; int (*sort_func)(const void *, const void *) = peer_size == OT_PEER_SIZE6 ? &vector_compare_peer6 : &vector_compare_peer4; @@ -229,7 +229,7 @@ void vector_redistribute_buckets(ot_peerlist *peer_list, size_t peer_size) { /* Now sort them into the correct bucket */ for (bucket = 0; bucket < num_buckets_old; ++bucket) { ot_peer *peers_old = bucket_list_old[bucket].data; - int peer_count_old = bucket_list_old[bucket].size; + size_t peer_count_old = bucket_list_old[bucket].size; while (peer_count_old--) { ot_vector *bucket_dest = bucket_list_new; if (num_buckets_new > 1) diff --git a/ot_vector.h b/ot_vector.h index 8d41452..2618363 100644 --- a/ot_vector.h +++ b/ot_vector.h @@ -31,6 +31,6 @@ void vector_remove_torrent(ot_vector *vector, ot_torrent *match); /* For ot_clean.c */ void vector_redistribute_buckets(ot_peerlist *peer_list, size_t peer_size); void vector_fixup_peers(ot_vector *vector, size_t peer_size); -void vector_clean_list(ot_vector *vector, int num_buckets); +void vector_clean_list(ot_vector *vector, size_t num_buckets); #endif diff --git a/proxy.c b/proxy.c index 9946240..6bf45df 100644 --- a/proxy.c +++ b/proxy.c @@ -276,12 +276,12 @@ void reset_info_block(proxy_peer *peer) { * Multiple connections to/from the same ip are okay, if tracker_id doesn't match * Reconnect attempts occur only twice a minute */ -static int g_connection_count; +static size_t g_connection_count; static ot_time g_connection_reconn; static proxy_peer g_connections[MAX_PEERS]; static void handle_reconnects(void) { - int i; + size_t i; for (i = 0; i < g_connection_count; ++i) if (PROXYPEER_NEEDSCONNECT(g_connections[i].state)) { int64 newfd = socket_tcp6(); @@ -625,7 +625,7 @@ int main(int argc, char **argv) { static void *streamsync_worker(void *args) { (void)args; while (1) { - int bucket; + size_t bucket; /* For each bucket... */ for (bucket = 0; bucket < OT_BUCKET_COUNT; ++bucket) { /* Get exclusive access to that bucket */ diff --git a/trackerlogic.c b/trackerlogic.c index 04df544..1e25ec8 100644 --- a/trackerlogic.c +++ b/trackerlogic.c @@ -195,7 +195,7 @@ size_t add_peer_to_torrent_and_return_peers(PROTO_FLAG proto, struct ot_workstru } static size_t return_peers_all(ot_peerlist *peer_list, size_t peer_size, char *reply) { - unsigned int bucket, num_buckets = 1; + size_t bucket, num_buckets = 1; ot_vector *bucket_list = &peer_list->peers; size_t compare_size = OT_PEER_COMPARE_SIZE_FROM_PEER_SIZE(peer_size); size_t result = compare_size * peer_list->peer_count; @@ -224,7 +224,7 @@ static size_t return_peers_all(ot_peerlist *peer_list, size_t peer_size, char *r } static size_t return_peers_selection(struct ot_workstruct *ws, ot_peerlist *peer_list, size_t peer_size, size_t amount, char *reply) { - unsigned int bucket_offset, bucket_index = 0, num_buckets = 1; + size_t bucket_offset, bucket_index = 0, num_buckets = 1; ot_vector *bucket_list = &peer_list->peers; unsigned int shifted_pc = peer_list->peer_count; unsigned int shifted_step = 0; @@ -403,9 +403,10 @@ size_t return_udp_scrape_for_torrent(ot_hash const hash, char *reply) { } /* Fetches scrape info for a specific torrent */ -size_t return_tcp_scrape_for_torrent(ot_hash const *hash_list, int amount, char *reply) { +size_t return_tcp_scrape_for_torrent(ot_hash const *hash_list, size_t amount, char *reply) { char *r = reply; - int exactmatch, i; + int exactmatch; + size_t i; r += sprintf(r, "d5:filesd"); @@ -489,8 +490,7 @@ size_t remove_peer_from_torrent(PROTO_FLAG proto, struct ot_workstruct *ws) { } void iterate_all_torrents(int (*for_each)(ot_torrent *torrent, uintptr_t data), uintptr_t data) { - int bucket; - size_t j; + size_t bucket, j; for (bucket = 0; bucket < OT_BUCKET_COUNT; ++bucket) { ot_vector *torrents_list = mutex_bucket_lock(bucket); @@ -569,8 +569,8 @@ void trackerlogic_init() { } void trackerlogic_deinit(void) { - int bucket, delta_torrentcount = 0; - size_t j; + int delta_torrentcount = 0; + size_t bucket, j; /* Free all torrents... */ for (bucket = 0; bucket < OT_BUCKET_COUNT; ++bucket) { diff --git a/trackerlogic.h b/trackerlogic.h index 022184d..88d9a11 100644 --- a/trackerlogic.h +++ b/trackerlogic.h @@ -194,7 +194,7 @@ void exerr(char *message); otherwise it is released in return_peers_for_torrent */ size_t add_peer_to_torrent_and_return_peers(PROTO_FLAG proto, struct ot_workstruct *ws, size_t amount); size_t remove_peer_from_torrent(PROTO_FLAG proto, struct ot_workstruct *ws); -size_t return_tcp_scrape_for_torrent(ot_hash const *hash_list, int amount, char *reply); +size_t return_tcp_scrape_for_torrent(ot_hash const *hash_list, size_t amount, char *reply); size_t return_udp_scrape_for_torrent(ot_hash const hash, char *reply); void add_torrent_from_saved_state(ot_hash const hash, ot_time base, size_t down_count); #ifdef _DEBUG_RANDOMTORRENTS -- cgit v1.2.3