[PATCH] queue_new(): if calloc fails, abort (CID #57918)

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/OpenBSC@lists.osmocom.org/.

Neels Hofmeyr nhofmeyr at sysmocom.de
Thu Apr 14 14:38:42 UTC 2016


Coverity complains about a 'Dereference before null check' on *queue.
So, push the NULL check further up, but also, instead of handling a calloc
failure as error, rather abort the program.
---
 gtp/queue.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/gtp/queue.c b/gtp/queue.c
index 7c971b0..707b522 100644
--- a/gtp/queue.c
+++ b/gtp/queue.c
@@ -127,16 +127,15 @@ int queue_new(struct queue_t **queue)
 	if (QUEUE_DEBUG)
 		printf("queue_new\n");
 	*queue = calloc(1, sizeof(struct queue_t));
+	if (!(*queue))
+		abort();
 	(*queue)->next = 0;
 	(*queue)->first = -1;
 	(*queue)->last = -1;
 
 	if (QUEUE_DEBUG)
 		queue_print(*queue);
-	if (*queue)
-		return 0;
-	else
-		return EOF;
+	return 0;
 }
 
 /*! \brief Deallocates queue structure */
-- 
2.1.4




More information about the OpenBSC mailing list