avr-gcc-list
[Top][All Lists]
Advanced

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

Re: [avr-gcc-list] Strange compile behaviour


From: Dave Hylands
Subject: Re: [avr-gcc-list] Strange compile behaviour
Date: Tue, 2 Feb 2010 09:41:21 -0800

Hi Han,

On Tue, Feb 2, 2010 at 4:57 AM, Han Hoekstra
<address@hidden> wrote:
> However, what I don't understand is that the while loop does not cause some
> stack overflow, because I have decreased the array to be only a single
> element, so app_TXIncomming is always 0, so the while loop should therefore
> never loop.

Since the code size changes, lots of things that are stored on the
stack will also change (i.e. return addresses, addresses of global
variables etc). So the content of uninitialized variable may change as
well.

It's also possible to have a stack overwrite which doesn't affect all
bytes of the stack.

For example, let's suppose I declared a local (i.e. stack variable)

char buf[20];

And the last two bytes happened to line up with your 2 checker bytes.
If you never actually wrote to those bytes (maybe you only use the
first 10 bytes of buf), you still have a stack overflow, but not one
that is detected.

Changing the code size will cause the location of your checker bytes
to also change, and that may be enough to have it now collide.

You may wish to try filling all of the stack space with a fill byte,
and then checking to see how many fill bytes are untouched. It still
suffers from the problem I mentioned above, but it can often tell you
if you're getting close to filling the stack.

-- 
Dave Hylands
Shuswap, BC, Canada
http://www.DaveHylands.com/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]