Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   Local Variables not getting values back (http://www.velocityreviews.com/forums/t620448-local-variables-not-getting-values-back.html)

Samant.Trupti@gmail.com 06-16-2008 01:41 PM

Local Variables not getting values back
 
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

AnonMail2005@gmail.com 06-16-2008 01:56 PM

Re: Local Variables not getting values back
 
> 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.

Lionel B 06-16-2008 01:57 PM

Re: Local Variables not getting values back
 
On Mon, 16 Jun 2008 06:41:18 -0700, Samant.Trupti@gmail.com 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-lit...t.html#faq-5.8

--
Lionel B

Pascal J. Bourguignon 06-16-2008 02:34 PM

Re: Local Variables not getting values back
 
"Samant.Trupti@gmail.com" <Samant.Trupti@gmail.com> 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__

Samant.Trupti@gmail.com 06-16-2008 02:42 PM

Re: Local Variables not getting values back
 
On Jun 16, 7:34*pm, p...@informatimago.com (Pascal J. Bourguignon)
wrote:
> "Samant.Tru...@gmail.com" <Samant.Tru...@gmail.com> 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

Pascal J. Bourguignon 06-16-2008 02:59 PM

Re: Local Variables not getting values back
 
"Samant.Trupti@gmail.com" <Samant.Trupti@gmail.com> 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__


All times are GMT. The time now is 08:07 AM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57