Skip to content

Commit 26e9c7e

Browse files
committed
Add a bounds check and negative slice support to strided view fill_args
1 parent 2be98b4 commit 26e9c7e

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

include/xtensor/views/xstrided_view_base.hpp

+8
Original file line numberDiff line numberDiff line change
@@ -903,6 +903,14 @@ namespace xt
903903
if (ptr != nullptr)
904904
{
905905
auto slice0 = static_cast<old_strides_value_type>(*ptr);
906+
if (slice0 < 0)
907+
{
908+
slice0 += shape[i_ax];
909+
}
910+
if (slice0 < 0 || slice0 >= shape[i_ax])
911+
{
912+
XTENSOR_THROW(std::runtime_error, "Slice index out of range.");
913+
}
906914
new_offset += static_cast<std::size_t>(slice0 * old_strides[i_ax]);
907915
}
908916
else if (std::get_if<xt::xnewaxis_tag>(&slices[i]) != nullptr)

0 commit comments

Comments
 (0)