void error ();
#endif
+static VOID *
+fixup_null_alloc (n)
+ size_t n;
+{
+ VOID *p;
+
+ p = 0;
+ if (n == 0)
+ p = malloc ((size_t) 1);
+ if (p == 0)
+ error (xmalloc_exit_failure, 0, "memory exhausted");
+ return p;
+}
+
/* Allocate N bytes of memory dynamically, with error checking. */
VOID *
p = malloc (n);
if (p == 0)
- error (xmalloc_exit_failure, 0, "memory exhausted");
+ p = fixup_null_alloc (n);
return p;
}
/* Change the size of an allocated block of memory P to N bytes,
with error checking.
- If P is NULL, run xmalloc.
- If N is 0, run free and return NULL. */
+ If P is NULL, run xmalloc. */
VOID *
xrealloc (p, n)
{
if (p == 0)
return xmalloc (n);
- if (n == 0)
- {
- free (p);
- return 0;
- }
p = realloc (p, n);
if (p == 0)
- error (xmalloc_exit_failure, 0, "memory exhausted");
+ p = fixup_null_alloc (n);
return p;
}