/[pspp]/pspp/src/alloc.c
ViewVC logotype

Diff of /pspp/src/alloc.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.7 by jmd, Fri Apr 29 01:02:13 2005 UTC revision 1.8 by jmd, Wed May 25 02:31:32 2005 UTC
# Line 43  xmalloc (size_t size) Line 43  xmalloc (size_t size)
43    return vp;    return vp;
44  }  }
45    
46  /* Allocates a block of SIZE bytes, fill it with all-bits-0, and  
47     returns it.  /* Allocates a continous block of N_MEMB by SIZE elements, with all
48     If SIZE is 0, returns a null pointer.     bits set to 0.
49     Aborts if unsuccessful. */     Aborts if unsuccessful.
50    */
51  void *  void *
52  xcalloc (size_t size)  xcalloc (size_t n_memb, size_t size)
53  {  {
54    void *vp = xmalloc (size);    const size_t prod = size * n_memb;
55    memset (vp, 0, size);    void *vp = 0;
56    
57      if (prod == 0)
58        return NULL;
59    
60      /* Trap overflow errors */
61      assert ( prod >= size );
62      assert ( prod >= n_memb ) ;
63    
64      vp = xmalloc ( prod );
65      memset (vp, 0, prod);
66    return vp;    return vp;
67  }  }
68    
69    
70    
71  /* If SIZE is 0, then block PTR is freed and a null pointer is  /* If SIZE is 0, then block PTR is freed and a null pointer is
72     returned.     returned.
73     Otherwise, if PTR is a null pointer, then a new block is allocated     Otherwise, if PTR is a null pointer, then a new block is allocated

Legend:
Removed from v.1.7  
changed lines
  Added in v.1.8

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26