On Sep 30, 2004, at 11:13 PM, Ben Combee wrote:
At 04:08 PM 9/30/2004, you wrote:
I'm getting the error :

YourApp (1.0) just read from memory location
0x0003CC00, which is in the
unused portion of the stack.  The stack range is
0x0003C504 - 0x0003D2B2,
and the stack pointer is 0x0003D110.

I have a local pointer variable that's pointing to a
global variable, and I'm writing to the structure that
this local pointer points to. That's where the error
is occurring.

It sounds like your programm is exceeding the stack size allocated to it at startup, and the stack is crawling into the section of memory being used by global variables. If you're using CodeWarrior, look into #pragma warn_stack_usage as a way to find functions that are using large amounts of stack. The default stack size is only about 4K.

I think that the problem actually lies elsewhere.

First, if the stack indeed overflowed, then the Palm OS Emulator would have reported it. That's one of the standard checks it makes any time A7 (the stack pointer) is adjusted.

Second, even if a stack overflow occurred and the Palm OS Emulator didn't catch or report it, I don't think that a stack overflow would lead to the actual reported problem. If the local pointer actually pointed to a global variable, then that pointer would still be outside the reported stack range, and the Emulator would not report it as an error.

I think it far more likely that the local pointer variable actually points to a local variable of a function that was called and had since returned. E.g:

char* MyGetBuffer()
{
    char myBuffer[0x400];
    return myBuffer;
}

If the result of MyGetBuffer is stored in the OP's local pointer variable and then used to access the buffer, you'd get the error message reported. Notice how the memory location reported in the error message is 0x510 bytes below the stack pointer, which might be explained by a conveniently-sized 1K buffer in there somewhere.

The OP has since reported that he's fixed the problem, but I don't understand his explanation.

-- Keith Rollin
-- Palm OS Developer Tools engineer


-- For information on using the Palm Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/support/forums/

Reply via email to