diff options
author | Coren[m] <Break@Ocean> | 2013-09-14 10:43:09 +0200 |
---|---|---|
committer | Coren[m] <Break@Ocean> | 2013-09-14 10:43:09 +0200 |
commit | a341b259b6342962e209f1b50708abe40f1cdad2 (patch) | |
tree | 167a6809cf3d5e186a2f9ccf2da8693a3b417d89 /toxcore/DHT.c | |
parent | d2603cf169b1b2d860f2b851590f5ae2be01011c (diff) |
Change sublength to 32 bits. Someone might have more than (sizeof(Friends) / 65536) friends...
Diffstat (limited to 'toxcore/DHT.c')
-rw-r--r-- | toxcore/DHT.c | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/toxcore/DHT.c b/toxcore/DHT.c index 0b866940..fcd15686 100644 --- a/toxcore/DHT.c +++ b/toxcore/DHT.c | |||
@@ -1304,8 +1304,6 @@ int DHT_load_old(DHT *dht, uint8_t *data, uint32_t size) | |||
1304 | #define DHT_STATE_TYPE_FRIENDS 1 | 1304 | #define DHT_STATE_TYPE_FRIENDS 1 |
1305 | #define DHT_STATE_TYPE_CLIENTS 2 | 1305 | #define DHT_STATE_TYPE_CLIENTS 2 |
1306 | 1306 | ||
1307 | typedef uint16_t statelensub_t; | ||
1308 | |||
1309 | /* Get the size of the DHT (for saving). */ | 1307 | /* Get the size of the DHT (for saving). */ |
1310 | uint32_t DHT_size(DHT *dht) | 1308 | uint32_t DHT_size(DHT *dht) |
1311 | { | 1309 | { |
@@ -1314,26 +1312,25 @@ uint32_t DHT_size(DHT *dht) | |||
1314 | if (dht->close_clientlist[i].timestamp != 0) | 1312 | if (dht->close_clientlist[i].timestamp != 0) |
1315 | num++; | 1313 | num++; |
1316 | 1314 | ||
1317 | uint32_t size32 = sizeof(uint32_t), lengthsublen = sizeof(statelensub_t); | 1315 | uint32_t size32 = sizeof(uint32_t), sizesubhead = size32 * 2; |
1318 | uint32_t sizesubhead = lengthsublen + size32; | ||
1319 | return size32 | 1316 | return size32 |
1320 | + sizesubhead + sizeof(DHT_Friend) * dht->num_friends | 1317 | + sizesubhead + sizeof(DHT_Friend) * dht->num_friends |
1321 | + sizesubhead + sizeof(Client_data) * num; | 1318 | + sizesubhead + sizeof(Client_data) * num; |
1322 | } | 1319 | } |
1323 | 1320 | ||
1324 | static uint8_t *z_state_save_subheader(uint8_t *data, statelensub_t len, uint16_t type) | 1321 | static uint8_t *z_state_save_subheader(uint8_t *data, uint32_t len, uint16_t type) |
1325 | { | 1322 | { |
1326 | *(statelensub_t *)data = len; | 1323 | uint32_t *data32 = (uint32_t *)data; |
1327 | data += sizeof(statelensub_t); | 1324 | data32[0] = len; |
1328 | *(uint32_t *)data = (DHT_STATE_COOKIE_TYPE << 16) | type; | 1325 | data32[1] = (DHT_STATE_COOKIE_TYPE << 16) | type; |
1329 | data += sizeof(uint32_t); | 1326 | data += sizeof(uint32_t) * 2; |
1330 | return data; | 1327 | return data; |
1331 | } | 1328 | } |
1332 | 1329 | ||
1333 | /* Save the DHT in data where data is an array of size DHT_size(). */ | 1330 | /* Save the DHT in data where data is an array of size DHT_size(). */ |
1334 | void DHT_save(DHT *dht, uint8_t *data) | 1331 | void DHT_save(DHT *dht, uint8_t *data) |
1335 | { | 1332 | { |
1336 | statelensub_t len; | 1333 | uint32_t len; |
1337 | uint16_t type; | 1334 | uint16_t type; |
1338 | *(uint32_t *)data = DHT_STATE_COOKIE_GLOBAL; | 1335 | *(uint32_t *)data = DHT_STATE_COOKIE_GLOBAL; |
1339 | data += sizeof(uint32_t); | 1336 | data += sizeof(uint32_t); |