[omniORB] CORBA::String operator = (char *)

Bjoern Wennberg bjornw@fairplay.no
Wed, 29 Jul 1998 12:55:40 +0000


Liutger Franzen wrote:

> Is it correct, that the operator = of CORBA::String differs when using a
> (char *) compared to a (const char *)? I checked the source and found
> that in the 1st case, the string is not copied. This is a bit annoying
> when using stuff like:
>
>         CORBA::String str;
>         str = "foo";
>
> In this case the "foo" is a (char *) (could not believe this 1st, but I
> checked it with several compilers incl. g++) and you get into trouble if
> you don't change it to:
>
>         str = (const char *) "foo";

It will call operator char * since 'str' is not a const object and you must
assume that the'str' object will change the "foo" expression. If 'str' was
a const object - the operator const char *
could be called.

>
>
> because CORBA::String will coredump when deleting "foo" ... any
> suggestions? Or is this just my mistake?
>
> --
> Lio

I exeperinced the exact same thing - my app core-dumped in the destructors
of a CORBA::String.
IMO I find it to be a bug that char * and const char * differs. The problem
is that the
operator = (char *s) initializes a mere pointer to the right-hand-side and
during the destructor
it tries to delete that pointer - clearly an error.
operator = (const char *s) duplicates the right-hand-side and correctly
frees it during the destructor.

bjornw>


--
-------------------------------------------------------
Bjorn Wennberg              email: bjornw@fairplay.no
                               ms: +47 950 82 657
Senior Programmer           phone: +47 22405538
FairPlay International AS     fax: +47 22405539