From c1be1fdaa93fb0c492047f2f57c238e8d42b50eb Mon Sep 17 00:00:00 2001 From: Jesper Jensen Date: Thu, 19 Jun 2025 17:33:09 +0200 Subject: Correct duplicate check I though it was a cool feature that C allowed you to implicitly memcmp statically sized arrays. It turns out it doesn't, it was just comparing their pointers which are obviously not equal. --- src/main.c | 1 - src/peers.c | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main.c b/src/main.c index 43d24e8..7dcac87 100644 --- a/src/main.c +++ b/src/main.c @@ -163,7 +163,6 @@ int main(int argc, char** argv) { dht.self = myID; } - metric_init(); routing_update_metrics(); peer_update_metrics(); diff --git a/src/peers.c b/src/peers.c index 42722b4..5942021 100644 --- a/src/peers.c +++ b/src/peers.c @@ -53,7 +53,7 @@ static void check_duplicates() { qsort(keys, keyi, sizeof(struct infohash), infohash_compar); for(size_t i = 1; i < keyi; i++) { - if(keys[i].inner == keys[i-1].inner) { + if(memcmp(&keys[i], &keys[i-1], sizeof(struct infohash)) == 0) { fatal("Duplicate key found"); } } -- cgit v1.2.3