Skip to content

Commit 7d46956

Browse files
committed
try
1 parent 0e114a0 commit 7d46956

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

include/xtensor/core/xassign.hpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,14 @@ namespace xt
601601
size_type size = e2.dimension();
602602
index_type shape = uninitialized_shape<index_type>(size);
603603
bool trivial_broadcast = e2.broadcast_shape(shape, true);
604-
e1.resize(std::move(shape));
604+
// Safety check: limit resize to shape size
605+
if (shape.size() > e1.shape().size()) {
606+
index_type safe_shape;
607+
std::copy_n(shape.begin(), e1.shape().size(), safe_shape.begin());
608+
e1.resize(std::move(safe_shape));
609+
} else {
610+
e1.resize(std::move(shape));
611+
}
605612
return trivial_broadcast;
606613
}
607614
}

include/xtensor/views/xstrided_view_base.hpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -654,8 +654,13 @@ namespace xt
654654
template <class O>
655655
inline bool xstrided_view_base<D>::has_linear_assign(const O& str) const noexcept
656656
{
657-
return has_data_interface<xexpression_type>::value && str.size() == strides().size()
658-
&& std::equal(str.cbegin(), str.cend(), strides().begin());
657+
if (!has_data_interface<xexpression_type>::value)
658+
return false;
659+
if (str.size() == 0 || strides().size() == 0)
660+
return false;
661+
if (str.size() != strides().size())
662+
return false;
663+
return std::equal(str.cbegin(), str.cend(), strides().begin());
659664
}
660665

661666
//@}

0 commit comments

Comments
 (0)