Page 1 of 1

StoreProhibited error when equating two pointers

Posted: Fri Apr 01, 2022 2:07 am
by hobbsac
Hello, I am using the ESP-WROOM-32 with the latest version of ESP-IDF and have run into an error. I am trying to set a double pointer in a struct equal to another double pointer. My code works fine until it encounters this line of code (it works if it is commented out) where it will cause the core to panic and say StoreProhibited.

Here is the error message:

Code: Untitled.c Select all


Guru Meditation Error: Core  1 panic'ed (StoreProhibited). Exception was unhandled.

Core 1 register dump:
PC : 0x400d2882 PS : 0x00060b30 A0 : 0x80088ea8 A1 : 0x3ffc7fd0
A2 : 0x00000000 A3 : 0x00000000 A4 : 0x00000000 A5 : 0x00000f9f
A6 : 0x3ffc46dc A7 : 0x00000000 A8 : 0x800d2878 A9 : 0x3ffc7f80
A10 : 0x00000001 A11 : 0x3f401440 A12 : 0x3f40136c A13 : 0x00005080
A14 : 0x3f401440 A15 : 0x3ffb32b8 SAR : 0x00000004 EXCCAUSE: 0x0000001d
EXCVADDR: 0x00000000 LBEG : 0x400014fd LEND : 0x4000150d LCOUNT : 0xfffffffd

Backtrace:0x400d287f:0x3ffc7fd0 0x40088ea5:0x3ffc8020
Here is the line that causes the error:

Code: Untitled.c Select all

Timeptr->data = tPtr;
To my understanding, StoreProhibited normally means that you are trying to write to non-existent memory, however, I have allocated memory for both of these pointers in a separate task that definitely runs before the line of code in question.

Code: Untitled.c Select all


tPtr = malloc(4000 * sizeof(double));
Timeptr->data = malloc(sizeof(*Timeptr->data)*4000);
Here is the struct to show the double pointer:

Code: Untitled.c Select all

struct emxArray_real_T {
double *data;
int *size;
int allocatedSize;
int numDimensions;
boolean_T canFreeData;
};
This could very well be just a misunderstanding of how pointers work, but any help would be appreciated.

Re: StoreProhibited error when equating two pointers

Posted: Fri Apr 01, 2022 6:07 am
by Sprite
You're very optimistically assuming your malloc() succeeds.

Re: StoreProhibited error when equating two pointers

Posted: Fri Apr 01, 2022 6:03 pm
by hobbsac
You're very optimistically assuming your malloc() succeeds.
How do I make sure that it succeeds? Is this a common issue with ESP32 or is it something wrong with my code?

Re: StoreProhibited error when equating two pointers

Posted: Sat Apr 02, 2022 1:27 am
by Sprite
My point is that you're allocating about 48K of RAM, which is a non-trivial amount. Malloc will fail if you do not have that amount of free RAM and will return a NULL pointer. That guru meditation has all the hallmarks of you trying to dereference a null pointer (specifically EXCVADDR: 0x00000000). Hence my remark: why are you so sure that those malloc calls succeed that you do not even check their result?