[omniORB] omniORB.CORBA.BAD_PARAM

baileyk@slxi.com baileyk@slxi.com
Thu, 15 Nov 2001 07:56:16 -0600


>> Unfortunately, that's not an option for me.  In C++, I can do:
>>
>>   Test::Bar b;
>>   std::strncpy(b.str, "testing", sizeof(b.str));
>>   b.str[sizeof(b.str)-1] = '\0';

>You do realise that this copies a couple of bytes of arbitrary memory
>into the str field... Whatever followed the "testing" string.

A minor point, but that's not the way I read it.  Here's an excerpt from a
man page

  strcpy(), strncpy(), strlcpy()
     The strcpy() function copies string s2 to s1, including  the
     terminating  null character, stopping after the null charac-
     ter has been copied. The strncpy() function copies exactly n
     bytes,  truncating  s2  or  adding  null characters to s1 if
     necessary. The result will not  be  null-terminated  if  the
     length of s2 is n or more.  Each function returns s1.

This tells me that when the null following "testing" is seen, no more
'copying' is done, and
the rest of b.str is filled will null characters.  I've depended on such
behavior many times. If
he had used memcpy, you would be correct.

Kendall