diff options
author | irungentoo <irungentoo@gmail.com> | 2013-08-18 10:27:03 -0400 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2013-08-18 10:27:03 -0400 |
commit | 88ea4659e98d2ecfab7296e334a6a46b53aeb46e (patch) | |
tree | 98babe952f5fbc0d64476df8cafb6685a4f5c3f2 /core/Messenger.c | |
parent | 558a80f1c38dd4a9099102b5e1f54b7cbd209a33 (diff) |
Properly fixed possible realloc with size zero problem.
Diffstat (limited to 'core/Messenger.c')
-rw-r--r-- | core/Messenger.c | 8 |
1 files changed, 6 insertions, 2 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 */ |
38 | int realloc_friendlist(Messenger *m, uint32_t num) | 38 | int 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; |