1  /* { dg-additional-options "-Wno-analyzer-too-complex" } */
       2  
       3  #define NULL ((void *)0)
       4  
       5  extern int printf (const char *__restrict __format, ...);
       6  extern int vasprintf (char **__restrict __ptr, const char *__restrict __f,
       7  		      __builtin_va_list __arg)
       8    __attribute__ ((__nothrow__, __format__ (__printf__, 2, 0))) ;
       9  extern void free (void *__ptr) __attribute__ ((__nothrow__ , __leaf__));
      10  
      11  static char * __attribute__ ((__format__ (__printf__, 1, 2)))
      12  zasprintf (const char *format, ...)
      13  {
      14    char *resultp;
      15    __builtin_va_list args;
      16    __builtin_va_start (args, format);
      17    int r = vasprintf (&resultp, format, args);
      18    __builtin_va_end (args);
      19    return r < 0 ? NULL : resultp;
      20  }
      21  
      22  int run_test() {
      23      char *buf = NULL;
      24      char *bar = NULL;
      25      char *baz = NULL;
      26      int i = 1232;
      27  
      28      printf("static function check\n");
      29  
      30      buf = zasprintf("i = %d", i);
      31      if (buf) {
      32          printf("buf = %s\nbuf = %p\n", buf, buf);
      33      }
      34  
      35      bar = zasprintf("i = %d - %d", i, i - 13);
      36      if (bar) {
      37          printf("bar = %s\nbar = %p\n", bar, bar);
      38          printf("buf = %s\nbuf = %p\n", buf, buf);
      39      }
      40  
      41      baz = zasprintf("No i's here");
      42      if (baz) {
      43          printf("baz = %s\nbaz = %p\n", baz, baz);
      44          printf("bar = %s\nbar = %p\n", bar, bar);
      45          printf("buf = %s\nbuf = %p\n", buf, buf);
      46      }
      47  
      48      free(buf);
      49      free(bar);
      50      free(baz);
      51  
      52      return 1;
      53  }
      54  
      55  int main(int argc, char **argv) {
      56      return run_test();
      57  }