Re: strint <--> octect problem



Hi Samuele,

On Sun, 9 Dec 2001, Samuele Gallazzi wrote:
> I've a problem with strings: I have to cast them to octect sequence
> and throw the obtained sequence; at the end I re-cast to string to
> view the output.

        Sounds nasty - but OK if you don't have UTF-8 strings - I would
strongly suggest using Gnome 2.0 and clean UTF-8 throught.

> I noticed that with some kind of strings all works really fine, with
> some other (longer or with a lot of white spaces strings) the software
> gives an error of segmentation fault and the output isn't correct.

        Extremely strange.

> Why does this happen?

        Well - there could be several reasons.

> I believe the octect thowing part is correct because of the success
> with lot of input, so the error could be in the casting...

        Hmm - this depends on the lifecycle of your strings.

> My code is something like that:
>
>   char* message ="Bla bla bla 123456789012XXX";
>   char* msgstring;
>   DispatcherDataQueue_mem * msg;     /* Sequence of octet */
>
>   //Insert the strings in the octet sequences
>    msg = DispatcherDataQueue_mem__alloc();
>    msg->_length = strlen(message)+1;
>    msg->_maximum = msg->_length;
>    msg->_buffer = CORBA_sequence_CORBA_octet_allocbuf(msg->_length);
>    for (i=0; i<msg->_length ; i++)
>          msg->_buffer[i] = (CORBA_octet) message[i];

        This code is fine; apart from the C++ comment :-)
>       ...<snip>...
>
>       // WHEN I RECEIVE THE OCTECT BACK, I OUTPUT IN THIS WAY:
>     printf("The message read length is %i\n", msg->_length);
>     printf("The message read is %s.\n",(char*)msg->_buffer);
>     msg->_release=CORBA_TRUE;
>     CORBA_free(msg3);

        Why do you do msg->_release ? client code should _Never_ be
touching _release. Only server code should do that [ and incidentaly you
should be setting release to TRUE on the server side ].

> Where is my horrible error??

        Hard to say; you copy the terminating NULL correctly; there should
be no error. Can you post the code to both ends on some web server were I
can poke at it ( not to the list ).

        Regards,

                Michael.

-- 
 mmeeks@gnu.org  <><, Pseudo Engineer, itinerant idiot




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]