I have a doubly linked list, that I am working on function to clear the list, but it winds up in an infinite loop because the head pointer is supposed to be NULL when the list is empty, but it doesn't evaluate as such.
I'm pretty confident that the list is set up correctly with all pointers intact. However, somehow when the last node is deleted, the while loop doesn't terminate, and the loop goes into perpuity.
Can anyone see why I'm not getting a NULL value on this?
That was it. I didn't see that when clearing the list, of course head_ptr eventually becomes NULL (that's the point of clearing the list), which makes line 17 crash the program. I just had to wrap line 17 in if (head_ptr != NULL) and the problem goes away.