[Insight-users] Small bug in Examples/IO/DicomSeriesReadPrintTags.cxx

Kris Thielemans kris.thielemans at csc.mrc.ac.uk
Fri Sep 15 12:29:31 EDT 2006


Hi

There is a small bug in the  Examples/IO/DicomSeriesReadPrintTags.cxx file
in case an tag is not found. Code goes as follows

    std::string entryId = "0010|0010";
    DictionaryType::ConstIterator tagItr = dictionary.Find( entryId );
    if( tagItr == end )
      {
      std::cerr << "Tag " << entryId;
      std::cerr << " not found in the DICOM header" << std::endl;
      }
    MetaDataStringType::ConstPointer entryvalue = 
      dynamic_cast<const MetaDataStringType *>( tagItr->second.GetPointer()
);
    // etc

This crashes if tagItr==end. There is an 'else' missing as in
    if( tagItr == end )
      {
      std::cerr << "Tag " << entryId;
      std::cerr << " not found in the DICOM header" << std::endl;
      }
	else
      {
      MetaDataStringType::ConstPointer entryvalue = 
      dynamic_cast<const MetaDataStringType *>( tagItr->second.GetPointer()
);
      // etc
      }

Ok. This is only an example file, so maybe we don't care. I tend to copy
stuff from the examples though, so had a bug... I'd suggest to at least flag
this up in a comment.

Thanks for all the good work!

Kris Thielemans
Hammersmith Imanet, part of GE Healthcare



More information about the Insight-users mailing list