Skip to content

Commit

Permalink
Fixed a possible memory error. Refs #7506.
Browse files Browse the repository at this point in the history
  • Loading branch information
wdzhou committed Jul 29, 2013
1 parent 5fd0e17 commit 3ab7e48
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion Code/Mantid/Framework/Algorithms/src/FindPeaks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -847,9 +847,24 @@ namespace Algorithms
*/
int getMaxHeightIndex(const MantidVec &Y, const int leftIndex, const int rightIndex)
{
if (leftIndex < 0 || leftIndex >= static_cast<int>(Y.size()))
throw std::runtime_error("Left index out of boundary");

if (rightIndex < 0 || rightIndex > static_cast<int>(Y.size()))
{
std::stringstream errss;
errss << "In getMaxHeightIndex, Size(Y) = " << Y.size() << ", Left Index = " << leftIndex
<< ", Right Index = " << rightIndex;
throw std::runtime_error(errss.str());
}

int right_index = rightIndex;
if (right_index == static_cast<int>(Y.size()))
right_index -= 1;

double maxY = Y[leftIndex];
int indexMax = leftIndex;
for (int i = leftIndex + 1; i < rightIndex; i++)
for (int i = leftIndex + 1; i < right_index; i++)
{
if (Y[i] > maxY)
{
Expand Down

0 comments on commit 3ab7e48

Please sign in to comment.