what will happen while don't dynamic alloc space for out parameter?

what will happen while don't dynamic alloc space for out parameter?

Post by Cai Wenlian » Tue, 15 Jul 2003 10:23:47



Hi, all
    I made a mistake in my program that I directly use "strcpy" give the
string-type-out parameter instead dynamic allocing space for this parameter
. now the program is running on server. I want to know if this codes would
cause fatal error . anyone can tell me ? thank you !

William Cai

 
 
 

what will happen while don't dynamic alloc space for out parameter?

Post by Arthur J. Musgrov » Wed, 16 Jul 2003 00:05:14


Yep, memory corruption is happening.

The easiest way to set the string_out variable using CORBA::string_dup. It
will allocate the memory, the perform the string copy.

-- A.J.


Quote:

> Hi, all
>     I made a mistake in my program that I directly use "strcpy" give the
> string-type-out parameter instead dynamic allocing space for this
parameter
> . now the program is running on server. I want to know if this codes would
> cause fatal error . anyone can tell me ? thank you !

> William Cai


 
 
 

what will happen while don't dynamic alloc space for out parameter?

Post by Cai Wenlian » Wed, 16 Jul 2003 10:16:50


but I just "stcpied" a character to the out-string-parameter . I have tested
this codes , it didn't corrupt. I use orbix for this test .



> Yep, memory corruption is happening.

> The easiest way to set the string_out variable using CORBA::string_dup. It
> will allocate the memory, the perform the string copy.

> -- A.J.



> > Hi, all
> >     I made a mistake in my program that I directly use "strcpy" give the
> > string-type-out parameter instead dynamic allocing space for this
> parameter
> > . now the program is running on server. I want to know if this codes
would
> > cause fatal error . anyone can tell me ? thank you !

> > William Cai

 
 
 

what will happen while don't dynamic alloc space for out parameter?

Post by Brian Kel » Wed, 16 Jul 2003 22:30:45


Quote:> but I just "stcpied" a character to the out-string-parameter . I have tested
> this codes , it didn't corrupt. I use orbix for this test .

Would you mind posting some sample code, and perhaps
a snippet of IDL also?

BTW, apart from the fact that you should (as A.J. says)
be using CORBA::string_dup(), you should really consider
using strncpy() instead of strcpy() to prevent buffer
overflows.

Cheers,
Brian
IONA Technologies

> > Yep, memory corruption is happening.

> > The easiest way to set the string_out variable using CORBA::string_dup. It
> > will allocate the memory, the perform the string copy.

> > -- A.J.



> > > Hi, all
> > >     I made a mistake in my program that I directly use "strcpy" give the
> > > string-type-out parameter instead dynamic allocing space for this
>  parameter
> > > . now the program is running on server. I want to know if this codes
>  would
> > > cause fatal error . anyone can tell me ? thank you !

> > > William Cai

 
 
 

what will happen while don't dynamic alloc space for out parameter?

Post by Cai Wenlian » Thu, 17 Jul 2003 10:18:08


codes just like below:

idl:

module MyTest{
    typedef sequence<string>  TypeTest;
    interface test{
    void  Hello(out TypeTest tt);
 }; /* test interface */

Quote:}; /* MyTest Module */

cpp file:
    const int rowcount = 10;

    tt = new TypeTest(rowcount);
    tt->length(rowcount);
    for(int i=0 ;i < rowcount ; i++){
        strcpy((*tt)[i],"N");  // just strcpy a character "Y" or "N"
    }

waiting for your reply . Thank you very much!

William


Quote:> > but I just "stcpied" a character to the out-string-parameter . I have
tested
> > this codes , it didn't corrupt. I use orbix for this test .

> Would you mind posting some sample code, and perhaps
> a snippet of IDL also?

> BTW, apart from the fact that you should (as A.J. says)
> be using CORBA::string_dup(), you should really consider
> using strncpy() instead of strcpy() to prevent buffer
> overflows.

> Cheers,
> Brian
> IONA Technologies

> > > Yep, memory corruption is happening.

> > > The easiest way to set the string_out variable using

CORBA::string_dup. It

- Show quoted text -

> > > will allocate the memory, the perform the string copy.

> > > -- A.J.



> > > > Hi, all
> > > >     I made a mistake in my program that I directly use "strcpy" give
the
> > > > string-type-out parameter instead dynamic allocing space for this
> >  parameter
> > > > . now the program is running on server. I want to know if this codes
> >  would
> > > > cause fatal error . anyone can tell me ? thank you !

> > > > William Cai

 
 
 

what will happen while don't dynamic alloc space for out parameter?

Post by Brian Kel » Fri, 18 Jul 2003 03:36:06


Quote:> module MyTest{
>     typedef sequence<string>  TypeTest;
>     interface test{
>     void  Hello(out TypeTest tt);
>  }; /* test interface */
> }; /* MyTest Module */

> cpp file:
>     const int rowcount = 10;

>     tt = new TypeTest(rowcount);
>     tt->length(rowcount);
>     for(int i=0 ;i < rowcount ; i++){
>         strcpy((*tt)[i],"N");  // just strcpy a character "Y" or "N"
>     }

You need to allocate memory for the string, and this memory
will be deleted by the ORB once the reply has been sent to
the caller. strcpy() doesn't cut it here.

Use this instead (I haven't compiled it, but you'll get the idea):

  const int rowcount = 10;
  tt = new TypeTest(rowcount);
  tt->length(rowcount);
  for (int i=0; i < rowcount; ++i)
  {
      (*tt)[i] =  CORBA::string_dup("N");
  }

Using string_dup() prevents bad things from happening if you
mix different CRTs in your application (for instance, if you
are using a mix of debug and non-debug CRTs on Windows).

Cheers,
Brian
IONA Technologies

 
 
 

1. a question (configuration space and parameter space)

Hello,

Could anyone kindly explain what the difference between a
configuration space and a parameter space?  It seems to me that they
are almost same, but I have seen the notion of configuration space in
the context of robot motion planning while the parameter space seems
to be used in image processing area.  I would really appreciate your
explanation!  

Thank you very much for your time!

Regards,

2. Make Microsoft wake up!!

3. Warnings: Parameters cannot have a datatype of 'void' -- BUT, it is NOT a parameter

4. PowerBook Address Bus/Data Bus? 32-bits?

5. DON'T BUY COMPEYE SCANNERS, they don't care about customers

6. Can't print to TCP/IP network printer

7. dynamic interfaces; I don't understand how

8. DSP56030

9. Dynamic Connectors don't connect

10. Dynamic Controls wheelchair controller internal PCB questions (pin outs)

11. 'out' type parameter in Long sequence doesn't work!

12. What if users don't select 'fit to page' as they print?

13. Maybe I don't understand 'set'