[Insight-developers] TransformFileReader endless loop

Tomáš Kazmar Tomash.Kazmar at seznam.cz
Mon Feb 18 08:54:33 EST 2008


Hi all,

  I think there is a bug in itkTransformFileReader which causes an endless
loop when the input file does not end with an empty new line. A value returned
from a call to std::string::find() should be checked properly for std::string::npos,
there should be something like the following:

  while ( position < data.size() )
    {
    // Find the next string
    std::string::size_type end = data.find ( "\n", position );
    if (end == std::string::npos) {
            end = data.size()-1;
    }
    std::string line = trim ( data.substr ( position, end - position ) );
    position = end+1;
 
patch:
114a115,117
>     if (end == std::string::npos) {
>           end = data.size()-1;
>     }

Another option is to add newline at the end of the buffer before the loop starts.

Regards,
Tomas


More information about the Insight-developers mailing list