From 39700abd86cb2ffb13c8a428ddd75a00866f8a21 Mon Sep 17 00:00:00 2001 From: irungentoo Date: Thu, 10 Dec 2015 10:09:48 -0500 Subject: [PATCH] Check if node can be stored before sorting. --- toxcore/DHT.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/toxcore/DHT.c b/toxcore/DHT.c index 1edc86ae2..dc640562a 100644 --- a/toxcore/DHT.c +++ b/toxcore/DHT.c @@ -733,15 +733,15 @@ static int replace_all( Client_data *list, if ((ip_port.ip.family != AF_INET) && (ip_port.ip.family != AF_INET6)) return 0; - memcpy(cmp_public_key, comp_public_key, crypto_box_PUBLICKEYBYTES); - qsort(list, length, sizeof(Client_data), cmp_dht_entry); + if (store_node_ok(&list[1], public_key, comp_public_key)) { + memcpy(cmp_public_key, comp_public_key, crypto_box_PUBLICKEYBYTES); + qsort(list, length, sizeof(Client_data), cmp_dht_entry); - Client_data *client = &list[0]; - - if (store_node_ok(client, public_key, comp_public_key)) { IPPTsPng *ipptp_write = NULL; IPPTsPng *ipptp_clear = NULL; + Client_data *client = &list[0]; + if (ip_port.ip.family == AF_INET) { ipptp_write = &client->assoc4; ipptp_clear = &client->assoc6; @@ -1375,7 +1375,6 @@ static void divide_by_2(uint8_t *public_key) static void find_midpoint(uint8_t *out, const uint8_t *top, const uint8_t *bot) { unsigned int i; - _Bool one = 0; for (i = 0; i < crypto_box_PUBLICKEYBYTES; ++i) { out[i] = top[i] ^ bot[i];