(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.dg/
analyzer/
pr104029.c
       1  // TODO: remove need for this option
       2  /* { dg-additional-options "-fanalyzer-checker=taint" } */
       3  
       4  typedef __SIZE_TYPE__ size_t;
       5  typedef const void *t_comptype;
       6  typedef int (*t_compfunc)(t_comptype, t_comptype);
       7  
       8  extern int *__errno_location(void)
       9    __attribute__((__nothrow__, __leaf__,__const__));
      10  extern void free(void *__ptr)
      11    __attribute__((__nothrow__, __leaf__));
      12  extern void *my_malloc1(const char *file, int line, size_t size);
      13  
      14  int heapsort(void *vbase, size_t nmemb, size_t size, t_compfunc compar) {
      15    char tmp, *tmp1, *tmp2, *abase, *k, *p, *t;
      16    size_t cnt, i, j, l;
      17  
      18    if (nmemb <= 1)
      19      return (0);
      20  
      21    if (!size) {
      22      (*__errno_location()) = 22;
      23      return (-1);
      24    }
      25  
      26    k = my_malloc1(__FILE__, __LINE__, size);
      27  
      28    abase = (char *)vbase - size;
      29  
      30    for (l = nmemb / 2 + 1; --l;) {
      31      for (i = l; (j = i * 2) <= nmemb; i = j) {
      32        p = abase + j * size;
      33        if (j < nmemb && compar(p, p + size) < 0) {
      34          p += size;
      35          ++j;
      36        }
      37        t = abase + i * size;
      38        if (compar(p, t) <= 0)
      39          break;
      40        {
      41          cnt = size;
      42          do {
      43            tmp = *t;
      44            *t++ = *p;
      45            *p++ = tmp;
      46          } while (--cnt);
      47        };
      48      }
      49    };
      50  
      51    while (nmemb > 1) {
      52      {
      53        cnt = size;
      54        tmp1 = k;
      55        tmp2 = abase + nmemb * size;
      56        do {
      57          *tmp1++ = *tmp2++;
      58        } while (--cnt);
      59      };
      60      {
      61        cnt = size;
      62        tmp1 = abase + nmemb * size;
      63        tmp2 = abase + size;
      64        do {
      65          *tmp1++ = *tmp2++;
      66        } while (--cnt);
      67      };
      68      --nmemb;
      69      {
      70        for (i = 1; (j = i * 2) <= nmemb; i = j) {
      71          p = abase + j * size;
      72          if (j < nmemb && compar(p, p + size) < 0) {
      73            p += size;
      74            ++j;
      75          }
      76          t = abase + i * size;
      77          {
      78            cnt = size;
      79            tmp1 = t;
      80            tmp2 = p;
      81            do {
      82              *tmp1++ = *tmp2++;
      83            } while (--cnt);
      84          };
      85        }
      86        for (;;) {
      87          j = i;
      88          i = j / 2;
      89          p = abase + j * size;
      90          t = abase + i * size;
      91          if (j == 1 || compar(k, t) < 0) {
      92            {
      93              cnt = size;
      94              tmp1 = p;
      95              tmp2 = k;
      96              do {
      97                *tmp1++ = *tmp2++;
      98              } while (--cnt);
      99            };
     100            break;
     101          }
     102          {
     103            cnt = size;
     104            tmp1 = p;
     105            tmp2 = t;
     106            do {
     107              *tmp1++ = *tmp2++;
     108            } while (--cnt);
     109          };
     110        }
     111      };
     112    }
     113    free(k);
     114    return (0);
     115  }