diff --git a/include/xtensor/xstrided_view_base.hpp b/include/xtensor/xstrided_view_base.hpp index 9f3f8ef4c..b4b26e01c 100644 --- a/include/xtensor/xstrided_view_base.hpp +++ b/include/xtensor/xstrided_view_base.hpp @@ -903,6 +903,14 @@ namespace xt if (ptr != nullptr) { auto slice0 = static_cast(*ptr); + if (slice0 < 0) + { + slice0 += shape[i_ax]; + } + if (slice0 < 0 || slice0 >= shape[i_ax]) + { + XTENSOR_THROW(std::runtime_error, "Slice index out of range."); + } new_offset += static_cast(slice0 * old_strides[i_ax]); } else if (xtl::get_if(&slices[i]) != nullptr)