I would go for: (unsigned char *)malloc(sizeof(char) * size);
but I'm more concerned about the sizeof(char) since we are assigning an unsigned char buffer. I'll double check this.