Skip to content

Commit 103dbcd

Browse files
committed
Fix iterator dereference for null pointer and improve strided_data_end checks
1 parent fcb0855 commit 103dbcd

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

include/xtensor/core/xiterator.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,11 @@ namespace xt
483483
template <class C>
484484
inline auto xstepper<C>::operator*() const -> reference
485485
{
486+
if (m_it == nullptr)
487+
{
488+
static std::remove_reference_t<reference> sentinel{};
489+
return sentinel;
490+
}
486491
return *m_it;
487492
}
488493

include/xtensor/core/xstrides.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,11 @@ namespace xt
171171
It strided_data_end(const C& c, It begin, layout_type l, size_type offset)
172172
{
173173
using difference_type = typename std::iterator_traits<It>::difference_type;
174-
if (c.dimension() == 0 || c.size() == 0)
174+
if (c.size() == 0)
175+
{
176+
return begin;
177+
}
178+
if (c.dimension() == 0)
175179
{
176180
++begin;
177181
}

0 commit comments

Comments
 (0)