blob: 58223533b5da3f51c88d1d5a6d1f24313b35ce13 [file] [log] [blame]
/* { dg-skip-if "no strndup in libc" { *-*-darwin[789]* *-*-darwin10* } } */
#include <string.h>
#include <stdlib.h>
extern void requires_nonnull (void *ptr)
__attribute__((nonnull));
void test_1 (const char *s)
{
char *p = strndup (s, 42); /* { dg-message "allocated here" } */
} /* { dg-warning "leak of 'p'" } */
void test_2 (const char *s)
{
char *p = strndup (s, 42);
free (p);
}
void test_3 (const char *s)
{
char *p = strndup (s, 42); /* { dg-message "this call could return NULL" } */
requires_nonnull (p); /* { dg-warning "use of possibly-NULL 'p'" } */
}