Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libc/stdlib allow calloc(0, x) and calloc(x, 0). sync w...



details:   https://anonhg.NetBSD.org/src/rev/11ed5e4b8bb0
branches:  trunk
changeset: 534643:11ed5e4b8bb0
user:      itojun <itojun%NetBSD.org@localhost>
date:      Wed Jul 31 09:26:49 2002 +0000

description:
allow calloc(0, x) and calloc(x, 0).  sync w/openbsd

diffstat:

 lib/libc/stdlib/calloc.c |  11 ++++++-----
 1 files changed, 6 insertions(+), 5 deletions(-)

diffs (35 lines):

diff -r 8f745ad38797 -r 11ed5e4b8bb0 lib/libc/stdlib/calloc.c
--- a/lib/libc/stdlib/calloc.c  Wed Jul 31 07:01:26 2002 +0000
+++ b/lib/libc/stdlib/calloc.c  Wed Jul 31 09:26:49 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: calloc.c,v 1.10 2002/07/30 09:45:02 itojun Exp $       */
+/*     $NetBSD: calloc.c,v 1.11 2002/07/31 09:26:49 itojun Exp $       */
 
 /*-
  * Copyright (c) 1990, 1993
@@ -38,7 +38,7 @@
 #if 0
 static char sccsid[] = "@(#)calloc.c   8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: calloc.c,v 1.10 2002/07/30 09:45:02 itojun Exp $");
+__RCSID("$NetBSD: calloc.c,v 1.11 2002/07/31 09:26:49 itojun Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -54,12 +54,13 @@
 {
        void *p;
 
-       if (SIZE_T_MAX / num < size) {
+       if (num && size && SIZE_T_MAX / num < size) {
                errno = ENOMEM;
                return NULL;
        }
        size *= num;
-       if ((p = malloc(size)) != NULL)
-               memset(p, '\0', size);
+       p = malloc(size);
+       if (p)
+               memset(p, 0, size);
        return(p);
 }



Home | Main Index | Thread Index | Old Index