queue_new(): fix NULL dereference on allocation failure
Coverity complains about a 'Dereference before null check' on *queue. So, push the NULL check further up. Though I doubt that 'return EOF' is the proper way to handle allocation failure, this patch is only about the NULL dereference. Fixes: CID#57918
This commit is contained in:
parent
b29ff1da55
commit
f89dc4e127
|
@ -127,16 +127,15 @@ int queue_new(struct queue_t **queue)
|
||||||
if (QUEUE_DEBUG)
|
if (QUEUE_DEBUG)
|
||||||
printf("queue_new\n");
|
printf("queue_new\n");
|
||||||
*queue = calloc(1, sizeof(struct queue_t));
|
*queue = calloc(1, sizeof(struct queue_t));
|
||||||
|
if (!(*queue))
|
||||||
|
return EOF;
|
||||||
(*queue)->next = 0;
|
(*queue)->next = 0;
|
||||||
(*queue)->first = -1;
|
(*queue)->first = -1;
|
||||||
(*queue)->last = -1;
|
(*queue)->last = -1;
|
||||||
|
|
||||||
if (QUEUE_DEBUG)
|
if (QUEUE_DEBUG)
|
||||||
queue_print(*queue);
|
queue_print(*queue);
|
||||||
if (*queue)
|
return 0;
|
||||||
return 0;
|
|
||||||
else
|
|
||||||
return EOF;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! \brief Deallocates queue structure */
|
/*! \brief Deallocates queue structure */
|
||||||
|
|
Loading…
Reference in New Issue