/[inetutils]/inetutils/lib/xmalloc.c
ViewVC logotype

Diff of /inetutils/lib/xmalloc.c

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

revision 1.1 by ams, Fri Jan 21 13:02:48 2005 UTC revision 1.2 by gray, Fri Jul 29 10:52:44 2005 UTC
# Line 1  Line 1 
1  /* xmalloc.c -- malloc with out of memory checking  /* xmalloc.c -- malloc with out of memory checking
2    
3     Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,     Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
4     1999, 2000, 2002, 2003, 2004 Free Software Foundation, Inc.     1999, 2000, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
5    
6     This program is free software; you can redistribute it and/or modify     This program is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by     it under the terms of the GNU General Public License as published by
# Line 15  Line 15 
15    
16     You should have received a copy of the GNU General Public License     You should have received a copy of the GNU General Public License
17     along with this program; if not, write to the Free Software Foundation,     along with this program; if not, write to the Free Software Foundation,
18     Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */     Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
19    
20  #if HAVE_CONFIG_H  #if HAVE_CONFIG_H
21  # include <config.h>  # include <config.h>
# Line 30  Line 30 
30  # define SIZE_MAX ((size_t) -1)  # define SIZE_MAX ((size_t) -1)
31  #endif  #endif
32    
33    /* 1 if calloc is known to be compatible with GNU calloc.  This
34       matters if we are not also using the calloc module, which defines
35       HAVE_CALLOC and supports the GNU API even on non-GNU platforms.  */
36    #if defined HAVE_CALLOC || defined __GLIBC__
37    enum { HAVE_GNU_CALLOC = 1 };
38    #else
39    enum { HAVE_GNU_CALLOC = 0 };
40    #endif
41    
42  /* Allocate an array of N objects, each with S bytes of memory,  /* Allocate an array of N objects, each with S bytes of memory,
43     dynamically, with error checking.  S must be nonzero.  */     dynamically, with error checking.  S must be nonzero.  */
44    
# Line 204  xcalloc (size_t n, size_t s) Line 213  xcalloc (size_t n, size_t s)
213  {  {
214    void *p;    void *p;
215    /* Test for overflow, since some calloc implementations don't have    /* Test for overflow, since some calloc implementations don't have
216       proper overflow checks.  */       proper overflow checks.  But omit overflow and size-zero tests if
217    if (xalloc_oversized (n, s) || (! (p = calloc (n, s)) && n != 0))       HAVE_GNU_CALLOC, since GNU calloc catches overflow and never
218         returns NULL if successful.  */
219      if ((! HAVE_GNU_CALLOC && xalloc_oversized (n, s))
220          || (! (p = calloc (n, s)) && (HAVE_GNU_CALLOC || n != 0)))
221      xalloc_die ();      xalloc_die ();
222    return p;    return p;
223  }  }

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

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