blob: 9ac3921af21271f5d2ea4173c8f40adae8877fab (
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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
#include <string.h>
#include <stdlib.h>
extern void requires_nonnull (void *ptr)
__attribute__((nonnull));
void test_1 (const char *s)
{
char *p = strdup (s); /* { dg-message "allocated here" } */
} /* { dg-warning "leak of 'p'" } */
void test_2 (const char *s)
{
char *p = strdup (s);
free (p);
}
void test_3 (const char *s)
{
char *p = strdup (s); /* { dg-message "this call could return NULL" } */
requires_nonnull (p); /* { dg-warning "use of possibly-NULL 'p'" } */
}
/* Repeat tests for __builtin_strdup. */
void test_4 (const char *s)
{
char *p = __builtin_strdup (s); /* { dg-message "allocated here" } */
} /* { dg-warning "leak of 'p'" } */
void test_5 (const char *s)
{
char *p = __builtin_strdup (s);
free (p);
}
void test_6 (const char *s)
{
char *p = __builtin_strdup (s); /* { dg-message "this call could return NULL" } */
requires_nonnull (p); /* { dg-warning "use of possibly-NULL 'p'" } */
}
|