summaryrefslogtreecommitdiffstats
path: root/tools/test/malloc/main.c
diff options
context:
space:
mode:
authorkbyanc <kbyanc@FreeBSD.org>2002-01-02 06:42:34 +0000
committerkbyanc <kbyanc@FreeBSD.org>2002-01-02 06:42:34 +0000
commited7ec83f0d2f54584f606a9efc352ae506c712d6 (patch)
treef8269378d1f1429251fc72c079e5ae33b2fab0e6 /tools/test/malloc/main.c
parent4138d6fd95e561858b2c915db352cf0c7494103f (diff)
downloadFreeBSD-src-ed7ec83f0d2f54584f606a9efc352ae506c712d6.zip
FreeBSD-src-ed7ec83f0d2f54584f606a9efc352ae506c712d6.tar.gz
Remove broken attempt to compile libc's malloc source directly; this
allows this tool to compile again. Albeit, now to test a new malloc implementation one has to install the new libc which may have bad consequences (i.e. if the new malloc implementation were buggy). Add logic to workaround malloc's current behaviour of returning an invalid non-NULL pointer for 0 byte allocation requests; this prevents the tool from coring during the NOPS loop. Add $FreeBSD$ tags.
Diffstat (limited to 'tools/test/malloc/main.c')
-rw-r--r--tools/test/malloc/main.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/tools/test/malloc/main.c b/tools/test/malloc/main.c
index 4d1d380..2a05029 100644
--- a/tools/test/malloc/main.c
+++ b/tools/test/malloc/main.c
@@ -1,3 +1,4 @@
+/* $FreeBSD$ */
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
@@ -19,7 +20,7 @@ main(int argc, char **argv)
printf("BRK(0)=%x ",sbrk(0));
foo = malloc (sizeof *foo * NBUCKETS);
memset(foo,0,sizeof *foo * NBUCKETS);
- for (i = 1; i <= 4096; i+=i) {
+ for (i = 1; i <= 4096; i *= 2) {
for (j = 0 ; j < 40960/i && j < NBUCKETS; j++) {
foo[j] = malloc(i);
}
@@ -31,8 +32,15 @@ main(int argc, char **argv)
for (i = 0 ; i < NOPS ; i++) {
j = random() % NBUCKETS;
- k = random() % NSIZE;
+ k = random() % NSIZE;
foo[j] = realloc(foo[j], k & 1 ? 0 : k);
+ if (k & 1 || k == 0) {
+ /*
+ * Workaround because realloc return bogus pointer rather than
+ * NULL if passed zero length.
+ */
+ foo[j] = 0;
+ }
if (foo[j])
foo[j][0] = 1;
}
OpenPOWER on IntegriCloud