-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathfile.c
More file actions
98 lines (64 loc) · 1.34 KB
/
file.c
File metadata and controls
98 lines (64 loc) · 1.34 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
typedef void FILE;
FILE *fopen(const char *path, const char *mode);
int fclose(FILE *fp);
#define NULL ((FILE *)0)
void f1(int i) {
FILE *f = fopen("somefile.txt", "r");
if (!f) return;
if (!i) return; // Not closed here
fclose(f);
}
FILE *f2(int i) {
FILE *f = fopen("somefile.txt", "r");
if (!f) return NULL;
if (!i) return NULL; // Not closed here
return f;
}
void g2(int i) {
FILE *f = f2(i);
fclose(f); // This makes the final return in f2 count as closed
}
void f3(int i) {
FILE *f = fopen("somefile.txt", "r"); // Never closed
if (!f) return;
if (!i) return;
}
void f4(void) {
FILE *f = fopen("somefile.txt", "r"); // Always closed
if (!f) return;
fclose(f);
}
FILE *f5(void) {
FILE *f = fopen("somefile.txt", "r"); // Always closed, by g5
if (!f) return NULL;
return f;
}
void g5(void) {
FILE *f = f5();
fclose(f);
}
int f6(int b) {
FILE *f;
f = fopen("somefile.txt", "r"); // Not always closed
if (f) {
if (b) {
fclose(f);
}
}
return 0;
}
int f7(void) {
FILE *f;
f = fopen("somefile.txt", "r"); // Always closed
if (f) {
fclose(f);
}
return 0;
}
int f8(void) {
FILE *f;
if (f = fopen("somefile.txt", "r")) { // Always closed
fclose(f);
}
return 0;
}