Hello,
I am working on AT91SAM9G20, Keil 5.10. I am passing a constant structure pointer to a function.
typedef struct { int Test; int OkFlag; }StructNode; typedef const StructNode *const Node_t
after passing the node 3 times recursively through a function
stack data is getting corrupted.
Am I doing any mistake, Please suggest.
So have you verified that the stack is big enough? And have you verified if there are other structures that are neighbour with the stack and might overwrite the stack? And have you verified your use of pointers or arrays to check for use of invalid pointers or out-of-bounds accesses to arrays?
I have abundant stack, I am not modifying any data inside the function, I have trimmed the function to minimal, for just passing a duplicate node but data variables present in the first caller are getting corrupted.
I am type casting a auto variable to const type
StructNode Node; Node_t NodePtr = &Node;
I suspect there might be issue with Node_t typecast from Node
Passing an address of a stack based variable can be tricky since the lifetime of the variable ends at the function return.
When the reference pointer of such a variable is used after that, you get a stack corruption. I suggest that you analyze your program for such a scenario.