From: Andrew Cagney Date: Wed, 16 Apr 2003 14:43:03 +0000 (+0000) Subject: 2003-04-16 Andrew Cagney X-Git-Tag: binutils-2_14-branchpoint~108 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=25d41031648fa41bc108e1a3c6794da69c8bdd0f;p=thirdparty%2Fbinutils-gdb.git 2003-04-16 Andrew Cagney * utils.c (xmmalloc): Always allocate something, matches libiberty/xmalloc's semantics. (xmrealloc, xmcalloc): Ditto. --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index fc874f0b223..ce1361386fb 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,9 @@ +2003-04-16 Andrew Cagney + + * utils.c (xmmalloc): Always allocate something, matches + libiberty/xmalloc's semantics. + (xmrealloc, xmcalloc): Ditto. + 2003-04-16 Andrew Cagney * frame.c (get_prev_frame): Do not initialize "unwind" or "type", diff --git a/gdb/utils.c b/gdb/utils.c index e72aec72a2b..3d820deae0b 100644 --- a/gdb/utils.c +++ b/gdb/utils.c @@ -1073,16 +1073,15 @@ xmmalloc (void *md, size_t size) { void *val; + /* See libiberty/xmalloc.c. This function need's to match that's + semantics. It never returns NULL. */ if (size == 0) - { - val = NULL; - } - else - { - val = mmalloc (md, size); - if (val == NULL) - nomem (size); - } + size = 1; + + val = mmalloc (md, size); + if (val == NULL) + nomem (size); + return (val); } @@ -1091,27 +1090,18 @@ xmrealloc (void *md, void *ptr, size_t size) { void *val; + /* See libiberty/xmalloc.c. This function need's to match that's + semantics. It never returns NULL. */ if (size == 0) - { - if (ptr != NULL) - mfree (md, ptr); - val = NULL; - } + size = 1; + + if (ptr != NULL) + val = mrealloc (md, ptr, size); else - { - if (ptr != NULL) - { - val = mrealloc (md, ptr, size); - } - else - { - val = mmalloc (md, size); - } - if (val == NULL) - { - nomem (size); - } - } + val = mmalloc (md, size); + if (val == NULL) + nomem (size); + return (val); } @@ -1119,14 +1109,19 @@ void * xmcalloc (void *md, size_t number, size_t size) { void *mem; + + /* See libiberty/xmalloc.c. This function need's to match that's + semantics. It never returns NULL. */ if (number == 0 || size == 0) - mem = NULL; - else { - mem = mcalloc (md, number, size); - if (mem == NULL) - nomem (number * size); + number = 1; + size = 1; } + + mem = mcalloc (md, number, size); + if (mem == NULL) + nomem (number * size); + return mem; }