Skip to content

Conversation

@belyshevdenis
Copy link
Collaborator

I've removed removeByObject method because it can delete wrong object using the view of a node that doesn't exists. For example, if you try to remove object with non-existing value 60, it constructs the node with key 2 (that equals to value 20) and deletes it.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds comprehensive test coverage for the TreeMap class and removes a potentially unsafe removeByObject method that could delete incorrect objects due to faulty node construction logic.

  • Adds extensive BDD-style test cases covering all TreeMap methods and edge cases
  • Removes the problematic removeByObject method to prevent incorrect object deletion
  • Suppresses a deprecated API warning in the GenericTableAvl allocation routine

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
test/TreeMapTest.cpp New comprehensive test file covering TreeMap functionality with BDD-style scenarios
test/CMakeLists.txt Adds TreeMapTest.cpp to the build configuration
include/kf/TreeMap.h Removes the unsafe removeByObject method
include/kf/GenericTableAvl.h Suppresses deprecation warning for ExAllocatePoolWithTag

@belyshevdenis
Copy link
Collaborator Author

I've removed removeByObject method because it can delete wrong object using the view of a node that doesn't exists. For example, if you try to remove object with non-existing value 60, it constructs the node with key 2 (that equals to value 20) and deletes it.

@SergiusTheBest I've encountered the same problem in tests for LinkedTreeMap: the remove method uses CONTAINING_RECORD, that creates a view for a not existed node and it leads to memory access violation. So, the usage of CONTAINING_RECORD is not safe for not existant values.

@SergiusTheBest
Copy link
Member

I've removed removeByObject method because it can delete wrong object using the view of a node that doesn't exists. For example, if you try to remove object with non-existing value 60, it constructs the node with key 2 (that equals to value 20) and deletes it.

@belyshevdenis But we use that method, so we need it.

@SergiusTheBest
Copy link
Member

I've removed removeByObject method because it can delete wrong object using the view of a node that doesn't exists. For example, if you try to remove object with non-existing value 60, it constructs the node with key 2 (that equals to value 20) and deletes it.

@SergiusTheBest I've encountered the same problem in tests for LinkedTreeMap: the remove method uses CONTAINING_RECORD, that creates a view for a not existed node and it leads to memory access violation. So, the usage of CONTAINING_RECORD is not safe for not existant values.

Oh, I see! removeByObject accepts an object that is in the map. If the object is not in the map then it's undefined behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants