From 6d0d8d2a04b3509d589cb18bf632278ce113cd77 Mon Sep 17 00:00:00 2001 From: flizzywine <1041958497@qq.com> Date: Mon, 2 Apr 2018 13:12:48 +0800 Subject: [PATCH] fix a list infinite loop bug 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. --- C10-Elementary-Data-Structures/exercise_code/af-obj.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/C10-Elementary-Data-Structures/exercise_code/af-obj.c b/C10-Elementary-Data-Structures/exercise_code/af-obj.c index 9bb7f4fb..2047f0f7 100644 --- a/C10-Elementary-Data-Structures/exercise_code/af-obj.c +++ b/C10-Elementary-Data-Structures/exercise_code/af-obj.c @@ -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; }