summaryrefslogtreecommitdiff
path: root/toxcore/DHT.c
diff options
context:
space:
mode:
authorCoren[m] <Break@Ocean>2013-09-17 01:08:57 +0200
committerCoren[m] <Break@Ocean>2013-09-17 01:08:57 +0200
commit1c57a3a3de376c8e9f127c409032fd94298e5e7b (patch)
tree7e4f841b70d15b5ea999100eb1445dd3c47361f9 /toxcore/DHT.c
parent1d2f4465bf634f45704eb69791c45bd623154909 (diff)
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)
Diffstat (limited to 'toxcore/DHT.c')
-rw-r--r--toxcore/DHT.c14
1 files changed, 6 insertions, 8 deletions
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)
1576 if (dht->close_clientlist[i].timestamp != 0) 1576 if (dht->close_clientlist[i].timestamp != 0)
1577 num++; 1577 num++;
1578 1578
1579 if (!num)
1580 return;
1581
1582 len = num * sizeof(Client_data); 1579 len = num * sizeof(Client_data);
1583 type = DHT_STATE_TYPE_CLIENTS; 1580 type = DHT_STATE_TYPE_CLIENTS;
1584 data = z_state_save_subheader(data, len, type); 1581 data = z_state_save_subheader(data, len, type);
1585 Client_data *clients = (Client_data *)data; 1582 if (num) {
1586 1583 Client_data *clients = (Client_data *)data;
1587 for (num = 0, i = 0; i < LCLIENT_LIST; ++i)
1588 if (dht->close_clientlist[i].timestamp != 0)
1589 memcpy(&clients[num++], &dht->close_clientlist[i], sizeof(Client_data));
1590 1584
1585 for (num = 0, i = 0; i < LCLIENT_LIST; ++i)
1586 if (dht->close_clientlist[i].timestamp != 0)
1587 memcpy(&clients[num++], &dht->close_clientlist[i], sizeof(Client_data));
1588 }
1591 data += len; 1589 data += len;
1592} 1590}
1593 1591