4 ms·
Quoting from "man tdelete": tdelete() returns a pointer to the parent of the node deleted, or NULL if the item was not found. If the deleted node was the r
by geophile 6y ago
Quoting from "man tdelete": tdelete() returns a pointer to the parent of the node deleted, or NULL if the item was not found. If the deleted node was the root node, tdelete() returns a dangling pointer that must not be accessed.
The quote in TFA is incomplete. The design of tdelete is quite bad, but I would argue that it is not a memory bug. A bug would occur when the caller of tdelete ignores the spec and dereferences the dangling pointer.
- cee-studio 6y agohttps://linux.die.net/man/3/tdelete https://linux.die.net/man/3/tdelete does not have it. My man does not have it. I'm curious what system do you use.
- zokier 6y agolinux.die.net man-pages are crap. See e.g. man7.org for better ones: https://man7.org/linux/man-pages/man3/tdelete.3.html https://man7.org/linux/man-pages/man3/tdelete.3.html See also POSIX spec here: https://pubs.opengroup.org/onlinepubs/9699919799/functions/tdelete.html https://pubs.opengroup.org/onlinepubs/9699919799/functions/t... > The tdelete() function shall return a pointer to the parent of the deleted node, or an unspecified non-null pointer if the deleted node was the root node, or a null pointer if the node is not found. Oh and here is Ubuntu man pages, seeing that they are online and all: https://manpages.ubuntu.com/manpages/focal/en/man3/tdelete.3.html https://manpages.ubuntu.com/manpages/focal/en/man3/tdelete.3... https://manpages.ubuntu.com/manpages/focal/en/man3/tdelete.3posix.html https://manpages.ubuntu.com/manpages/focal/en/man3/tdelete.3...
- cee-studio 6y agoThanks for pointing out the updated man page. This is much better. But the another question is how developers are supposed to know which node is the root node, which is supposed to be opaque.
- geophile 6y agoYou have to know the root of the tree to do anything: void *tsearch(const void *key, void **rootp, int (*compar)(const void *, const void *)); void *tfind(const void *key, void *const *rootp, int (*compar)(const void *, const void *)); ... rootp points to a variable which points to the root of the tree. You can't operate on a tree unless you have a pointer to it, i.e., it's root.
- geophile 6y agoPop OS 20.04, which is derived from Ubuntu 20.04.