fix up botch() debug code
SCCS-vsn: lib/libc/stdlib/malloc.c 5.4
-static char sccsid[] = "@(#)malloc.c 5.3 (Berkeley) %G%";
+static char sccsid[] = "@(#)malloc.c 5.4 (Berkeley) %G%";
#include <stdio.h>
#endif
#include <stdio.h>
#endif
+#if defined(DEBUG) || defined(RCHECK)
#define ASSERT(p) if (!(p)) botch("p")
#define ASSERT(p) if (!(p)) botch("p")
static
botch(s)
char *s;
{
static
botch(s)
char *s;
{
-
- printf("assertion botched: %s\n", s);
+ fprintf(stderr, "\r\nassertion botched: %s\r\n", s);
+ (void) fflush(stderr); /* just in case user buffered it */
* the last ``realloc_srchlen'' items free'd.
* If all lookups fail, then assume the size of
* the memory block being realloc'd is the
* the last ``realloc_srchlen'' items free'd.
* If all lookups fail, then assume the size of
* the memory block being realloc'd is the
+ * largest possible (so that all "nbytes" of new
+ * memory are copied into). Note that this could cause
+ * a memory fault if the old area was tiny, and the moon
+ * is gibbous. However, that is very unlikely.
*/
if ((i = findbucket(op, 1)) < 0 &&
(i = findbucket(op, realloc_srchlen)) < 0)
*/
if ((i = findbucket(op, 1)) < 0 &&
(i = findbucket(op, realloc_srchlen)) < 0)
-#ifndef RCHECK
- i = 0;
-#else
- i = 1; /* smallest possible w/ RCHECK */
-#endif
}
onb = 1 << (i + 3);
if (onb < pagesz)
}
onb = 1 << (i + 3);
if (onb < pagesz)
}
if ((res = malloc(nbytes)) == NULL)
return (NULL);
}
if ((res = malloc(nbytes)) == NULL)
return (NULL);
- if (cp != res) /* common optimization */
+ if (cp != res) /* common optimization if "compacting" */
bcopy(cp, res, (nbytes < onb) ? nbytes : onb);
return (res);
}
bcopy(cp, res, (nbytes < onb) ? nbytes : onb);
return (res);
}