2003-04-16 Andrew Cagney <cagney@redhat.com>

* utils.c (xmmalloc): Always allocate something, matches
	libiberty/xmalloc's semantics.
	(xmrealloc, xmcalloc): Ditto.
This commit is contained in:
Andrew Cagney 2003-04-16 14:43:03 +00:00
parent c50901fda0
commit 25d4103164
2 changed files with 34 additions and 33 deletions

View file

@ -1,3 +1,9 @@
2003-04-16 Andrew Cagney <cagney@redhat.com>
* utils.c (xmmalloc): Always allocate something, matches
libiberty/xmalloc's semantics.
(xmrealloc, xmcalloc): Ditto.
2003-04-16 Andrew Cagney <cagney@redhat.com> 2003-04-16 Andrew Cagney <cagney@redhat.com>
* frame.c (get_prev_frame): Do not initialize "unwind" or "type", * frame.c (get_prev_frame): Do not initialize "unwind" or "type",

View file

@ -1073,16 +1073,15 @@ xmmalloc (void *md, size_t size)
{ {
void *val; void *val;
/* See libiberty/xmalloc.c. This function need's to match that's
semantics. It never returns NULL. */
if (size == 0) if (size == 0)
{ size = 1;
val = NULL;
} val = mmalloc (md, size);
else if (val == NULL)
{ nomem (size);
val = mmalloc (md, size);
if (val == NULL)
nomem (size);
}
return (val); return (val);
} }
@ -1091,27 +1090,18 @@ xmrealloc (void *md, void *ptr, size_t size)
{ {
void *val; void *val;
/* See libiberty/xmalloc.c. This function need's to match that's
semantics. It never returns NULL. */
if (size == 0) if (size == 0)
{ size = 1;
if (ptr != NULL)
mfree (md, ptr); if (ptr != NULL)
val = NULL; val = mrealloc (md, ptr, size);
}
else else
{ val = mmalloc (md, size);
if (ptr != NULL) if (val == NULL)
{ nomem (size);
val = mrealloc (md, ptr, size);
}
else
{
val = mmalloc (md, size);
}
if (val == NULL)
{
nomem (size);
}
}
return (val); return (val);
} }
@ -1119,14 +1109,19 @@ void *
xmcalloc (void *md, size_t number, size_t size) xmcalloc (void *md, size_t number, size_t size)
{ {
void *mem; void *mem;
/* See libiberty/xmalloc.c. This function need's to match that's
semantics. It never returns NULL. */
if (number == 0 || size == 0) if (number == 0 || size == 0)
mem = NULL;
else
{ {
mem = mcalloc (md, number, size); number = 1;
if (mem == NULL) size = 1;
nomem (number * size);
} }
mem = mcalloc (md, number, size);
if (mem == NULL)
nomem (number * size);
return mem; return mem;
} }