Module Name:    src
Committed By:   dholland
Date:           Sun Dec 30 17:36:00 UTC 2012

Modified Files:
        src/lib/libutil: efun.c

Log Message:
If malloc, calloc, or realloc returns NULL when a size of 0 was
requested, which is allowed by pertinent standards, honor it instead
of bombing.

Do not do this for calloc(x, y) where x != 0 && y != 0 but x*y == 0;
in that case bomb.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/lib/libutil/efun.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/efun.c
diff -u src/lib/libutil/efun.c:1.6 src/lib/libutil/efun.c:1.7
--- src/lib/libutil/efun.c:1.6	Mon Apr 28 20:23:02 2008
+++ src/lib/libutil/efun.c	Sun Dec 30 17:36:00 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: efun.c,v 1.6 2008/04/28 20:23:02 martin Exp $	*/
+/*	$NetBSD: efun.c,v 1.7 2012/12/30 17:36:00 dholland Exp $	*/
 
 /*-
  * Copyright (c) 2006 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 
 #include <sys/cdefs.h>
 #ifdef __RCSID
-__RCSID("$NetBSD: efun.c,v 1.6 2008/04/28 20:23:02 martin Exp $");
+__RCSID("$NetBSD: efun.c,v 1.7 2012/12/30 17:36:00 dholland Exp $");
 #endif
 
 #include <err.h>
@@ -104,7 +104,7 @@ void *
 emalloc(size_t n)
 {
 	void *p = malloc(n);
-	if (p == NULL)
+	if (p == NULL && n != 0)
 		(*efunc)(1, "Cannot allocate %zu bytes", n);
 	return p;
 }
@@ -113,7 +113,7 @@ void *
 ecalloc(size_t n, size_t s)
 {
 	void *p = calloc(n, s);
-	if (p == NULL)
+	if (p == NULL && n != 0 && s != 0)
 		(*efunc)(1, "Cannot allocate %zu bytes", n);
 	return p;
 }
@@ -122,7 +122,7 @@ void *
 erealloc(void *p, size_t n)
 {
 	void *q = realloc(p, n);
-	if (q == NULL)
+	if (q == NULL && n != 0)
 		(*efunc)(1, "Cannot re-allocate %zu bytes", n);
 	return q;
 }

Reply via email to