list icon indicating copy to clipboard operation
list copied to clipboard

list_remove should check node to NULL

Open LuisCRSousa opened this issue 4 years ago • 3 comments

Because if I use list_remove(list, list_find(list, item)) it will break because list_find could return NULL

LuisCRSousa avatar Mar 23 '20 23:03 LuisCRSousa

Currently we expect you to check the return value of list_find:

list_node_t *thing = list_find(list, "value");
if (thing != NULL) {
  list_remove(list, thing);
}

I think this is a reasonable thing to do. What is the use case for not checking the return value yourself?

stephenmathieson avatar Mar 24 '20 15:03 stephenmathieson

A lib should be bullet proof and check for this kind of edge cases that's all. I just wanted to do it in one line of code, there's no need to repeat the same code over and over again.

Thanks :)

LuisCRSousa avatar Mar 27 '20 22:03 LuisCRSousa

Feel free to open a PR :)

stephenmathieson avatar Mar 27 '20 23:03 stephenmathieson