CyU3PMemAlloc behaving strangely | Cypress Semiconductor
CyU3PMemAlloc behaving strangely
I'm having an issue with CyU3PMemAlloc. I found this thread, but there were no solutions. Basically I ask CyU3PMemAlloc for 16 bytes and it returns 4 bytes. Let me give a little context. So CommandOutQueue is type uint8_t**. I first allocate sizeof(uint8_t*) (4 bytes) for CommandOutQueue, and then allocate 16 bytes for CommandOutQueue. This code is slightly simplified, but it boils down to:
CommandOutQueue = CyU3PMemAlloc(sizeof(uint8_t*));
MBIMCommandOutQueue = CyU3PMemAlloc(16);
CyU3PDebugPrint(4,"\n\rsizeof(CommandOutQueue) = %d",i,sizeof(CommandOutQueue);
sizeof(CommanOutQueue) = 4
on the debug console.
The behavior is really odd, because it doesn't return null which is the error condition. What's also strange is that it doesn't throw a segfault when my code address outside of the 4 bytes. I only realized there was problem when I later needed to know the size of the CommandOutQueue and it returned 4 which caused a cascade of other issues. By the way I'm confident there is at least 16 bytes left on the stack. If anyone has faced similiar issues, how did you get around them?