summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/regress/lib/libc/malloc/malloc0test.c39
1 files changed, 35 insertions, 4 deletions
diff --git a/src/regress/lib/libc/malloc/malloc0test.c b/src/regress/lib/libc/malloc/malloc0test.c
index 459e42c985..d226af5a28 100644
--- a/src/regress/lib/libc/malloc/malloc0test.c
+++ b/src/regress/lib/libc/malloc/malloc0test.c
@@ -7,6 +7,8 @@
7#include <unistd.h> 7#include <unistd.h>
8#include <stdlib.h> 8#include <stdlib.h>
9#include <setjmp.h> 9#include <setjmp.h>
10#include <limits.h>
11#include <errno.h>
10 12
11volatile sig_atomic_t got; 13volatile sig_atomic_t got;
12jmp_buf jmp; 14jmp_buf jmp;
@@ -59,10 +61,38 @@ main(int argc, char *argv[])
59 caddr_t zblob = malloc(0); 61 caddr_t zblob = malloc(0);
60 caddr_t *blobp, blob; 62 caddr_t *blobp, blob;
61 int size, rsize, tsize; 63 int size, rsize, tsize;
62 int count = 0, prot; 64 int prot;
63 int rval = 0, fuckup = 0; 65 int rval = 0, fuckup = 0;
66 long limit = 200000, count;
67 int ch, silent = 0;
68 char *ep;
69 extern char *__progname;
64 70
65 while (1) { 71 while ((ch = getopt(argc, argv, "sn:")) != -1) {
72 switch (ch) {
73 case 's':
74 silent = 1;
75 break;
76 case 'n':
77 errno = 0;
78 limit = strtol(optarg, &ep, 10);
79 if (optarg[0] == '\0' || *ep != '\0' ||
80 (errno == ERANGE &&
81 (limit == LONG_MAX || limit == LONG_MIN)))
82 goto usage;
83 break;
84 default:
85usage:
86 fprintf(stderr, "Usage: %s [-s][-n <count>]\n",
87 __progname);
88 exit(1);
89 }
90 }
91
92 if (limit == 0)
93 limit = LONG_MAX;
94
95 for (count = 0; count < limit; count++) {
66 size = arc4random() % SIZE; 96 size = arc4random() % SIZE;
67 blob = malloc(size); 97 blob = malloc(size);
68 if (blob == NULL) { 98 if (blob == NULL) {
@@ -94,8 +124,9 @@ main(int argc, char *argv[])
94 } 124 }
95 *blobp = blob; 125 *blobp = blob;
96 126
97 127 if (!silent && count % 100000 == 0 && count != 0)
98 if (++count % 100000 == 0)
99 fprintf(stderr, "count = %d\n", count); 128 fprintf(stderr, "count = %d\n", count);
100 } 129 }
130
131 return rval;
101} \ No newline at end of file 132} \ No newline at end of file