(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.dg/
analyzer/
pr103217-3.c
       1  /* { dg-additional-options "-Wno-analyzer-too-complex" } */
       2  
       3  extern char *strdup (const char *__s)
       4    __attribute__ ((__nothrow__ , __leaf__, __malloc__, __nonnull__ (1)));
       5  
       6  extern void abort (void)
       7    __attribute__ ((__nothrow__ , __leaf__, __noreturn__));
       8  
       9  extern int getopt (int ___argc, char *const *___argv, const char *__shortopts)
      10    __attribute__ ((__nothrow__ , __leaf__, __nonnull__ (2, 3)));
      11  extern char *optarg;
      12  
      13  extern void free (void *__ptr)
      14    __attribute__ ((__nothrow__ , __leaf__));
      15  
      16  struct state {
      17    const char *confpath;
      18    const char *host;
      19    const char *port;
      20    const char *state_dir_prefix;
      21  };
      22  
      23  static inline char *xstrdup(const char *s) { 
      24          char *val = strdup(s);
      25          if (!val)
      26                  abort();
      27          return val;
      28  }
      29  
      30  int config_init(struct state *config);
      31  
      32  int main(int argc, char *argv[]) { 
      33          int rc;
      34          struct state state = { 0 };
      35  
      36          config_init(&state);
      37  
      38          while ((rc = getopt(argc, argv, "H:p:")) != -1) { 
      39                  switch (rc) { 
      40                  case 'H':
      41                          free((void*)state.host);
      42                          state.host = xstrdup(optarg);
      43                          break;
      44                  case 'p':
      45                          free((void*)state.port);
      46                          state.port = xstrdup(optarg);
      47                          break;
      48                  } 
      49          } 
      50  
      51          free((void*)state.host);
      52          free((void*)state.port);
      53          return rc;
      54  }