At 3:41 AM +0200 04/26/00, D. DeVecchio wrote:
>It can't be the ROM (OS 3.3). It must be my program, but HOW can I make
>the OS crash as long as the pointer is vaild?

1) are you sure it's the event pointer that's causing the problem?  You
should look carefully at the stack trace and the address that's being
followed when the bus error occurs.

2) It's possible for stack-based variables to be in invalid ranges.  This
happens when you overflow the stack!  So maybe that's what's going on here,
and the newEvent structure happens to be the one that shows up at the end.

Some versions of the codewarrior compiler have a really nasty optimization
problem that could be hitting you.  Consider code with 'locally declared'
variables like this:

    if (condition) {
        EventType newEvent;
        EvtGetEvent (&newEvent, 0);
        ...blah...
        }
    else if (condition2) {
        EventType newEvent;
        EvtGetEvent (&newEvent, 0);
        ...blah...
        }
    else if (condition3) {
        EventType newEvent;
        EvtGetEvent (&newEvent, 0);
        ...blah...
        }
    ...etc.

You'd *think* the compiler would notice that the scope of all those
newEvent variables does not overlap, and would allocate just ONE
stack-based newEvent structure to handle them.  That is, it would produce:

    EventType newEvent;

    if (condition) {
        EvtGetEvent (&newEvent, 0);
        ...blah...
        }
    else if (condition2) {
        EvtGetEvent (&newEvent, 0);
        ...blah...
        }
    else if (condition3) {
        EvtGetEvent (&newEvent, 0);
        ...blah...
        }
    ...etc.

But, it doesn't.  Instead, it does essentially this:

    EventType newEvent1;
    EventType newEvent2;
    EventType newEvent3;

    if (condition) {
        EvtGetEvent (&newEvent1, 0);
        ...blah...
        }
    else if (condition2) {
        EvtGetEvent (&newEvent2, 0);
        ...blah...
        }
    else if (condition3) {
        EvtGetEvent (&newEvent3, 0);
        ...blah...
        }
    ...etc.

Now this function is taking 3x the stack space that you think!  There's
nothing illegal or non-ANSI about this, it's just a missed optimization.

That's why it's good practice (in C) to always declare ALL of your
variables at the top of the function, rather than trying to inline the
declarations.

I think this got fixed somewhere along the way, but I'm not sure exactly
which compiler version handles it.

                                --Bob



-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palm.com/devzone/mailinglists.html

Reply via email to