summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/Messenger.c8
-rw-r--r--core/net_crypto.c8
2 files changed, 12 insertions, 4 deletions
diff --git a/core/Messenger.c b/core/Messenger.c
index 8a5d9ed4..66ae4f41 100644
--- a/core/Messenger.c
+++ b/core/Messenger.c
@@ -37,11 +37,15 @@ static int write_cryptpacket_id(Messenger *m, int friendnumber, uint8_t packet_i
37 return -1 if realloc fails */ 37 return -1 if realloc fails */
38int realloc_friendlist(Messenger *m, uint32_t num) 38int realloc_friendlist(Messenger *m, uint32_t num)
39{ 39{
40 if (num * sizeof(Friend) == 0) return -1; 40 if (num == 0) {
41 free(m->friendlist);
42 m->friendlist = NULL;
43 return 0;
44 }
41 45
42 Friend *newfriendlist = realloc(m->friendlist, num * sizeof(Friend)); 46 Friend *newfriendlist = realloc(m->friendlist, num * sizeof(Friend));
43 47
44 if (newfriendlist == NULL && num != 0) 48 if (newfriendlist == NULL)
45 return -1; 49 return -1;
46 50
47 m->friendlist = newfriendlist; 51 m->friendlist = newfriendlist;
diff --git a/core/net_crypto.c b/core/net_crypto.c
index 6ced942b..a9af3430 100644
--- a/core/net_crypto.c
+++ b/core/net_crypto.c
@@ -406,11 +406,15 @@ static int getcryptconnection_id(uint8_t *public_key)
406 return -1 if realloc fails */ 406 return -1 if realloc fails */
407int realloc_cryptoconnection(uint32_t num) 407int realloc_cryptoconnection(uint32_t num)
408{ 408{
409 if (num * sizeof(Crypto_Connection) == 0) return -1; 409 if (num == 0) {
410 free(crypto_connections);
411 crypto_connections = NULL;
412 return 0;
413 }
410 414
411 Crypto_Connection *newcrypto_connections = realloc(crypto_connections, num * sizeof(Crypto_Connection)); 415 Crypto_Connection *newcrypto_connections = realloc(crypto_connections, num * sizeof(Crypto_Connection));
412 416
413 if (newcrypto_connections == NULL && num != 0) 417 if (newcrypto_connections == NULL)
414 return -1; 418 return -1;
415 419
416 crypto_connections = newcrypto_connections; 420 crypto_connections = newcrypto_connections;