mirror of
https://github.com/moparisthebest/curl
synced 2024-12-22 08:08:50 -05:00
Fixed test 1309 to pass the torture test
Removing dynamic allocations also simplifies the test.
This commit is contained in:
parent
c4dd8df081
commit
b688f2c260
@ -70,25 +70,20 @@ UNITTEST_START
|
|||||||
/* number of nodes to add to the splay tree */
|
/* number of nodes to add to the splay tree */
|
||||||
#define NUM_NODES 50
|
#define NUM_NODES 50
|
||||||
|
|
||||||
struct Curl_tree *root, *t;
|
struct Curl_tree *root;
|
||||||
void *ptrs[NUM_NODES];
|
struct Curl_tree nodes[NUM_NODES];
|
||||||
int rc;
|
int rc;
|
||||||
int i;
|
int i;
|
||||||
root = NULL; /* the empty tree */
|
root = NULL; /* the empty tree */
|
||||||
|
|
||||||
for(i = 0; i < NUM_NODES; i++) {
|
for(i = 0; i < NUM_NODES; i++) {
|
||||||
struct timeval key;
|
struct timeval key;
|
||||||
ptrs[i] = t = malloc(sizeof(struct Curl_tree));
|
|
||||||
if(!t) {
|
|
||||||
puts("out of memory!");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
key.tv_sec = 0;
|
key.tv_sec = 0;
|
||||||
key.tv_usec = (541*i)%1023;
|
key.tv_usec = (541*i)%1023;
|
||||||
|
|
||||||
t->payload = (void *)key.tv_usec; /* for simplicity */
|
nodes[i].payload = (void *)key.tv_usec; /* for simplicity */
|
||||||
root = Curl_splayinsert(key, root, t);
|
root = Curl_splayinsert(key, root, &nodes[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
puts("Result:");
|
puts("Result:");
|
||||||
@ -99,11 +94,13 @@ UNITTEST_START
|
|||||||
printf("Tree look:\n");
|
printf("Tree look:\n");
|
||||||
splayprint(root, 0, 1);
|
splayprint(root, 0, 1);
|
||||||
printf("remove pointer %d, payload %ld\n", rem,
|
printf("remove pointer %d, payload %ld\n", rem,
|
||||||
(long)((struct Curl_tree *)ptrs[rem])->payload);
|
(long)(nodes[rem].payload));
|
||||||
rc = Curl_splayremovebyaddr(root, (struct Curl_tree *)ptrs[rem], &root);
|
rc = Curl_splayremovebyaddr(root, &nodes[rem], &root);
|
||||||
if(rc)
|
if(rc) {
|
||||||
/* failed! */
|
/* failed! */
|
||||||
printf("remove %d failed!\n", rem);
|
printf("remove %d failed!\n", rem);
|
||||||
|
fail("remove");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
UNITTEST_STOP
|
UNITTEST_STOP
|
||||||
|
Loading…
Reference in New Issue
Block a user