Skip to content

Commit

Permalink
BUG: Guarantee array contains enough elements for access in loop
Browse files Browse the repository at this point in the history
Guarantee array contains enough elements for access in loop.
Specifically, the array must contain at least two elements so that the
sorting can take place.
  • Loading branch information
jhlegarreta authored and dzenanz committed Jan 12, 2022
1 parent 4804adc commit 90f7396
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ ThresholdLabelerImageFilter<TInputImage, TOutputImage>::BeforeThreadedGenerateDa
{
auto size = static_cast<unsigned int>(m_Thresholds.size());

for (unsigned int i = 0; i < size - 1; ++i)
for (unsigned int i = 1; i < size; ++i)
{
if (m_Thresholds[i] > m_Thresholds[i + 1])
if (m_Thresholds[i - 1] > m_Thresholds[i])
{
itkExceptionMacro(<< "Thresholds must be sorted.");
}
Expand Down

0 comments on commit 90f7396

Please sign in to comment.