]> git.proxmox.com Git - rustc.git/blob - src/compiler-rt/test/msan/tsearch.cc
New upstream version 1.19.0+dfsg3
[rustc.git] / src / compiler-rt / test / msan / tsearch.cc
1 // RUN: %clangxx_msan -O0 -g %s -o %t && %run %t
2
3 #include <assert.h>
4 #include <search.h>
5 #include <stdlib.h>
6
7 int compare(const void *pa, const void *pb) {
8 int a = *(const int *)pa;
9 int b = *(const int *)pb;
10 if (a < b)
11 return -1;
12 else if (a > b)
13 return 1;
14 else
15 return 0;
16 }
17
18 void myfreenode(void *p) {
19 delete (int *)p;
20 }
21
22 int main(void) {
23 void *root = NULL;
24 for (int i = 0; i < 5; ++i) {
25 int *p = new int(i);
26 void *q = tsearch(p, &root, compare);
27 if (q == NULL)
28 exit(1);
29 if (*(int **)q != p)
30 delete p;
31 }
32
33 tdestroy(root, myfreenode);
34
35 return 0;
36 }