Make allocations based on var size, not struct size - it's safer
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user