Hi,
The xmalloc and xrealloc functions defined in lib/xmalloc.c expect live
pointers to be always returned form system's malloc and realloc
function. This is an invalid assumption for most (all?) libc
implementations including glibc in realloc [1], and an invalid
assumption for many libc's like uClibc in malloc.
The patch I include makes xmalloc/xrealloc behave the same way whatever
we decide to use system's malloc/realloc or glibc's ones (maybe with
help of rpl_malloc/rpl_realloc) doing boundary checking and out of
memory checking when this makes sense (i.e. when we request a positive
amount of memory).
[1] form man 3 malloc: realloc() .... if size is equal to zero,
the call is equivalent to free(ptr). ...
Yuri.
PS: please CC me on replays as I'm not subscribed to the list.
--- diffutils-2.8.7.orig/lib/xmalloc.c 2003-11-22 15:07:36 +0000
+++ diffutils-2.8.7/lib/xmalloc.c 2005-08-27 05:16:39 +0000
@@ -70,8 +70,8 @@
static inline void *
xnmalloc_inline (size_t n, size_t s)
{
- void *p;
- if (xalloc_oversized (n, s) || ! (p = malloc (n * s)))
+ void *p = NULL;
+ if (xalloc_oversized (n, s) || ! ((n * s == 0) || (p = malloc (n * s))))
xalloc_die ();
return p;
}
@@ -96,7 +96,7 @@
static inline void *
xnrealloc_inline (void *p, size_t n, size_t s)
{
- if (xalloc_oversized (n, s) || ! (p = realloc (p, n * s)))
+ if (xalloc_oversized (n, s) || ! ((p = realloc (p, n * s)) || (n * s == 0)))
xalloc_die ();
return p;
}
_______________________________________________
bug-gnulib mailing list
bug-gnulib@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-gnulib