From 194878fbac0a1598fdf7fc8d9045c183c195b6e7 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Wed, 6 Oct 2004 23:08:03 +0000 Subject: [PATCH] Don't call memset if malloc returns a null pointer git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@16797 91177308-0d34-0410-b5e6-96231b3b80d8 --- runtime/GCCLibraries/libc/memory.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/runtime/GCCLibraries/libc/memory.c b/runtime/GCCLibraries/libc/memory.c index 64aef89094a..ebca404d488 100644 --- a/runtime/GCCLibraries/libc/memory.c +++ b/runtime/GCCLibraries/libc/memory.c @@ -28,5 +28,6 @@ void *calloc(size_t nelem, size_t elsize) __ATTRIBUTE_WEAK__; void *calloc(size_t nelem, size_t elsize) { void *Result = malloc(nelem*elsize); - return memset(Result, 0, nelem*elsize); + if (Result) memset(Result, 0, nelem*elsize); + return Result; }