Page MenuHomePhabricator

Potential infinite loop in imagestatistics
Closed, ResolvedPublic

Description

We are currently fixing T4069 in the QmitkImageStatisticsView.cpp and stumbled upon the following code snippet ( lines 302-311 as of revision 23097 )

do
{
  parentObjects = this->GetDefaultDataStorage()->GetSources( selectedNode );
  if ( parentObjects->Size() > 0 )
  {
    // Use first parent object (if multiple parents are present)
    parentNode = parentObjects->ElementAt( 0 );
    parentImage = dynamic_cast< mitk::Image * >( parentNode->GetData() );
  }
} while ( (parentImage == NULL) && (parentObjects->Size() != 0) );

is there a reason for the do while statement? It looks like it was supposed to iterate through the parentObjects, but should the dynamic_cast return a NULL Pointer it seems to enter an infinite loop instead.

Event Timeline

commenting out the whole 'do {} while' loop fixes the T4069. Windows does not enter this block anyways. Removing it does not seem to impair functionality.

If I remember correclty code block is necessary for the case when an image mask (binary image) or planar figure is selected as a CHILD element of a gray value image. Statistics is then computed over the region of the image defined by the mask or planar figure.

Could you check if this is the case?

I agree that the code looks strange, we should rather

  • Get the parent objects
  • Iterate over all parent objects
  • Take the first parent which is an image and use it as parentImage / parentNode

[SVN revision 23805]
FIX (#4120): Fixed check for masking

Merging "applicazion modules" component with "ExtApp plugins"