[omniORB] copying strings
Attila.Pletyak@anemo.com
Attila.Pletyak@anemo.com
Mon, 23 Apr 2001 11:12:53 +0200
The difference between the two lines is that the string_dup in the seco=
nd
one dinamically allocates store and gives a char* to the kind member. N=
ow,
in the first line the String_member copies the given char string into
itself, in the second line it simply takes the char* pointer and uses i=
t.
It should work. However when you make length(2) a copying of buffers an=
d
releasing old buffers starts and maybe that is causing a segmentation
fault.
Can't you solve somehow to give const char * as a right value to the ki=
nd
member?
Sincerely,
Attila Pletyak
Anemo Ltd.
=
=20
Joan Ramon L=F3pez Gillu=E9 =
=
=20
<jrlopez@visionadvance.com> To: <omnior=
b-list@uk.research.att.com> =20
Sent by: cc: =
=20
owner-omniorb-list@uk.resear Subject: [o=
mniORB] copying strings =20
ch.att.com =
=20
=
=20
=
=20
04/22/01 03:51 PM =
=20
=
=20
=
=20
Hello everybody,
Please, can anybody tell me what am I doing wrong in thye following
fragment
of code?
The problem is with copyinn nameBuf over (*name)[0].kind. If instead of=
copying nameBuf, I copy a (const char *), as in the previous line,
everything works fine.
#include <omniORB3/CORBA.h>
void main(int argc, char** argv) {
CosNaming::Name* name;
char nameBuf[15]=3D"Hola";
name =3D new CosNaming::Name(0);
name->length(1);
(*name)[0].id =3D (const char*)"id0";
(*name)[0].kind =3D CORBA::string_dup(&(nameBuf[0]));
name->length(2); // it crashes here !!!
etc...
}
Many thanks in advance
Joan Ramon Lopez Gillue
=