linked-list-good-taste icon indicating copy to clipboard operation
linked-list-good-taste copied to clipboard

Clarify undefined behavior if target isn't in the list

Open olawlor opened this issue 4 months ago • 0 comments

If target isn't in the list, find_indirect will walk off the end and dereference NULL.

Example:

list_item item1 = { 3, NULL };
list_item item0 = { 1, &item1 };
list L = {&item0};

list_item itemZ = { 0, NULL };

list_item **it = find_indirect(&L,&itemZ);

Currently both the README and code comments claim this should return a pointer to item1.next, which isn't the case.

This pull clarifies the code comments to reflect the code's actual behavior, and adds a parenthetical in the README about how you could detect and handle the not found case in find_indirect.

olawlor avatar Oct 02 '24 07:10 olawlor