summaryrefslogtreecommitdiff
path: root/tests/libtest/lib537.c
diff options
context:
space:
mode:
authorYang Tse <yangsita@gmail.com>2006-11-03 10:05:21 +0000
committerYang Tse <yangsita@gmail.com>2006-11-03 10:05:21 +0000
commit78081a1652bce9877f464d97e9780f9e296e293b (patch)
treea4417292b35913b45a880d11efed9a0c67575984 /tests/libtest/lib537.c
parent7408976b158c56034c9e9d739acf41a6d462418e (diff)
downloadcurl-78081a1652bce9877f464d97e9780f9e296e293b.tar.gz
reduce max size of dinamically allocated arrays to minimize the nasty
behaviour some versions of IRIX exhibit of committing suicide on big mallocs instead of just returning a friendly null pointer
Diffstat (limited to 'tests/libtest/lib537.c')
-rw-r--r--tests/libtest/lib537.c22
1 files changed, 19 insertions, 3 deletions
diff --git a/tests/libtest/lib537.c b/tests/libtest/lib537.c
index c9c4dd4f1..08bf1209c 100644
--- a/tests/libtest/lib537.c
+++ b/tests/libtest/lib537.c
@@ -185,11 +185,19 @@ static int rlimit(int keep_open)
* that it becomes available to the test.
*/
- nitems = INT_MAX / sizeof(*memchunk);
+ for (nitems = i = 1; nitems <= i; i *= 2)
+ nitems = i;
+ if (nitems > 0x7fff)
+ nitems = 0x40000;
do {
+ num_open.rlim_max = sizeof(*memchunk) * (size_t)nitems;
+ sprintf(strbuff, fmt, num_open.rlim_max);
+ fprintf(stderr, "allocating memchunk %s byte array\n", strbuff);
memchunk = malloc(sizeof(*memchunk) * (size_t)nitems);
- if (!memchunk)
+ if (!memchunk) {
+ fprintf(stderr, "memchunk, malloc() failed\n");
nitems /= 2;
+ }
} while (nitems && !memchunk);
if (!memchunk) {
store_errmsg("memchunk, malloc() failed", our_errno());
@@ -199,6 +207,8 @@ static int rlimit(int keep_open)
/* initialize it to fight lazy allocation */
+ fprintf(stderr, "initializing memchunk array\n");
+
for (i = 0; i < nitems; i++)
memchunk[i] = -1;
@@ -214,7 +224,11 @@ static int rlimit(int keep_open)
}
else {
/* a huge number of file descriptors */
- num_open.rlim_max = INT_MAX / sizeof(*fd);
+ for (nitems = i = 1; nitems <= i; i *= 2)
+ nitems = i;
+ if (nitems > 0x7fff)
+ nitems = 0x40000;
+ num_open.rlim_max = nitems;
}
/* verify that we won't overflow size_t in malloc() */
@@ -249,6 +263,8 @@ static int rlimit(int keep_open)
/* initialize it to fight lazy allocation */
+ fprintf(stderr, "initializing fd array\n");
+
for (num_open.rlim_cur = 0;
num_open.rlim_cur < num_open.rlim_max;
num_open.rlim_cur++)