Local Variables not getting values back

Discussion in 'C++' started by Samant.Trupti@gmail.com, Jun 16, 2008.

  1. Guest

    Hi All,

    I am facing a strange problem..
    I am calling a function func2 from func1. Before calling func2 all
    the local variables in func1 looks fine and has their respective
    values. When function returns back from func2 to func1 all the local
    variables in func1 has values 0xfdfdfd.
    Can somebody please explain me what is happening and what is the
    solution for this?
    Thanks
    Trupti
    , Jun 16, 2008
    #1
    1. Advertising

  2. Guest

    > Hi All,
    >
    >   I am facing a strange problem..
    > I am calling a function func2 from func1.  Before calling func2 all
    > the local variables in func1 looks fine and has their respective
    > values.  When function returns back from func2 to func1 all the local
    > variables in func1 has values 0xfdfdfd.
    >  Can somebody please explain me what is happening and what is the
    > solution for this?

    Post some code so we can take a look at it.
    , Jun 16, 2008
    #2
    1. Advertising

  3. Lionel B Guest

    On Mon, 16 Jun 2008 06:41:18 -0700, wrote:

    > Hi All,
    >
    > I am facing a strange problem..
    > I am calling a function func2 from func1. Before calling func2 all the
    > local variables in func1 looks fine and has their respective values.
    > When function returns back from func2 to func1 all the local variables
    > in func1 has values 0xfdfdfd.
    > Can somebody please explain me what is happening and what is the
    > solution for this?


    Post code.

    http://www.parashift.com/c -faq-lite/how-to-post.html#faq-5.8

    --
    Lionel B
    Lionel B, Jun 16, 2008
    #3
  4. "" <> writes:

    > Hi All,
    >
    > I am facing a strange problem..
    > I am calling a function func2 from func1. Before calling func2 all
    > the local variables in func1 looks fine and has their respective
    > values. When function returns back from func2 to func1 all the local
    > variables in func1 has values 0xfdfdfd.
    > Can somebody please explain me what is happening and what is the
    > solution for this?


    There's probably a "buffer overflow" or some other kind of overrun in
    the local variables of func2. In the usual processors, the stack
    grows downward, and the local variables are allocated on the stack.
    So the local variables of func2 are stored before the the local
    variables of func1, and if you write beyond the bounds of the local
    variables of func2, you can erase the frame pointers, the return
    addresses and the local variables of the calling procedures.

    The solution would be to debug func2.


    --
    __Pascal Bourguignon__
    Pascal J. Bourguignon, Jun 16, 2008
    #4
  5. Guest

    On Jun 16, 7:34 pm, (Pascal J. Bourguignon)
    wrote:
    > "" <> writes:
    > > Hi All,

    >
    > >   I am facing a strange problem..
    > > I am calling a function func2 from func1.  Before calling func2 all
    > > the local variables in func1 looks fine and has their respective
    > > values.  When function returns back from func2 to func1 all the local
    > > variables in func1 has values 0xfdfdfd.
    > >  Can somebody please explain me what is happening and what is the
    > > solution for this?

    >
    > There's probably a "buffer overflow" or some other kind of overrun in
    > the local variables of func2.  In the usual processors, the stack
    > grows downward, and the local variables are allocated on the stack.
    > So the local variables of func2 are stored before the the local
    > variables of func1, and if you write beyond the bounds of the local
    > variables of func2, you can erase the frame pointers, the return
    > addresses and the local variables of the calling procedures.
    >
    > The solution would be to debug func2.
    >
    > --
    > __Pascal Bourguignon__


    Thank you for quick reply for my query. It is not possible for me to
    post code. It is a big application and lots of variables.
    I will try to debug it according your suggestions. Please post me
    some more suggestions if any.

    Trupti
    , Jun 16, 2008
    #5
  6. "" <> writes:
    > Thank you for quick reply for my query. It is not possible for me to
    > post code. It is a big application and lots of variables.
    > I will try to debug it according your suggestions. Please post me
    > some more suggestions if any.


    Well, given this kind of behavior (of your program), it might be very
    useful for you to run it under valgrind. You will probably find a
    lot of bugs with valgrind.

    http://valgrind.org/

    --
    __Pascal Bourguignon__
    Pascal J. Bourguignon, Jun 16, 2008
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Joby
    Replies:
    0
    Views:
    1,617
  2. Sullivan WxPyQtKinter
    Replies:
    10
    Views:
    641
    Antoon Pardon
    Nov 8, 2007
  3. steve king
    Replies:
    0
    Views:
    206
    steve king
    Sep 4, 2003
  4. Tammo Tjarks
    Replies:
    2
    Views:
    276
    Tammo Tjarks
    Sep 13, 2007
  5. king
    Replies:
    2
    Views:
    161
    Tad McClellan
    Jun 27, 2006
Loading...

Share This Page