Skip to content
This repository was archived by the owner on Aug 11, 2023. It is now read-only.

Commit fbfc410

Browse files
jwlawsonDuncanMcBain
authored andcommitted
Add check so end iterator is not dereferenced (#150)
The current behaviour of `get_node` in the virtual pointer mapper will use `lower_bound` to get the buffer which is not less than the input pointer. If the pointer mapper has only allocated one buffer, and we are looking up a pointer offset into that buffer then the call to `lower_bound` will return an iterator pointing past the end of the map. This means we cannot dereference this iterator, as it does not point into the map, but we still want to decrement this iterator to get the buffer that the virtual pointer is referencing. By adding a check for whether the iterator is the end we can short circuit the iterator dereference, and so avoid this problem without otherwise changing the behaviour of the pointer mapper.
1 parent 654cf66 commit fbfc410

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

include/vptr/virtual_ptr.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ class PointerMapper {
219219
auto node = m_pointerMap.lower_bound(ptr);
220220
// If the value of the pointer is not the one of the node
221221
// then we return the previous one
222-
if (node->first != ptr) {
222+
if (node == m_pointerMap.end() || node->first != ptr) {
223223
if (node == std::begin(m_pointerMap)) {
224224
throw std::out_of_range("The pointer is not registered in the map");
225225
}

0 commit comments

Comments
 (0)