Debian Codegraph @

gcc/testsuite/c-c++-common/analyzer/pr110830.c

raw
1 typedef __SIZE_TYPE__ size_t;
2
3 void free(void *);
4 void *malloc(__SIZE_TYPE__);
5
6 extern int ext();
7
8 void test_supersedes ()
9 {
10 int *p = (int *)malloc(sizeof(int));
11 free(p);
12 int x = *p + 4; /* { dg-warning "use after 'free' of 'p'" } */
13 /* { dg-bogus "use of uninitialized value '\\*p" "" { target *-*-* } .-1 } */
14 }
15
16 int *called_by_test0()
17 {
18 int *p = 0;
19 if (ext())
20 {
21 p = (int *)malloc(sizeof(int));
22 free(p);
23 return p;
24 }
25 else
26 return (int *)malloc(sizeof(int));
27 }
28
29 void test0()
30 {
31 int *y = called_by_test0();
32 int x = 0;
33 if (y != 0)
34 x = *y; /* { dg-warning "use after 'free' of 'y'" } */
35 /* { dg-warning "use of uninitialized value '\\*y'" "don't supersede warnings with incompatible cfg path" { target *-*-* } .-1 } */
36 free(y); /* { dg-warning "double-'free'" } */
37 }
38
39 void test1()
40 {
41 int *p = 0;
42 if (ext())
43 {
44 p = (int *)malloc(sizeof(int));
45 free(p);
46 }
47 else
48 p = (int *)malloc(sizeof(int));
49
50 int x = 0;
51 if (p != 0)
52 x = *p; /* { dg-warning "use after 'free' of 'p'" } */
53 /* { dg-warning "use of uninitialized value '\\*p'" "don't supersede warnings with incompatible cfg path" { target *-*-* } .-1 } */
54 free(p); /* { dg-warning "double-'free'" } */
55 }
56
57 void test2()
58 {
59 int *p = 0;
60 p = (int *)malloc(sizeof(int));
61 if (ext())
62 free(p);
63
64 int x = 0;
65 if (p != 0)
66 x = *p; /* { dg-warning "use after 'free' of 'p'" } */
67 /* { dg-warning "use of uninitialized value '\\*p'" "don't supersede warnings with incompatible cfg path" { target *-*-* } .-1 } */
68 free(p); /* { dg-warning "double-'free'" } */
69 }
70
71 void test3()
72 {
73 int *p = 0;
74 p = (int *)malloc(sizeof(int));
75 int i = 100;
76 while (i--)
77 {
78 int x = 0;
79 if (p != 0)
80 x = *p; /* { dg-warning "use after 'free' of 'p'" } */
81 /* { dg-warning "use of uninitialized value '\\*p'" "don't supersede warnings with incompatible cfg path" { target *-*-* } .-1 } */
82 p = (int *)malloc(sizeof(int));
83 free(p);
84 }
85
86 free(p); /* { dg-warning "double-'free'" } */
87 }
88
89
90 void test4()
91 {
92 int *p = 0;
93 if (ext())
94 {
95 p = (int *) malloc(sizeof(int));
96 if (ext () > 5)
97 {
98 mal:
99 free (p);
100 }
101 }
102 else {
103 goto mal;
104 }
105
106 int x = 0;
107 if (p != 0)
108 x = *p; /* { dg-warning "use after 'free' of 'p'" } */
109 /* { dg-warning "use of uninitialized value '\\*p'" "" { target *-*-* } .-1 } */
110 free(p); /* { dg-warning "double-'free'" } */
111 }