ModSim: Minor bug fix in assignment 2.7

parent 5e94d2c1
...@@ -10,6 +10,7 @@ q%: q%.o ...@@ -10,6 +10,7 @@ q%: q%.o
%.o: %.c %.o: %.c
$(CC) $(CFLAGS) -o $@ -c $^ $(CC) $(CFLAGS) -o $@ -c $^
.PHONY: clean
clean: clean:
for i in `seq 7`; do \ for i in `seq 7`; do \
rm -vf q$$i; \ rm -vf q$$i; \
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#include <assert.h> #include <assert.h>
typedef struct rabbit { typedef struct rabbit {
int age; unsigned short age;
struct rabbit *prev, *next; struct rabbit *prev, *next;
} rabbit; } rabbit;
...@@ -38,7 +38,7 @@ void rabbit_die(rabbit **ptr) { ...@@ -38,7 +38,7 @@ void rabbit_die(rabbit **ptr) {
r->next->prev = r->prev; r->next->prev = r->prev;
if( r == rabbits ) if( r == rabbits )
rabbits = NULL; rabbits = r->next;
*ptr = NULL; *ptr = NULL;
rabbit_count--; rabbit_count--;
...@@ -69,7 +69,6 @@ void sequence(int generations, int max_age) { ...@@ -69,7 +69,6 @@ void sequence(int generations, int max_age) {
puts(""); puts("");
// This does not free() all rabbits
while( rabbits ) while( rabbits )
rabbit_die(&rabbits); rabbit_die(&rabbits);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment