1  /* { dg-additional-options "-fanalyzer-call-summaries -Wno-analyzer-too-complex" } */
       2  
       3  typedef __SIZE_TYPE__ size_t;
       4  typedef struct _IO_FILE FILE;
       5  extern char *fgets(char *__restrict __s, int __n, FILE *__restrict __stream)
       6      __attribute__((__access__(__write_only__, 1, 2)));
       7  extern void perror(const char *__s);
       8  enum {
       9    _ISspace = ((5) < 8 ? ((1 << (5)) << 8) : ((1 << (5)) >> 8)),
      10  };
      11  extern const unsigned short int **__ctype_b_loc(void)
      12      __attribute__((__nothrow__, __leaf__)) __attribute__((__const__));
      13  extern void *malloc(size_t __size) __attribute__((__nothrow__, __leaf__))
      14  __attribute__((__malloc__)) __attribute__((__alloc_size__(1)));
      15  extern void exit(int __status) __attribute__((__nothrow__, __leaf__))
      16  __attribute__((__noreturn__));
      17  extern char *strcpy(char *__restrict __dest, const char *__restrict __src)
      18      __attribute__((__nothrow__, __leaf__)) __attribute__((__nonnull__(1, 2)));
      19  extern size_t strlen(const char *__s) __attribute__((__nothrow__, __leaf__))
      20  __attribute__((__pure__)) __attribute__((__nonnull__(1)));
      21  
      22  struct mydata {
      23    struct mydata *link;
      24    char *name;
      25    char *type;
      26  };
      27  
      28  static struct mydata *all_data;
      29  static int line_no;
      30  
      31  _Noreturn static void failed(const char *message) {
      32    perror(message);
      33    exit(1);
      34  }
      35  
      36  static char *string_dup(const char *string) {
      37    char *buf;
      38  
      39    if ((buf = malloc(strlen(string) + 1)) == ((void *)0))
      40      failed("malloc() failed");
      41  
      42    return strcpy(buf, string);
      43  }
      44  
      45  static void store_data(const char *name, const char *type) {
      46    struct mydata *p, *q;
      47  
      48    if ((p = (struct mydata *)malloc(sizeof(struct mydata))) == ((void *)0))
      49      failed("malloc() failed");
      50  
      51    p->link = ((void *)0);
      52    p->name = string_dup(name);
      53    p->type = string_dup(type);
      54  
      55    if ((q = all_data) == ((void *)0))
      56      all_data = p;
      57    else {
      58      while (q->link != ((void *)0))
      59        q = q->link;
      60      q->link = p;
      61    }
      62  }
      63  
      64  static void parse_tbl(char *buffer) {
      65    char *s = buffer;
      66    char *t = s + strlen(s);
      67  
      68    do {
      69      t--;
      70      if (((*__ctype_b_loc())[(int)(((int)*t))] & (unsigned short int)_ISspace))
      71        *t = '\0';
      72      else
      73        break;
      74    } while (t > s);
      75    while (((*__ctype_b_loc())[(int)(((int)*s))] & (unsigned short int)_ISspace))
      76      s++;
      77    buffer = s;
      78  
      79    line_no++;
      80    if (*buffer != ';' && *buffer != '\0') {
      81      if (*buffer == '#') {
      82        store_data(buffer, ""); /* { dg-bogus "leak" "PR analyzer/107158" { xfail *-*-* } } */
      83      } else {
      84  
      85        while (*s && !((*__ctype_b_loc())[(int)(((int)*s))] &
      86                       (unsigned short int)_ISspace))
      87          s++;
      88        while (
      89            ((*__ctype_b_loc())[(int)(((int)*s))] & (unsigned short int)_ISspace))
      90          *s++ = '\0';
      91        store_data(buffer, s); /* { dg-bogus "leak" "PR analyzer/107158" { xfail *-*-* } } */
      92      }
      93    }
      94  }
      95  
      96  /* [...snip...] */
      97  
      98  static void makecfg(FILE *ifp, FILE *ofp, FILE *ofp2) {
      99    char buffer[8192];
     100  
     101    /* [...snip...] */
     102  
     103    line_no = 0;
     104    while (fgets(buffer, sizeof(buffer) - 1, ifp))
     105      parse_tbl(buffer);
     106  
     107    /* [...snip...] */
     108  }