Skip to content

Commit

Permalink
Fix list malloc(0) bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Diadlo authored and iphydf committed Mar 26, 2017
1 parent f675474 commit c07c61c
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions toxcore/list.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ static int find(const BS_LIST *list, const uint8_t *data)
*/
static int resize(BS_LIST *list, uint32_t new_size)
{
if (new_size == 0) {
bs_list_free(list);
return 1;
}

uint8_t *data = (uint8_t *)realloc(list->data, list->element_size * new_size);

if (!data) {
Expand Down Expand Up @@ -161,7 +166,10 @@ void bs_list_free(BS_LIST *list)
{
//free both arrays
free(list->data);
list->data = NULL;

free(list->ids);
list->ids = NULL;
}

int bs_list_find(const BS_LIST *list, const uint8_t *data)
Expand Down

0 comments on commit c07c61c

Please sign in to comment.