diff --git a/include/clad/Differentiator/Array.h b/include/clad/Differentiator/Array.h index bceab2656..85ce60c5f 100644 --- a/include/clad/Differentiator/Array.h +++ b/include/clad/Differentiator/Array.h @@ -98,8 +98,11 @@ template class array { delete[] m_arr; // NOLINTNEXTLINE(cppcoreguidelines-owning-memory) m_arr = new T[arr.m_size]; - m_size = arr.m_size; } + // Adopt the source size before delegating to operator=(T*): otherwise a + // larger destination keeps its old m_size and that overload reads + // arr.m_arr past its end (heap over-read on shrinking assignment). + m_size = arr.m_size; (*this) = arr.m_arr; return *this; } diff --git a/test/Jacobian/Jacobian.C b/test/Jacobian/Jacobian.C index 7c82210c1..1a62d11dc 100644 --- a/test/Jacobian/Jacobian.C +++ b/test/Jacobian/Jacobian.C @@ -1,7 +1,5 @@ // RUN: %cladclang %s -I%S/../../include -oJacobian.out 2>&1 | %filecheck %s // RUN: ./Jacobian.out | %filecheck_exec %s -// FIXME: real clad::array copy-assignment over-read; drop when the fix lands. -// XFAIL: valgrind #include "clad/Differentiator/Differentiator.h" #include diff --git a/test/Jacobian/testUtility.C b/test/Jacobian/testUtility.C index 68567043b..0cf749114 100644 --- a/test/Jacobian/testUtility.C +++ b/test/Jacobian/testUtility.C @@ -1,7 +1,5 @@ // RUN: %cladclang %s -I%S/../../include -otestUtility.out 2>&1 | %filecheck %s // RUN: ./testUtility.out | %filecheck_exec %s -// FIXME: real clad::array copy-assignment over-read; drop when the fix lands. -// XFAIL: valgrind #include "clad/Differentiator/Differentiator.h"