summaryrefslogtreecommitdiff
path: root/toxcore
diff options
context:
space:
mode:
Diffstat (limited to 'toxcore')
-rw-r--r--toxcore/DHT.c14
-rw-r--r--toxcore/Messenger.c4
-rw-r--r--toxcore/util.c4
3 files changed, 11 insertions, 11 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
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c
index e4d32b8a..a27a44dc 100644
--- a/toxcore/Messenger.c
+++ b/toxcore/Messenger.c
@@ -1483,7 +1483,7 @@ uint32_t Messenger_size(Messenger *m)
1483{ 1483{
1484 uint32_t size32 = sizeof(uint32_t), sizesubhead = size32 * 2; 1484 uint32_t size32 = sizeof(uint32_t), sizesubhead = size32 * 2;
1485 return size32 * 2 // global cookie 1485 return size32 * 2 // global cookie
1486 + sizesubhead + sizeof(uint32_t) + crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES 1486 + sizesubhead + sizeof(uint32_t) + crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES
1487 + sizesubhead + DHT_size(m->dht) // DHT 1487 + sizesubhead + DHT_size(m->dht) // DHT
1488 + sizesubhead + sizeof(Friend) * m->numfriends // Friendlist itself. 1488 + sizesubhead + sizeof(Friend) * m->numfriends // Friendlist itself.
1489 + sizesubhead + m->name_length // Own nickname. 1489 + sizesubhead + m->name_length // Own nickname.
@@ -1589,10 +1589,12 @@ static int messenger_load_state_callback(void *outer, uint8_t *data, uint32_t le
1589 } 1589 }
1590 1590
1591 break; 1591 break;
1592
1592#ifdef DEBUG 1593#ifdef DEBUG
1593 default: 1594 default:
1594 fprintf(stderr, "Load state: contains unrecognized part (len %u, type %u)\n", 1595 fprintf(stderr, "Load state: contains unrecognized part (len %u, type %u)\n",
1595 length, type); 1596 length, type);
1597 break;
1596#endif 1598#endif
1597 } 1599 }
1598 1600
diff --git a/toxcore/util.c b/toxcore/util.c
index 51b31e7b..b3263d05 100644
--- a/toxcore/util.c
+++ b/toxcore/util.c
@@ -58,7 +58,7 @@ int load_state(load_state_callback_func load_state_callback, void *outer,
58 uint32_t length_sub, cookie_type; 58 uint32_t length_sub, cookie_type;
59 uint32_t size32 = sizeof(uint32_t), size_head = size32 * 2; 59 uint32_t size32 = sizeof(uint32_t), size_head = size32 * 2;
60 60
61 while (length > size_head) { 61 while (length >= size_head) {
62 length_sub = *(uint32_t *)data; 62 length_sub = *(uint32_t *)data;
63 cookie_type = *(uint32_t *)(data + size32); 63 cookie_type = *(uint32_t *)(data + size32);
64 data += size_head; 64 data += size_head;
@@ -89,7 +89,7 @@ int load_state(load_state_callback_func load_state_callback, void *outer,
89 length -= length_sub; 89 length -= length_sub;
90 } 90 }
91 91
92 return length == 0 ? 0 : - 1; 92 return length == 0 ? 0 : -1;
93}; 93};
94 94
95#ifdef LOGGING 95#ifdef LOGGING