StoreProhibited error when equating two pointers

hobbsac
Posts: 3
Joined: Fri Oct 08, 2021 3:34 am

StoreProhibited error when equating two pointers

Postby hobbsac » Fri Apr 01, 2022 2:07 am

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:
  1. Guru Meditation Error: Core  1 panic'ed (StoreProhibited). Exception was unhandled.
  2.  
  3. Core  1 register dump:
  4. PC      : 0x400d2882  PS      : 0x00060b30  A0      : 0x80088ea8  A1      : 0x3ffc7fd0  
  5. A2      : 0x00000000  A3      : 0x00000000  A4      : 0x00000000  A5      : 0x00000f9f
  6. A6      : 0x3ffc46dc  A7      : 0x00000000  A8      : 0x800d2878  A9      : 0x3ffc7f80
  7. A10     : 0x00000001  A11     : 0x3f401440  A12     : 0x3f40136c  A13     : 0x00005080  
  8. A14     : 0x3f401440  A15     : 0x3ffb32b8  SAR     : 0x00000004  EXCCAUSE: 0x0000001d
  9. EXCVADDR: 0x00000000  LBEG    : 0x400014fd  LEND    : 0x4000150d  LCOUNT  : 0xfffffffd  
  10.  
  11. Backtrace:0x400d287f:0x3ffc7fd0 0x40088ea5:0x3ffc8020
Here is the line that causes the error:
  1. 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.
  1. tPtr = malloc(4000 * sizeof(double));
  2. Timeptr->data = malloc(sizeof(*Timeptr->data)*4000);
Here is the struct to show the double pointer:
  1. struct emxArray_real_T {
  2.   double *data;
  3.   int *size;
  4.   int allocatedSize;
  5.   int numDimensions;
  6.   boolean_T canFreeData;
  7. };
This could very well be just a misunderstanding of how pointers work, but any help would be appreciated.

ESP_Sprite
Posts: 9727
Joined: Thu Nov 26, 2015 4:08 am

Re: StoreProhibited error when equating two pointers

Postby ESP_Sprite » Fri Apr 01, 2022 6:07 am

You're very optimistically assuming your malloc() succeeds.

hobbsac
Posts: 3
Joined: Fri Oct 08, 2021 3:34 am

Re: StoreProhibited error when equating two pointers

Postby hobbsac » Fri Apr 01, 2022 6:03 pm

ESP_Sprite wrote:
Fri Apr 01, 2022 6:07 am
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?

ESP_Sprite
Posts: 9727
Joined: Thu Nov 26, 2015 4:08 am

Re: StoreProhibited error when equating two pointers

Postby ESP_Sprite » Sat Apr 02, 2022 1:27 am

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?

Who is online

Users browsing this forum: No registered users and 73 guests