X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fxmalloc.c;h=3b5f86cdca11571c5326d9833d3597413e3e4425;hb=86627bb14a123f183bd094e582e4cd9f2aca489a;hp=b1f6993e3d603b2905bc4aed3198e8f817ad4563;hpb=34ebad3df7a99eea326f9170f2517b5d23873d1b;p=gnulib.git diff --git a/lib/xmalloc.c b/lib/xmalloc.c index b1f6993e3..3b5f86cdc 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-2012 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; } @@ -113,24 +115,6 @@ xmemdup (void const *p, size_t s) return memcpy (xmalloc (s), p, s); } -/* Clone an object P of size S, with error checking, and include a - terminating NUL byte. - - The terminating NUL makes it safe to use strlen or rawmemchr to - check for embedded NUL; it also speeds up algorithms such as escape - sequence processing on arbitrary memory, by making it always safe - to read the byte after the escape character rather than having to - check if each escape character is the last byte in the object. */ - -void * -xmemdup0 (void const *p, size_t s) -{ - char *result = xcharalloc (s + 1); - memcpy (result, p, s); - result[s] = 0; - return result; -} - /* Clone STRING. */ char *