linked-list-good-taste
linked-list-good-taste copied to clipboard
Clarify undefined behavior if target isn't in the list
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.