X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=lib%2Fxmalloc.c;h=08c30fb8a3b7cdcfa0fa903df1bd55417bae5395;hb=2726ca8984e8d2d8edf288b4d1d7007bfca0d82e;hp=89ecf17ad0851dc47687ac3e323e6743a2f942b3;hpb=929dcebaff7c1ee0501e83ee6e3016aa6d95b4cf;p=gnulib.git diff --git a/lib/xmalloc.c b/lib/xmalloc.c index 89ecf17ad..08c30fb8a 100644 --- a/lib/xmalloc.c +++ b/lib/xmalloc.c @@ -1,8 +1,6 @@ /* xmalloc.c -- malloc with out of memory checking - Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, - 1999, 2000, 2002, 2003, 2004, 2005, 2006, 2008 Free Software Foundation, - Inc. + Copyright (C) 1990-2000, 2002-2006, 2008-2011 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -28,14 +26,10 @@ #include #include -#ifndef SIZE_MAX -# define SIZE_MAX ((size_t) -1) -#endif - /* 1 if calloc is known to be compatible with GNU calloc. This matters if we are not also using the calloc module, which defines - HAVE_CALLOC and supports the GNU API even on non-GNU platforms. */ -#if defined HAVE_CALLOC || defined __GLIBC__ + HAVE_CALLOC_GNU and supports the GNU API even on non-GNU platforms. */ +#if defined HAVE_CALLOC_GNU || (defined __GLIBC__ && !defined __UCLIBC__) enum { HAVE_GNU_CALLOC = 1 }; #else enum { HAVE_GNU_CALLOC = 0 }; @@ -58,8 +52,16 @@ xmalloc (size_t n) void * xrealloc (void *p, size_t n) { + if (!n && p) + { + /* The GNU and C99 realloc behaviors disagree here. Act like + GNU, even if the underlying realloc is C99. */ + free (p); + return NULL; + } + p = realloc (p, n); - if (!p && n != 0) + if (!p && n) xalloc_die (); return p; }