electronicarts / EASTL

EASTL stands for Electronic Arts Standard Template Library. It is an extensive and robust implementation that has an emphasis on high performance.
BSD 3-Clause "New" or "Revised" License
7.82k stars 905 forks source link

Error of RBTreeDecrement function #522

Closed KilluaAoki closed 9 months ago

KilluaAoki commented 9 months ago

The implementation of this function does not account for the scenario where there is only a single node in the tree.

If this single node is passed to the RBTreeDecrement function at this point, according to the normal logic, it should return end(), which is the mAnchor node. But this function still returns the root node.

This could lead to some other errors, resulting in an infinite loop.

The link to the file: red_black_tree.cpp

KilluaAoki commented 9 months ago

Furthermore, there is a mistake in the comment for the RBTreeDecrement function, where it is written as RBTreeIncrement function.

jhopkins-ea commented 9 months ago

You'll have to explain the issue you have further. RBTreeDecrement is an EASTL internal function - it shouldn't be called by users.

If you have a case that is calling RBTreeDecrement when there is no previous elements then it's likely that you are using the container/iterator incorrectly - such as calling decrement on an iterator that is equal to begin(). In such cases EASTL behaviour is undefined. If you meeting the container & iterator requirements and believe there is an issue with rbtree please provide a small reproducible example of the issue.

KilluaAoki commented 9 months ago

ummm...., this is indeed discussing an undefined behavior, I'm very sorry about this and I will close this issues. But it may be avoidable, because there is no predecessor node to the root node of the tree structure, and it is more reasonable to return end() for this.