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 compare(const void * pa,const void * pb)7int 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 myfreenode(void * p)18void myfreenode(void *p) { 19 delete (int *)p; 20 } 21 main(void)22int 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 } 37