The above definition [note 54 changed to 1] and the following:
uint8_t payload; // <- This one here
} PACK packet_t;
Some compilers support
packet_t *allocatePacket(bool has54payload)
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.
In which case you could remove the -1 in the malloc() call.