Skip to content

Instantly share code, notes, and snippets.

@santileortiz
Last active March 13, 2019 04:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save santileortiz/08724683e74270efd3a5ac22788b694f to your computer and use it in GitHub Desktop.
Save santileortiz/08724683e74270efd3a5ac22788b694f to your computer and use it in GitHub Desktop.
Unexpected behavior of GTree
When using GTree I made the mistake of keeping pointers to keys and overwriting
them. I expected this would only affect the overwritten keys, and make lookups
for them return NULL. What actually happened was that other keys not related to
these became unaccessible. I am puzzled as to why this happened, it may be
interesting to dig inside GTree's implementation and see what's going on.
My guess is doing this breaks the sorted invariant of the tree, then things
will go crazy next time it tries to balance it, maybe for some reason it tries
to fix it by replacing existing keys?. Or, maybe the result of the string
comparison function does not really check for equallity, and instead has an
"else" clause that assumes keys to be sorted, then things compare as equal when
they ar not, causing some existing key to get replaced.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment