Bugfix: undefined behaviour in AbstractExternalFunctionNode::prepareForDerivation()
Input and output ranges should not overlap when calling std::set_union(), otherwise the behaviour is undefined. It seems that in this precise case the computation would still be correct (though inefficient), because of the properties of std::set or because of the specific implementation in libstdc++. But it’s better to be on the safe side.master
parent
41052ccb74
commit
fe83933b1d
|
@ -6758,11 +6758,15 @@ AbstractExternalFunctionNode::prepareForDerivation()
|
|||
|
||||
non_null_derivatives = arguments.at(0)->non_null_derivatives;
|
||||
for (int i = 1; i < static_cast<int>(arguments.size()); i++)
|
||||
set_union(non_null_derivatives.begin(),
|
||||
non_null_derivatives.end(),
|
||||
arguments.at(i)->non_null_derivatives.begin(),
|
||||
arguments.at(i)->non_null_derivatives.end(),
|
||||
inserter(non_null_derivatives, non_null_derivatives.begin()));
|
||||
{
|
||||
set<int> non_null_derivatives_tmp;
|
||||
set_union(non_null_derivatives.begin(),
|
||||
non_null_derivatives.end(),
|
||||
arguments.at(i)->non_null_derivatives.begin(),
|
||||
arguments.at(i)->non_null_derivatives.end(),
|
||||
inserter(non_null_derivatives_tmp, non_null_derivatives_tmp.begin()));
|
||||
non_null_derivatives = move(non_null_derivatives_tmp);
|
||||
}
|
||||
|
||||
preparedForDerivation = true;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue