mirror of
https://github.com/microsoft/GSL.git
synced 2024-11-03 17:56:43 -05:00
Fix negative indices to multi_span not being caught.
Negative indices to multi_span are not flagged with neither exception nor abort.
This commit is contained in:
commit
75fb2236ed
@ -443,7 +443,7 @@ namespace details
|
|||||||
template <typename T, size_t Dim = 0>
|
template <typename T, size_t Dim = 0>
|
||||||
size_type linearize(const T& arr) const
|
size_type linearize(const T& arr) const
|
||||||
{
|
{
|
||||||
Expects(arr[Dim] < CurrentRange); // Index is out of range
|
Expects(arr[Dim] >= 0 && arr[Dim] < CurrentRange); // Index is out of range
|
||||||
return this->Base::totalSize() * arr[Dim] +
|
return this->Base::totalSize() * arr[Dim] +
|
||||||
this->Base::template linearize<T, Dim + 1>(arr);
|
this->Base::template linearize<T, Dim + 1>(arr);
|
||||||
}
|
}
|
||||||
@ -1510,7 +1510,7 @@ public:
|
|||||||
template <bool Enabled = (Rank > 1), typename Ret = std::enable_if_t<Enabled, sliced_type>>
|
template <bool Enabled = (Rank > 1), typename Ret = std::enable_if_t<Enabled, sliced_type>>
|
||||||
constexpr Ret operator[](size_type idx) const noexcept
|
constexpr Ret operator[](size_type idx) const noexcept
|
||||||
{
|
{
|
||||||
Expects(idx < bounds_.size()); // index is out of bounds of the array
|
Expects(idx >= 0 && idx < bounds_.size()); // index is out of bounds of the array
|
||||||
const size_type ridx = idx * bounds_.stride();
|
const size_type ridx = idx * bounds_.stride();
|
||||||
|
|
||||||
// index is out of bounds of the underlying data
|
// index is out of bounds of the underlying data
|
||||||
|
@ -1084,6 +1084,12 @@ SUITE(multi_span_tests)
|
|||||||
|
|
||||||
CHECK_THROW(av[10][2], fail_fast);
|
CHECK_THROW(av[10][2], fail_fast);
|
||||||
CHECK_THROW((av[{10, 2}]), fail_fast);
|
CHECK_THROW((av[{10, 2}]), fail_fast);
|
||||||
|
|
||||||
|
CHECK_THROW(av[-1][0], fail_fast);
|
||||||
|
CHECK_THROW((av[{-1, 0}]), fail_fast);
|
||||||
|
|
||||||
|
CHECK_THROW(av[0][-1], fail_fast);
|
||||||
|
CHECK_THROW((av[{0, -1}]), fail_fast);
|
||||||
}
|
}
|
||||||
|
|
||||||
void overloaded_func(multi_span<const int, dynamic_range, 3, 5> exp, int expected_value)
|
void overloaded_func(multi_span<const int, dynamic_range, 3, 5> exp, int expected_value)
|
||||||
|
Loading…
Reference in New Issue
Block a user