From 1c57a3a3de376c8e9f127c409032fd94298e5e7b Mon Sep 17 00:00:00 2001 From: "Coren[m]" Date: Tue, 17 Sep 2013 01:08:57 +0200 Subject: Tests of state loading/saving lead to two fixes for DHT.c and util.c util.c: - fix in empty section at the end of the state, showed as bug when having an empty name DHT.c: - fix in saving less data than originally announced, showed as bug when not having reached any clients ever (no clients or only with timestamp of zero) --- toxcore/DHT.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'toxcore/DHT.c') diff --git a/toxcore/DHT.c b/toxcore/DHT.c index ddd1e1e0..f38ce3a5 100644 --- a/toxcore/DHT.c +++ b/toxcore/DHT.c @@ -1576,18 +1576,16 @@ void DHT_save(DHT *dht, uint8_t *data) if (dht->close_clientlist[i].timestamp != 0) num++; - if (!num) - return; - len = num * sizeof(Client_data); type = DHT_STATE_TYPE_CLIENTS; data = z_state_save_subheader(data, len, type); - Client_data *clients = (Client_data *)data; - - for (num = 0, i = 0; i < LCLIENT_LIST; ++i) - if (dht->close_clientlist[i].timestamp != 0) - memcpy(&clients[num++], &dht->close_clientlist[i], sizeof(Client_data)); + if (num) { + Client_data *clients = (Client_data *)data; + for (num = 0, i = 0; i < LCLIENT_LIST; ++i) + if (dht->close_clientlist[i].timestamp != 0) + memcpy(&clients[num++], &dht->close_clientlist[i], sizeof(Client_data)); + } data += len; } -- cgit v1.2.3