From d7fa9de08de666af5647be3053c6b3f04996277b Mon Sep 17 00:00:00 2001 From: Kevin Buettner Date: Sat, 10 Mar 2001 01:22:11 +0000 Subject: [PATCH] Committed. --- gdb/ChangeLog | 4 ++++ gdb/utils.c | 36 ++++++++++++++++++++++++++---------- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index dafb9554b3..97f93bd985 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,7 @@ +2001-03-09 Kevin Buettner + + * utils.c (xmrealloc, xcalloc): Return NULL for zero-sized requests. + 2001-03-09 Andrew Cagney * MAINTAINERS (Write After Approval): Update Philip Blundell. diff --git a/gdb/utils.c b/gdb/utils.c index 5ece78ded4..b81e3fd4c9 100644 --- a/gdb/utils.c +++ b/gdb/utils.c @@ -1044,17 +1044,26 @@ xmrealloc (PTR md, PTR ptr, long size) { register PTR val; - if (ptr != NULL) + if (size == 0) { - val = mrealloc (md, ptr, size); + if (ptr != NULL) + mfree (md, ptr); + val = NULL; } else { - val = mmalloc (md, size); - } - if (val == NULL) - { - nomem (size); + if (ptr != NULL) + { + val = mrealloc (md, ptr, size); + } + else + { + val = mmalloc (md, size); + } + if (val == NULL) + { + nomem (size); + } } return (val); } @@ -1073,9 +1082,16 @@ xmalloc (size_t size) PTR xcalloc (size_t number, size_t size) { - void *mem = mcalloc (NULL, number, size); - if (mem == NULL) - nomem (number * size); + void *mem; + + if (number == 0 || size == 0) + mem = NULL; + else + { + mem = mcalloc (NULL, number, size); + if (mem == NULL) + nomem (number * size); + } return mem; }