1  /* { dg-skip-if "no strndup in libc" { *-*-darwin[789]* *-*-darwin10* *-*-mingw* *-*-vxworks* } } */
       2  
       3  #include <string.h>
       4  #include <stdlib.h>
       5  
       6  extern void requires_nonnull (void *ptr)
       7    __attribute__((nonnull));
       8  
       9  void test_1 (const char *s)
      10  {
      11    char *p = strndup (s, 42); /* { dg-message "allocated here" } */
      12  } /* { dg-warning "leak of 'p'" } */
      13  
      14  void test_2 (const char *s)
      15  {
      16    char *p = strndup (s, 42);
      17    free (p);
      18  }
      19  void test_3 (const char *s)
      20  {
      21    char *p = strndup (s, 42); /* { dg-message "this call could return NULL" } */
      22    requires_nonnull (p); /* { dg-warning "use of possibly-NULL 'p'" } */
      23  }