summaryrefslogtreecommitdiffstats
path: root/tools/test/malloc
diff options
context:
space:
mode:
Diffstat (limited to 'tools/test/malloc')
-rw-r--r--tools/test/malloc/Makefile1
-rw-r--r--tools/test/malloc/main.c29
2 files changed, 16 insertions, 14 deletions
diff --git a/tools/test/malloc/Makefile b/tools/test/malloc/Makefile
index 7d60670..2f00c34 100644
--- a/tools/test/malloc/Makefile
+++ b/tools/test/malloc/Makefile
@@ -4,6 +4,7 @@ SRCS= main.c
.PATH: ${.CURDIR}/../../../lib/libc/stdlib
NO_MAN=
+WARNS?=6
test: malloc
@echo
diff --git a/tools/test/malloc/main.c b/tools/test/malloc/main.c
index 2a05029..5fef9a9 100644
--- a/tools/test/malloc/main.c
+++ b/tools/test/malloc/main.c
@@ -1,6 +1,7 @@
/* $FreeBSD$ */
#include <stdlib.h>
#include <stdio.h>
+#include <string.h>
#include <unistd.h>
u_long NBUCKETS = 2000;
@@ -12,25 +13,25 @@ char **foo;
int
main(int argc, char **argv)
{
- int i,j,k;
+ u_long i,j,k;
if (argc > 1) NOPS = strtoul(argv[1],0,0);
if (argc > 2) NBUCKETS = strtoul(argv[2],0,0);
if (argc > 3) NSIZE = strtoul(argv[3],0,0);
- printf("BRK(0)=%x ",sbrk(0));
- foo = malloc (sizeof *foo * NBUCKETS);
- memset(foo,0,sizeof *foo * NBUCKETS);
+ printf("BRK(0)=%p ", sbrk(0));
+ foo = malloc(sizeof(*foo) * NBUCKETS);
+ memset(foo, 0, sizeof(*foo) * NBUCKETS);
for (i = 1; i <= 4096; i *= 2) {
- for (j = 0 ; j < 40960/i && j < NBUCKETS; j++) {
+ for (j = 0; j < 40960/i && j < NBUCKETS; j++) {
foo[j] = malloc(i);
}
- for (j = 0 ; j < 40960/i && j < NBUCKETS; j++) {
+ for (j = 0; j < 40960/i && j < NBUCKETS; j++) {
free(foo[j]);
- foo[j] = 0;
+ foo[j] = NULL;
}
}
- for (i = 0 ; i < NOPS ; i++) {
+ for (i = 0; i < NOPS; i++) {
j = random() % NBUCKETS;
k = random() % NSIZE;
foo[j] = realloc(foo[j], k & 1 ? 0 : k);
@@ -39,19 +40,19 @@ main(int argc, char **argv)
* Workaround because realloc return bogus pointer rather than
* NULL if passed zero length.
*/
- foo[j] = 0;
+ foo[j] = NULL;
}
if (foo[j])
foo[j][0] = 1;
}
- printf("BRK(1)=%x ",sbrk(0));
- for (j = 0 ; j < NBUCKETS ; j++) {
+ printf("BRK(1)=%p ", sbrk(0));
+ for (j = 0; j < NBUCKETS; j++) {
if (foo[j]) {
free(foo[j]);
- foo[j] = 0;
+ foo[j] = NULL;
}
}
- printf("BRK(2)=%x NOPS=%lu NBUCKETS=%lu NSIZE=%lu\n",
- sbrk(0),NOPS,NBUCKETS,NSIZE);
+ printf("BRK(2)=%p NOPS=%lu NBUCKETS=%lu NSIZE=%lu\n",
+ sbrk(0), NOPS, NBUCKETS, NSIZE);
return 0;
}
OpenPOWER on IntegriCloud