Skip to content

Commit

Permalink
Fix memory read error in MDHistoWorkspaceIterator & test
Browse files Browse the repository at this point in the history
The skipping policy was being applied even if the iterator had
reached the last element causing the skipping policy check to
access an array out of bounds.
Refs #11512
  • Loading branch information
martyngigg committed Apr 13, 2015
1 parent 34ada20 commit 1ca499b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
Expand Up @@ -237,12 +237,14 @@ bool MDHistoWorkspaceIterator::next() {
} else {
++m_pos;
}
// Keep calling next if the current position is masked.
bool ret = m_pos < m_max;
while (m_skippingPolicy->keepGoing()) {
ret = this->next();
if (!ret)
break;
if(ret) {
// Keep calling next if the current position is masked and still valid.
while (m_skippingPolicy->keepGoing()) {
ret = this->next();
if (!ret)
break;
}
}
// Go through every point;
return ret;
Expand Down
Expand Up @@ -8,14 +8,14 @@
#include "MantidDataObjects/MDHistoWorkspaceIterator.h"
#include "MantidTestHelpers/MDEventsTestHelper.h"
#include <cxxtest/TestSuite.h>
#include <iomanip>
#include <iostream>
#include "MantidKernel/VMD.h"
#include "MantidGeometry/MDGeometry/MDImplicitFunction.h"
#include "MantidGeometry/MDGeometry/MDPlane.h"
#include <boost/assign/list_of.hpp>
#include <boost/function.hpp>
#include <boost/bind.hpp>
#include <boost/scoped_ptr.hpp>


using namespace Mantid;
using namespace Mantid::DataObjects;
Expand Down Expand Up @@ -67,9 +67,10 @@ class MDHistoWorkspaceIteratorTest: public CxxTest::TestSuite
void do_test_iterator(size_t nd, size_t numPoints)
{
MDHistoWorkspace_sptr ws = MDEventsTestHelper::makeFakeMDHistoWorkspace(1.0, nd, 10);
for (size_t i = 0; i < numPoints; i++)
for (size_t i = 0; i < numPoints; i++) {
ws->setSignalAt(i, double(i));
MDHistoWorkspaceIterator * it = new MDHistoWorkspaceIterator(ws);
}
boost::scoped_ptr<MDHistoWorkspaceIterator> it(new MDHistoWorkspaceIterator(ws));
TSM_ASSERT( "This iterator is valid at the start.", it->valid());
size_t i = 0;

Expand All @@ -90,10 +91,10 @@ class MDHistoWorkspaceIteratorTest: public CxxTest::TestSuite
{
TS_ASSERT_DELTA( it->getNormalizedSignal(), double(i) / 1.0, 1e-5);
TS_ASSERT_DELTA( it->getNormalizedError(), 1.0, 1e-5);
coord_t * vertexes;
size_t numVertices;
vertexes = it->getVertexesArray(numVertices);
TS_ASSERT( vertexes);
coord_t *vertexes = it->getVertexesArray(numVertices);
TS_ASSERT(vertexes);
delete [] vertexes;
TS_ASSERT_EQUALS( it->getNumEvents(), 1);
TS_ASSERT_EQUALS( it->getInnerDetectorID(0), 0);
TS_ASSERT_EQUALS( it->getInnerRunIndex(0), 0);
Expand Down

0 comments on commit 1ca499b

Please sign in to comment.