[PATCH] two-arguments ?:
[smatch.git] / test-sort.c
blobc259e2b64bcd92b258327d4eb816b360813473e2
1 #include "lib.h"
2 #include <stdio.h>
3 #include <stdlib.h>
5 static int
6 int_cmp (const void *_a, const void *_b)
8 const int *a = _a;
9 const int *b = _b;
10 return *a - *b;
13 #define MIN(_x,_y) ((_x) < (_y) ? (_x) : (_y))
15 int
16 main (int argc, char **argv)
18 struct ptr_list *l = NULL, *l2;
19 int i, *e;
20 const int N = argv[1] ? atoi (argv[1]) : 10000;
22 srand (N);
23 for (i = 0; i < 1000; i++)
24 (void)rand ();
26 for (i = 0; i < N; i++) {
27 e = (int *)malloc (sizeof (int));
28 *e = rand ();
29 add_ptr_list (&l, e);
31 sort_list (&l, int_cmp);
32 // Sort already sorted stuff.
33 sort_list (&l, int_cmp);
35 l2 = l;
36 do {
37 l2->nr = MIN (l2->nr, rand () % 3);
38 for (i = 0; i < l2->nr; i++)
39 *((int*)(l2->list[i])) = rand();
40 l2 = l2->next;
41 } while (l2 != l);
42 sort_list (&l, int_cmp);
44 return 0;