[Insight-users] strncpy problem in itkAnalyzeImageIO.cxx

Jill Goldschneider 327 jrgold at insightful.com
Thu Jun 17 18:19:44 EDT 2004


Hi,

I have been having some problems writing Analyze (SPM extension I
believe) formatted images where origin information is stored in
the data_history's char originator[10] field.  (I believe this
field was originally intended to hold a character string.)
If I use the ImageReadWrite example with Dimension = 3, e.g.
  ImageReadWrite image.hdr tmp.hdr
tmp.hdr loses all of the information in the originator field,
(and other fields as well).

What I've found, is that on a sun solaris8 system, strncpy is
actually NOT copying all 10 requested characters:

    // try using [ 0 128 0 128 0 64 0 0 0 0 ] in tmp.c_str()

    strncpy(this->m_hdr.hist.originator,temp.c_str(),10);//Note this is necessary because the array is not necessarily null terminated.

    // look at contents of m_hdr.hist and temp.c_str,
    // m_hdr.hist.originator is all 0!

If I change this statement, and all other strncpy statements
in the itkAnalyzeImageIO.cxx file, to use memcpy

    memcpy(this->m_hdr.hist.originator,temp.c_str(),10);//Note this is necessary because the array is not necessarily null terminated.

then everything works much better.

Would someone please consider making this change?

Thanks,

Jill



More information about the Insight-users mailing list