[omniORB] CORBA::string_alloc(len) problem
Douglas Kosovic
douglask@dstc.edu.au
Thu, 15 Jul 1999 15:30:39 +1000
Hi,
I want to describe a problem with OmniORB's string_alloc() when used in
combination with the String_var's index operator (i.e operator[] ) and a
simple fix for the string_alloc() implementation which will reduce the
number of problems.
Say we have the following code:
String_var myStr = CORBA::string_alloc(100);
myStr[0] = 'a';
myStr[1] = 'b'; // String_var operator[] broken from here
myStr[2] = '\0';
The operator[] is potentially broken from the second assignment because
in its implementation, it tries to do a strlen on a temporarily non-null
terminated string that contains uninitialised characters ...
Anyway, the fix I suggest for the CORBA::string_alloc(len)
implementation is instead of zeroing just the first char, zero the
entire allocated block, e.g.:
memset(s, 0, (len + 1) * sizeof(char))
Thanks,
Doug.