From 474cce002acbe20c7d598496338bf7bd3b1a6999 Mon Sep 17 00:00:00 2001 From: Jacob Merson Date: Sat, 27 Jul 2024 18:43:25 -0700 Subject: [PATCH] Update apfElement.cc This commit fixes #440 which will now work with any number of components. --- apf/apfElement.cc | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/apf/apfElement.cc b/apf/apfElement.cc index 161de8df1..534e6a35c 100644 --- a/apf/apfElement.cc +++ b/apf/apfElement.cc @@ -121,9 +121,12 @@ void Element::getNodeData() void Element::getElementNodeData(NewArray& d) { - d.allocated() ? d.resize(nen) : d.allocate(nen); - for (int i = 0; i < nen; i++) - d[i] = nodeData[i]; + d.resize(nodeData.size()); + // to get the iterator 1 past the end without indexing one past the + // end we get the address to the last element then do ptr arithmetic + // to get one past that. Indexing at nodeData.size() can lead to segfault + // as you are actually accessing that memory. + std::copy(&nodeData[0], (&nodeData[nodeData.size()-1])+1, &d[0]); } }//namespace apf