1 // RUN: %clang_analyze_cc1 -analyzer-checker=core,unix.Malloc -analyzer-max-loop 4 -verify %s
2 #include "Inputs/system-header-simulator.h"
4 typedef __typeof(sizeof(int)) size_t;
7 static int another_function(int *y
) {
13 static void function_which_doesnt_give_up(int **x
) {
17 static void function_which_gives_up(int *x
) {
18 for (int i
= 0; i
< 5; ++i
)
22 static void function_which_gives_up_nested(int *x
) {
23 function_which_gives_up(x
);
24 for (int i
= 0; i
< 5; ++i
)
28 static void function_which_doesnt_give_up_nested(int *x
, int *y
) {
29 *y
= another_function(x
);
30 function_which_gives_up(x
);
33 void coverage1(int *x
) {
34 function_which_gives_up(x
);
35 char *m
= (char*)malloc(12);
36 } // expected-warning {{Potential leak of memory pointed to by 'm'}}
38 void coverage2(int *x
) {
40 function_which_gives_up(x
);
41 char *m
= (char*)malloc(12);
43 } // expected-warning {{Potential leak of memory pointed to by 'm'}}
45 void coverage3(int *x
) {
47 function_which_gives_up(x
);
48 char *m
= (char*)malloc(12);
49 } // expected-warning {{Potential leak of memory pointed to by 'm'}}
51 void coverage4(int *x
) {
52 *x
+= another_function(x
);
53 function_which_gives_up(x
);
54 char *m
= (char*)malloc(12);
55 } // expected-warning {{Potential leak of memory pointed to by 'm'}}
57 void coverage5(int *x
) {
58 for (int i
= 0; i
<7; ++i
)
59 function_which_gives_up(x
);
60 // The root function gives up here.
61 char *m
= (char*)malloc(12); // no-warning
64 void coverage6(int *x
) {
65 for (int i
= 0; i
<3; ++i
) {
66 function_which_gives_up(x
);
68 char *m
= (char*)malloc(12);
69 } // expected-warning {{Potential leak of memory pointed to by 'm'}}
71 int coverage7_inline(int *i
) {
72 function_which_doesnt_give_up(&i
);
73 return *i
; // expected-warning {{Dereference}}
76 void coverage8(int *x
) {
78 function_which_doesnt_give_up_nested(x
, &y
);
79 y
= (*x
)/y
; // expected-warning {{Division by zero}}
80 char *m
= (char*)malloc(12);
81 } // expected-warning {{Potential leak of memory pointed to by 'm'}}
83 void function_which_gives_up_settonull(int **x
) {
86 for (int i
= 0; i
< 5; ++i
)
90 void coverage9(int *x
) {
92 function_which_gives_up_settonull(&x
);
93 y
= (*x
); // no warning
96 static void empty_function(void){
98 int use_empty_function(int x
) {
101 return 5/x
; //expected-warning {{Division by zero}}