Truncated strings with NXgetattr...

Brian Tieman tieman at aps.anl.gov
Fri Apr 17 20:12:44 BST 1998


Hi,

I downloaded the newest version of Nexus from home page (napi.c,v 1.7
1998/04/08 06:43:42 nexus Exp) and am having a problem reading string
attributes.

The problem I'm having is this, any string returned by NXgetattr is
truncated by one character.  the code I'm using is essentially the
following:

NXgetnextattr (exp_file_handle, attr_name, &length, &data_type)
//check if attrib is "Nexus Version"
if (!(strcmp (attr_name, "Nexus Version")))
{
   nexus_version = (char *) malloc(length*sizeof(char));
   NXgetattr (exp_file_handle, attr_name, nexus_version, &length,
&data_type)
}

If I examine length before NXgetattr, it is 3.  After calling NXgetattr,
it is only 2.  And the returned string is truncated by one character
from expected.

I poked around in NXgetattr and made the following change:

*datalen = (*datalen) * DFKNTsize(*iType);

to

if (*iType == DFNT_CHAR8 || *iType == DFNT_UCHAR8)
  *datalen = (*datalen + 1) * DFKNTsize(*iType);
else
  *datalen = (*datalen) * DFKNTsize(*iType);

which seams to have fixed the problem quit nicely.  Is anyone else
having this problem and did I do the right thing to fix it?

Thanks!

Brian Tieman
SRICAT--APS




More information about the NeXus mailing list