Просмотр исходного кода

table: check pos when invoking operator[]

Michele Caini 2 лет назад
Родитель
Сommit
a3cea32f93
1 измененных файлов с 2 добавлено и 0 удалено
  1. 2 0
      src/entt/entity/table.hpp

+ 2 - 0
src/entt/entity/table.hpp

@@ -397,11 +397,13 @@ public:
      * @return The row data at specified location.
      */
     [[nodiscard]] std::tuple<const Row &...> operator[](const size_type pos) const {
+        ENTT_ASSERT(pos < size(), "Index out of bounds");
         return std::forward_as_tuple(std::get<container_for<Row>>(payload.first())[pos]...);
     }
 
     /*! @copydoc operator[] */
     [[nodiscard]] std::tuple<Row &...> operator[](const size_type pos) {
+        ENTT_ASSERT(pos < size(), "Index out of bounds");
         return std::forward_as_tuple(std::get<container_for<Row>>(payload.first())[pos]...);
     }