flow: fix struct initialization bug
[smatch.git] / test-sort.c
blob5f176769bbcec04407b72aea60f621782a492bbf
1 #include "lib.h"
2 #include "allocate.h"
3 #include <stdio.h>
4 #include <stdlib.h>
6 static int
7 int_cmp (const void *_a, const void *_b)
9 const int *a = _a;
10 const int *b = _b;
11 return *a - *b;
14 #define MIN(_x,_y) ((_x) < (_y) ? (_x) : (_y))
16 int
17 main (int argc, char **argv)
19 struct ptr_list *l = NULL, *l2;
20 int i, *e;
21 const int N = argv[1] ? atoi (argv[1]) : 10000;
23 srand (N);
24 for (i = 0; i < 1000; i++)
25 (void)rand ();
27 for (i = 0; i < N; i++) {
28 e = (int *)malloc (sizeof (int));
29 *e = rand ();
30 add_ptr_list (&l, e);
32 sort_list (&l, int_cmp);
33 // Sort already sorted stuff.
34 sort_list (&l, int_cmp);
36 l2 = l;
37 do {
38 l2->nr = MIN (l2->nr, rand () % 3);
39 for (i = 0; i < l2->nr; i++)
40 *((int *)(l2->list[i])) = rand();
41 l2 = l2->next;
42 } while (l2 != l);
43 sort_list (&l, int_cmp);
45 return 0;