Browse Source

dense_hash_map/dense_hash_set: avoid pointer overflow for end iterators (close #804)

Michele Caini 4 years ago
parent
commit
4b3108283f
2 changed files with 8 additions and 2 deletions
  1. 4 1
      src/entt/container/dense_hash_map.hpp
  2. 4 1
      src/entt/container/dense_hash_set.hpp

+ 4 - 1
src/entt/container/dense_hash_map.hpp

@@ -198,6 +198,9 @@ public:
         return (it + curr);
         return (it + curr);
     }
     }
 
 
+    template<typename ILhs, typename IRhs>
+    [[nodiscard]] friend bool operator==(const dense_hash_map_local_iterator<ILhs> &, const dense_hash_map_local_iterator<IRhs> &) ENTT_NOEXCEPT;
+
 private:
 private:
     iterator_type it;
     iterator_type it;
     std::size_t curr;
     std::size_t curr;
@@ -205,7 +208,7 @@ private:
 
 
 template<typename ILhs, typename IRhs>
 template<typename ILhs, typename IRhs>
 [[nodiscard]] bool operator==(const dense_hash_map_local_iterator<ILhs> &lhs, const dense_hash_map_local_iterator<IRhs> &rhs) ENTT_NOEXCEPT {
 [[nodiscard]] bool operator==(const dense_hash_map_local_iterator<ILhs> &lhs, const dense_hash_map_local_iterator<IRhs> &rhs) ENTT_NOEXCEPT {
-    return lhs.base() == rhs.base();
+    return lhs.curr == rhs.curr;
 }
 }
 
 
 template<typename ILhs, typename IRhs>
 template<typename ILhs, typename IRhs>

+ 4 - 1
src/entt/container/dense_hash_set.hpp

@@ -198,6 +198,9 @@ public:
         return (it + curr);
         return (it + curr);
     }
     }
 
 
+    template<typename ILhs, typename IRhs>
+    [[nodiscard]] friend bool operator==(const dense_hash_set_local_iterator<ILhs> &, const dense_hash_set_local_iterator<IRhs> &) ENTT_NOEXCEPT;
+
 private:
 private:
     iterator_type it;
     iterator_type it;
     std::size_t curr;
     std::size_t curr;
@@ -205,7 +208,7 @@ private:
 
 
 template<typename ILhs, typename IRhs>
 template<typename ILhs, typename IRhs>
 [[nodiscard]] bool operator==(const dense_hash_set_local_iterator<ILhs> &lhs, const dense_hash_set_local_iterator<IRhs> &rhs) ENTT_NOEXCEPT {
 [[nodiscard]] bool operator==(const dense_hash_set_local_iterator<ILhs> &lhs, const dense_hash_set_local_iterator<IRhs> &rhs) ENTT_NOEXCEPT {
-    return lhs.base() == rhs.base();
+    return lhs.curr == rhs.curr;
 }
 }
 
 
 template<typename ILhs, typename IRhs>
 template<typename ILhs, typename IRhs>