Skip to content

Commit

Permalink
fix a list infinite loop bug
Browse files Browse the repository at this point in the history
imagine such code:
list_t ls1 = alloc_object(1);
cons(2, ls1);
these code will make an infinite loop, because NEXT(NEXT(ls1) ) == ls.
to avoid this bug, fix the alloc_object() function, add some statements.
  • Loading branch information
flizzywine authored Apr 2, 2018
1 parent 4aa54f0 commit 6d0d8d2
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions C10-Elementary-Data-Structures/exercise_code/af-obj.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ list_t allocate_object() {

list_t new = free_list;
free_list = NEXT(free_list);
NEXT(new_obj) = empty_list;
PREV(new_obj) = empty_list;
return new;
}

Expand Down

0 comments on commit 6d0d8d2

Please sign in to comment.