Make allocations based on var size, not struct size - it's safer

This commit is contained in:
2017-06-21 12:20:47 +03:00
parent a0915fc803
commit bee649a34e
4 changed files with 8 additions and 9 deletions

View File

@@ -12,7 +12,7 @@ int start_msg_queue(void)
for (i = 0; i < total_queues; i++) {
if (slot[i] == NULL) {
slot[i] = (struct msg_t *)calloc(100, sizeof(struct msg_t));
slot[i] = calloc(100, sizeof(**slot));
if (slot[i] == NULL)
return -1;
return i;
@@ -28,7 +28,7 @@ void free_queue(int id)
int start_job_queue(int poolsize)
{
slot = (struct msg_t **)calloc(poolsize, sizeof(struct msg_t *));
slot = calloc(poolsize, sizeof(*slot));
if (slot == NULL)
return -1;
total_queues = poolsize;