dangling reference in diagmat()
@rcurtin In the file include/bandicoot_bits/fn_diagmat.hpp
, the last diagmat()
overload creates a dangling reference as detailed below. The Op object will then effectively point to memory that can be overwritten at any time.
template<typename T1>
coot_warn_unused
inline
typename
enable_if2
<
is_coot_type<T1>::value,
const Op<eOp<T1, eop_scalar_times>, op_diagmat2>
>::result
diagmat(const Op<T1, op_htrans2>& X, const sword k)
{
coot_extra_debug_sigprint();
const uword a = (std::abs)(k);
const uword b = (k < 0) ? 3 : 2;
eOp<T1, eop_scalar_times> inner(X.m, X.aux); // BUG: 'inner' is destroyed when the function finishes; Op then holds a dangling ref
return Op<eOp<T1, eop_scalar_times>, op_diagmat2>(inner, a, b);
}
Edited by conradsnicta