From 816fa00625c45c90ffcabdcb4eb0b14b66ce396d Mon Sep 17 00:00:00 2001 From: Christophe CURIS Date: Sun, 16 May 2021 15:47:05 +0200 Subject: [PATCH] WUtil: Make sure wmalloc/wrealloc won't fail because of the abort handler As pointed by Coverity (#50074), despite the expected behaviour that 'wmalloc' should never return NULL, it may still happen if an abort handler set by user (with wsetabort) does not call exit() as expected. In such case we make sure the NULL pointer dereference does not happen inside WINGs code because we assume it is a known user choice. Signed-off-by: Christophe CURIS --- WINGs/memory.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/WINGs/memory.c b/WINGs/memory.c index 81476e45..e05e17a8 100644 --- a/WINGs/memory.c +++ b/WINGs/memory.c @@ -107,7 +107,8 @@ void *wmalloc(size_t size) } } } - memset(tmp, 0, size); + if (tmp != NULL) + memset(tmp, 0, size); return tmp; }