+2001-03-09 Kevin Buettner <kevinb@redhat.com>
+
+ * utils.c (xmrealloc, xcalloc): Return NULL for zero-sized requests.
+
2001-03-09 Andrew Cagney <ac131313@redhat.com>
* MAINTAINERS (Write After Approval): Update Philip Blundell.
{
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);
}
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;
}