pspp-cvs
[Top][All Lists]
Advanced

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

[Pspp-cvs] Changes to pspp/src/alloc.c


From: John Darrington
Subject: [Pspp-cvs] Changes to pspp/src/alloc.c
Date: Tue, 24 May 2005 22:31:37 -0400

Index: pspp/src/alloc.c
diff -u pspp/src/alloc.c:1.7 pspp/src/alloc.c:1.8
--- pspp/src/alloc.c:1.7        Fri Apr 29 01:02:13 2005
+++ pspp/src/alloc.c    Wed May 25 02:31:32 2005
@@ -43,18 +43,31 @@
   return vp;
 }
 
-/* Allocates a block of SIZE bytes, fill it with all-bits-0, and
-   returns it.
-   If SIZE is 0, returns a null pointer.
-   Aborts if unsuccessful. */
+
+/* Allocates a continous block of N_MEMB by SIZE elements, with all
+   bits set to 0.
+   Aborts if unsuccessful.
+*/
 void *
-xcalloc (size_t size)
+xcalloc (size_t n_memb, size_t size)
 {
-  void *vp = xmalloc (size);
-  memset (vp, 0, size);
+  const size_t prod = size * n_memb; 
+  void *vp = 0;
+
+  if (prod == 0)
+    return NULL;
+
+  /* Trap overflow errors */
+  assert ( prod >= size );
+  assert ( prod >= n_memb ) ;
+
+  vp = xmalloc ( prod );
+  memset (vp, 0, prod);
   return vp;
 }
 
+
+
 /* If SIZE is 0, then block PTR is freed and a null pointer is
    returned.
    Otherwise, if PTR is a null pointer, then a new block is allocated




reply via email to

[Prev in Thread] Current Thread [Next in Thread]