[omniORB] copying strings
   
    Joan Ramon López Gillué
     
    jrlopez@visionadvance.com
       
    Mon, 23 Apr 2001 11:26:29 +0200
    
    
  
Attila,
I thought it should work as it was, but it did not. You are right, it
crashes when it releases the old buffer. By now, the only workaround I've
found is casting the variable to a (const char*) and not usig string_dup.
	(*name)[0].kind = (const char*) nameBuf;
It seems to work fine this way.
Thanks a lot
Joan Ramon Lopez
Vision Advance.SL
Barcelona (Spain)
-----Original Message-----
From: Attila.Pletyak@anemo.com [mailto:Attila.Pletyak@anemo.com]
Sent: lunes, 23 de abril de 2001 11:13
To: Joan Ramon López Gillué
Cc: omniorb-list@uk.research.att.com
Subject: Re: [omniORB] copying strings
The difference between the two lines is that the string_dup in the second
one dinamically allocates store and gives a char* to the kind member. Now,
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 it.
It should work. However when you make length(2) a copying of buffers and
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 kind
member?
Sincerely,
Attila Pletyak
Anemo Ltd.
                    Joan Ramon López Gillué
                    <jrlopez@visionadvance.com>         To:
<omniorb-list@uk.research.att.com>
                    Sent by:                            cc:
                    owner-omniorb-list@uk.resear        Subject:
[omniORB] copying strings
                    ch.att.com
                    04/22/01 03:51 PM
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]="Hola";
           name = new CosNaming::Name(0);
           name->length(1);
           (*name)[0].id = (const char*)"id0";
           (*name)[0].kind = CORBA::string_dup(&(nameBuf[0]));
           name->length(2);                    // it crashes here !!!
           etc...
}
Many thanks in advance
Joan Ramon Lopez Gillue