From 3c32dd3bc92ccbcac538a25746f09ca68371319b Mon Sep 17 00:00:00 2001 From: Travis Cross Date: Fri, 22 Aug 2014 02:47:04 +0000 Subject: [PATCH] Return NULL from `sub_alloc` for zero size When zero was passed for the size to `sub_alloc`, we were passing this size on to `malloc` or `calloc`, which is unusual enough that static analyzers warn about this (POSIX says that either NULL or a pointer will be returned). We'll instead just return NULL right away. --- libs/sofia-sip/libsofia-sip-ua/su/su_alloc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libs/sofia-sip/libsofia-sip-ua/su/su_alloc.c b/libs/sofia-sip/libsofia-sip-ua/su/su_alloc.c index 005989bb75..e438a89543 100644 --- a/libs/sofia-sip/libsofia-sip-ua/su/su_alloc.c +++ b/libs/sofia-sip/libsofia-sip-ua/su/su_alloc.c @@ -432,6 +432,8 @@ void *sub_alloc(su_home_t *home, if (size >= ((size_t)1) << SIZEBITS) return (void)(errno = ENOMEM), NULL; + if (!size) return NULL; + if (sub == NULL || 3 * sub->sub_used > 2 * sub->sub_n) { /* Resize the hash table */ size_t i, n, n2; @@ -474,7 +476,7 @@ void *sub_alloc(su_home_t *home, sub = b2; } - if (size && sub && zero < do_clone && + if (sub && zero < do_clone && sub->sub_preload && size <= sub->sub_prsize) { /* Use preloaded memory */ size_t prused = sub->sub_prused + size + MEMCHECK_EXTRA;