[omniORB] CORBA::string_alloc(len) problem

Douglas Kosovic douglask@dstc.edu.au
Thu, 15 Jul 1999 18:39:40 +1000


Stephen Coy wrote:
> 
> G'Day,
> 
> You said:
> >   String_var myStr = CORBA::string_alloc(100);
> >
> >   myStr[0] = 'a';
> >   myStr[1] = 'b';   // String_var operator[] broken from here
> >   myStr[2] = '\0';

> The CORBA 2.2 spec seems to be a bit vague about allowed uses of
> String_var::operator[], but the Henning/Vinoski book* states that "Attempts
> to index beyond the NUL terminator result in undefined behaviour" on p160.
> 
> Relying on the behaviour provided by adding the memset call above will:
> a) result in non-portable code;
> b) force other users of omniORB to pay the cost of the memset.
> 
> You probably need to do something like:
> 
>     char * myStr = CORBA::string_alloc(100);
>     String_var myStrVar = myStr;
>     myStr[0] = 'a';
>     myStr[1] = 'b';
>     myStr[2] = '\0';

Yep, that make sense.

Thanks,
Doug.