Code:
typedef struct
{
uint8_t address;
uint8_t rxAddress;
uint8_t type;
uint8_t payload[1]; // <- This one here
} PACK packet_t;
The above definition [note 54 changed to 1] and the following:
Code:
packet_t *allocatePacket(bool has54payload)
{
packet_t *pkt;
size_t size = 9;
if (has54payload) size = 54;
pkt = malloc(sizeof(packet_t) + size - 1); // -1 because we already have 1 element in the struct.
return pkt;
}
Some compilers support
Code:
...
uint8_t payload[0];
...
In which case you could remove the -1 in the malloc() call.
--
Mats