mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Properly fixed possible realloc with size zero problem.
This commit is contained in:
parent
558a80f1c3
commit
88ea4659e9
|
@ -37,11 +37,15 @@ static int write_cryptpacket_id(Messenger *m, int friendnumber, uint8_t packet_i
|
|||
return -1 if realloc fails */
|
||||
int realloc_friendlist(Messenger *m, uint32_t num)
|
||||
{
|
||||
if (num * sizeof(Friend) == 0) return -1;
|
||||
if (num == 0) {
|
||||
free(m->friendlist);
|
||||
m->friendlist = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
Friend *newfriendlist = realloc(m->friendlist, num * sizeof(Friend));
|
||||
|
||||
if (newfriendlist == NULL && num != 0)
|
||||
if (newfriendlist == NULL)
|
||||
return -1;
|
||||
|
||||
m->friendlist = newfriendlist;
|
||||
|
|
|
@ -406,11 +406,15 @@ static int getcryptconnection_id(uint8_t *public_key)
|
|||
return -1 if realloc fails */
|
||||
int realloc_cryptoconnection(uint32_t num)
|
||||
{
|
||||
if (num * sizeof(Crypto_Connection) == 0) return -1;
|
||||
if (num == 0) {
|
||||
free(crypto_connections);
|
||||
crypto_connections = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
Crypto_Connection *newcrypto_connections = realloc(crypto_connections, num * sizeof(Crypto_Connection));
|
||||
|
||||
if (newcrypto_connections == NULL && num != 0)
|
||||
if (newcrypto_connections == NULL)
|
||||
return -1;
|
||||
|
||||
crypto_connections = newcrypto_connections;
|
||||
|
|
Loading…
Reference in New Issue
Block a user