Crashes unless I check for stack overflows?

Hi all, this seems a bit strange to me.

Ive been developing a project using a PIC32MX170, and so far Ive been doing everything under a debug build so that I can catch a software breakpoint in my stack overflow hook (plus other debugging as required). Everything has been working perfectly fine in debug mode for the past month or two after I resolved a couple of stack overflows that had occurred.

Now Im trying to run my project as a production build since I am sufficiently far enough through it, and it seems stable in a debug build that I want to let it run for a while without debugging to see if it continues to behave.

But when I perform a production build my application seems to be crashing on boot unless I enable stack overflow checking.

With stack checking enabled, it seems to run perfectly fine…

What could cause this kind of behaviour? Is there anything specific that I should look for? It doesnt appear that the stack overflow hook is being executed because the GPIO pin that it toggles is not toggling.

FWIW there is some code which, if I comment it out will also cause it to run correctly with stack checking disabled, so I am giving this plenty of scrutiny at the moment, but still it is strange that with stack checking enabled this code also runs just fine…? I have tried increasing the size of the stack related to this code but that didnt seem to have any effect.

Thanks

with stack checking enabled, your memory layout changes, so it might be the case that memory corruptions go unnoticed (non pathological) with the additional code/ run time memory footprint. Iow, with it enabled, the code may still be erratic but it goes unnoticed.

1 Like

I think I found the issue, but Im not even sure how or why it worked in debug mode in the first place…

for (ctr == (RX_MSG_MAX_LEN + 1); ctr > 0; ctr--) {

Yeah, == in assignment instead of =. :roll_eyes:

So, I think the reason it “worked” prior is because ctr is otherwise uninitialised. It probably had some random value (maybe the stack overflow test value) as its value going into that loop, while the thing == other_thing statement was essentially discarded because it does nothing - its just the rest of my logic that exited the loop successfully.

Ive since found options within MPLAB-X to turn on more warning messages, so hopefully that wont happen again in the future…!

Once again, nothing to see here, just me. :sweat_smile:

Thank you for reporting you solution.