aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/analyzer/attr-malloc-2.c
blob: 09d941fe082064c67395ff5cf6ed7d4e25447cd2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
extern void free (void *);
char *xstrdup (const char *)
  __attribute__((malloc (free), returns_nonnull));

void test_1 (const char *s)
{
  char *p = xstrdup (s);
  free (p);
}

/* Verify that we don't issue -Wanalyzer-possible-null-dereference
   when the allocator has __attribute__((returns_nonnull)).  */

char *test_2 (const char *s)
{
  char *p = xstrdup (s);
  p[0] = 'a'; /* { dg-bogus "possibly-NULL" } */
  return p;
}

void test_3 (const char *s)
{
  char *p = xstrdup (s); /* { dg-message "allocated here" } */
} /* { dg-warning "leak of 'p'" } */