annotate clang/docs/analyzer/checkers.rst @ 173:0572611fdcc8 llvm10 llvm12

reorgnization done
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 11:55:54 +0900
parents 1d019706d866
children 2e18cbf3894f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 ==================
anatofuz
parents:
diff changeset
2 Available Checkers
anatofuz
parents:
diff changeset
3 ==================
anatofuz
parents:
diff changeset
4
anatofuz
parents:
diff changeset
5 The analyzer performs checks that are categorized into families or "checkers".
anatofuz
parents:
diff changeset
6
anatofuz
parents:
diff changeset
7 The default set of checkers covers a variety of checks targeted at finding security and API usage bugs,
anatofuz
parents:
diff changeset
8 dead code, and other logic errors. See the :ref:`default-checkers` checkers list below.
anatofuz
parents:
diff changeset
9
anatofuz
parents:
diff changeset
10 In addition to these, the analyzer contains a number of :ref:`alpha-checkers` (aka *alpha* checkers).
anatofuz
parents:
diff changeset
11 These checkers are under development and are switched off by default. They may crash or emit a higher number of false positives.
anatofuz
parents:
diff changeset
12
anatofuz
parents:
diff changeset
13 The :ref:`debug-checkers` package contains checkers for analyzer developers for debugging purposes.
anatofuz
parents:
diff changeset
14
anatofuz
parents:
diff changeset
15 .. contents:: Table of Contents
anatofuz
parents:
diff changeset
16 :depth: 4
anatofuz
parents:
diff changeset
17
anatofuz
parents:
diff changeset
18
anatofuz
parents:
diff changeset
19 .. _default-checkers:
anatofuz
parents:
diff changeset
20
anatofuz
parents:
diff changeset
21 Default Checkers
anatofuz
parents:
diff changeset
22 ----------------
anatofuz
parents:
diff changeset
23
anatofuz
parents:
diff changeset
24 .. _core-checkers:
anatofuz
parents:
diff changeset
25
anatofuz
parents:
diff changeset
26 core
anatofuz
parents:
diff changeset
27 ^^^^
anatofuz
parents:
diff changeset
28 Models core language features and contains general-purpose checkers such as division by zero,
anatofuz
parents:
diff changeset
29 null pointer dereference, usage of uninitialized values, etc.
anatofuz
parents:
diff changeset
30 *These checkers must be always switched on as other checker rely on them.*
anatofuz
parents:
diff changeset
31
anatofuz
parents:
diff changeset
32 .. _core-CallAndMessage:
anatofuz
parents:
diff changeset
33
anatofuz
parents:
diff changeset
34 core.CallAndMessage (C, C++, ObjC)
anatofuz
parents:
diff changeset
35 """"""""""""""""""""""""""""""""""
anatofuz
parents:
diff changeset
36 Check for logical errors for function calls and Objective-C message expressions (e.g., uninitialized arguments, null function pointers).
anatofuz
parents:
diff changeset
37
anatofuz
parents:
diff changeset
38 .. literalinclude:: checkers/callandmessage_example.c
anatofuz
parents:
diff changeset
39 :language: objc
anatofuz
parents:
diff changeset
40
anatofuz
parents:
diff changeset
41 .. _core-DivideZero:
anatofuz
parents:
diff changeset
42
anatofuz
parents:
diff changeset
43 core.DivideZero (C, C++, ObjC)
anatofuz
parents:
diff changeset
44 """"""""""""""""""""""""""""""
anatofuz
parents:
diff changeset
45 Check for division by zero.
anatofuz
parents:
diff changeset
46
anatofuz
parents:
diff changeset
47 .. literalinclude:: checkers/dividezero_example.c
anatofuz
parents:
diff changeset
48 :language: c
anatofuz
parents:
diff changeset
49
anatofuz
parents:
diff changeset
50 .. _core-NonNullParamChecker:
anatofuz
parents:
diff changeset
51
anatofuz
parents:
diff changeset
52 core.NonNullParamChecker (C, C++, ObjC)
anatofuz
parents:
diff changeset
53 """""""""""""""""""""""""""""""""""""""
anatofuz
parents:
diff changeset
54 Check for null pointers passed as arguments to a function whose arguments are references or marked with the 'nonnull' attribute.
anatofuz
parents:
diff changeset
55
anatofuz
parents:
diff changeset
56 .. code-block:: cpp
anatofuz
parents:
diff changeset
57
anatofuz
parents:
diff changeset
58 int f(int *p) __attribute__((nonnull));
anatofuz
parents:
diff changeset
59
anatofuz
parents:
diff changeset
60 void test(int *p) {
anatofuz
parents:
diff changeset
61 if (!p)
anatofuz
parents:
diff changeset
62 f(p); // warn
anatofuz
parents:
diff changeset
63 }
anatofuz
parents:
diff changeset
64
anatofuz
parents:
diff changeset
65 .. _core-NullDereference:
anatofuz
parents:
diff changeset
66
anatofuz
parents:
diff changeset
67 core.NullDereference (C, C++, ObjC)
anatofuz
parents:
diff changeset
68 """""""""""""""""""""""""""""""""""
anatofuz
parents:
diff changeset
69 Check for dereferences of null pointers.
anatofuz
parents:
diff changeset
70
anatofuz
parents:
diff changeset
71 .. code-block:: objc
anatofuz
parents:
diff changeset
72
anatofuz
parents:
diff changeset
73 // C
anatofuz
parents:
diff changeset
74 void test(int *p) {
anatofuz
parents:
diff changeset
75 if (p)
anatofuz
parents:
diff changeset
76 return;
anatofuz
parents:
diff changeset
77
anatofuz
parents:
diff changeset
78 int x = p[0]; // warn
anatofuz
parents:
diff changeset
79 }
anatofuz
parents:
diff changeset
80
anatofuz
parents:
diff changeset
81 // C
anatofuz
parents:
diff changeset
82 void test(int *p) {
anatofuz
parents:
diff changeset
83 if (!p)
anatofuz
parents:
diff changeset
84 *p = 0; // warn
anatofuz
parents:
diff changeset
85 }
anatofuz
parents:
diff changeset
86
anatofuz
parents:
diff changeset
87 // C++
anatofuz
parents:
diff changeset
88 class C {
anatofuz
parents:
diff changeset
89 public:
anatofuz
parents:
diff changeset
90 int x;
anatofuz
parents:
diff changeset
91 };
anatofuz
parents:
diff changeset
92
anatofuz
parents:
diff changeset
93 void test() {
anatofuz
parents:
diff changeset
94 C *pc = 0;
anatofuz
parents:
diff changeset
95 int k = pc->x; // warn
anatofuz
parents:
diff changeset
96 }
anatofuz
parents:
diff changeset
97
anatofuz
parents:
diff changeset
98 // Objective-C
anatofuz
parents:
diff changeset
99 @interface MyClass {
anatofuz
parents:
diff changeset
100 @public
anatofuz
parents:
diff changeset
101 int x;
anatofuz
parents:
diff changeset
102 }
anatofuz
parents:
diff changeset
103 @end
anatofuz
parents:
diff changeset
104
anatofuz
parents:
diff changeset
105 void test() {
anatofuz
parents:
diff changeset
106 MyClass *obj = 0;
anatofuz
parents:
diff changeset
107 obj->x = 1; // warn
anatofuz
parents:
diff changeset
108 }
anatofuz
parents:
diff changeset
109
anatofuz
parents:
diff changeset
110 .. _core-StackAddressEscape:
anatofuz
parents:
diff changeset
111
anatofuz
parents:
diff changeset
112 core.StackAddressEscape (C)
anatofuz
parents:
diff changeset
113 """""""""""""""""""""""""""
anatofuz
parents:
diff changeset
114 Check that addresses to stack memory do not escape the function.
anatofuz
parents:
diff changeset
115
anatofuz
parents:
diff changeset
116 .. code-block:: c
anatofuz
parents:
diff changeset
117
anatofuz
parents:
diff changeset
118 char const *p;
anatofuz
parents:
diff changeset
119
anatofuz
parents:
diff changeset
120 void test() {
anatofuz
parents:
diff changeset
121 char const str[] = "string";
anatofuz
parents:
diff changeset
122 p = str; // warn
anatofuz
parents:
diff changeset
123 }
anatofuz
parents:
diff changeset
124
anatofuz
parents:
diff changeset
125 void* test() {
anatofuz
parents:
diff changeset
126 return __builtin_alloca(12); // warn
anatofuz
parents:
diff changeset
127 }
anatofuz
parents:
diff changeset
128
anatofuz
parents:
diff changeset
129 void test() {
anatofuz
parents:
diff changeset
130 static int *x;
anatofuz
parents:
diff changeset
131 int y;
anatofuz
parents:
diff changeset
132 x = &y; // warn
anatofuz
parents:
diff changeset
133 }
anatofuz
parents:
diff changeset
134
anatofuz
parents:
diff changeset
135
anatofuz
parents:
diff changeset
136 .. _core-UndefinedBinaryOperatorResult:
anatofuz
parents:
diff changeset
137
anatofuz
parents:
diff changeset
138 core.UndefinedBinaryOperatorResult (C)
anatofuz
parents:
diff changeset
139 """"""""""""""""""""""""""""""""""""""
anatofuz
parents:
diff changeset
140 Check for undefined results of binary operators.
anatofuz
parents:
diff changeset
141
anatofuz
parents:
diff changeset
142 .. code-block:: c
anatofuz
parents:
diff changeset
143
anatofuz
parents:
diff changeset
144 void test() {
anatofuz
parents:
diff changeset
145 int x;
anatofuz
parents:
diff changeset
146 int y = x + 1; // warn: left operand is garbage
anatofuz
parents:
diff changeset
147 }
anatofuz
parents:
diff changeset
148
anatofuz
parents:
diff changeset
149 .. _core-VLASize:
anatofuz
parents:
diff changeset
150
anatofuz
parents:
diff changeset
151 core.VLASize (C)
anatofuz
parents:
diff changeset
152 """"""""""""""""
anatofuz
parents:
diff changeset
153 Check for declarations of Variable Length Arrays of undefined or zero size.
anatofuz
parents:
diff changeset
154
anatofuz
parents:
diff changeset
155 Check for declarations of VLA of undefined or zero size.
anatofuz
parents:
diff changeset
156
anatofuz
parents:
diff changeset
157 .. code-block:: c
anatofuz
parents:
diff changeset
158
anatofuz
parents:
diff changeset
159 void test() {
anatofuz
parents:
diff changeset
160 int x;
anatofuz
parents:
diff changeset
161 int vla1[x]; // warn: garbage as size
anatofuz
parents:
diff changeset
162 }
anatofuz
parents:
diff changeset
163
anatofuz
parents:
diff changeset
164 void test() {
anatofuz
parents:
diff changeset
165 int x = 0;
anatofuz
parents:
diff changeset
166 int vla2[x]; // warn: zero size
anatofuz
parents:
diff changeset
167 }
anatofuz
parents:
diff changeset
168
anatofuz
parents:
diff changeset
169 .. _core-uninitialized-ArraySubscript:
anatofuz
parents:
diff changeset
170
anatofuz
parents:
diff changeset
171 core.uninitialized.ArraySubscript (C)
anatofuz
parents:
diff changeset
172 """""""""""""""""""""""""""""""""""""
anatofuz
parents:
diff changeset
173 Check for uninitialized values used as array subscripts.
anatofuz
parents:
diff changeset
174
anatofuz
parents:
diff changeset
175 .. code-block:: c
anatofuz
parents:
diff changeset
176
anatofuz
parents:
diff changeset
177 void test() {
anatofuz
parents:
diff changeset
178 int i, a[10];
anatofuz
parents:
diff changeset
179 int x = a[i]; // warn: array subscript is undefined
anatofuz
parents:
diff changeset
180 }
anatofuz
parents:
diff changeset
181
anatofuz
parents:
diff changeset
182 .. _core-uninitialized-Assign:
anatofuz
parents:
diff changeset
183
anatofuz
parents:
diff changeset
184 core.uninitialized.Assign (C)
anatofuz
parents:
diff changeset
185 """""""""""""""""""""""""""""
anatofuz
parents:
diff changeset
186 Check for assigning uninitialized values.
anatofuz
parents:
diff changeset
187
anatofuz
parents:
diff changeset
188 .. code-block:: c
anatofuz
parents:
diff changeset
189
anatofuz
parents:
diff changeset
190 void test() {
anatofuz
parents:
diff changeset
191 int x;
anatofuz
parents:
diff changeset
192 x |= 1; // warn: left expression is uninitialized
anatofuz
parents:
diff changeset
193 }
anatofuz
parents:
diff changeset
194
anatofuz
parents:
diff changeset
195 .. _core-uninitialized-Branch:
anatofuz
parents:
diff changeset
196
anatofuz
parents:
diff changeset
197 core.uninitialized.Branch (C)
anatofuz
parents:
diff changeset
198 """""""""""""""""""""""""""""
anatofuz
parents:
diff changeset
199 Check for uninitialized values used as branch conditions.
anatofuz
parents:
diff changeset
200
anatofuz
parents:
diff changeset
201 .. code-block:: c
anatofuz
parents:
diff changeset
202
anatofuz
parents:
diff changeset
203 void test() {
anatofuz
parents:
diff changeset
204 int x;
anatofuz
parents:
diff changeset
205 if (x) // warn
anatofuz
parents:
diff changeset
206 return;
anatofuz
parents:
diff changeset
207 }
anatofuz
parents:
diff changeset
208
anatofuz
parents:
diff changeset
209 .. _core-uninitialized-CapturedBlockVariable:
anatofuz
parents:
diff changeset
210
anatofuz
parents:
diff changeset
211 core.uninitialized.CapturedBlockVariable (C)
anatofuz
parents:
diff changeset
212 """"""""""""""""""""""""""""""""""""""""""""
anatofuz
parents:
diff changeset
213 Check for blocks that capture uninitialized values.
anatofuz
parents:
diff changeset
214
anatofuz
parents:
diff changeset
215 .. code-block:: c
anatofuz
parents:
diff changeset
216
anatofuz
parents:
diff changeset
217 void test() {
anatofuz
parents:
diff changeset
218 int x;
anatofuz
parents:
diff changeset
219 ^{ int y = x; }(); // warn
anatofuz
parents:
diff changeset
220 }
anatofuz
parents:
diff changeset
221
anatofuz
parents:
diff changeset
222 .. _core-uninitialized-UndefReturn:
anatofuz
parents:
diff changeset
223
anatofuz
parents:
diff changeset
224 core.uninitialized.UndefReturn (C)
anatofuz
parents:
diff changeset
225 """"""""""""""""""""""""""""""""""
anatofuz
parents:
diff changeset
226 Check for uninitialized values being returned to the caller.
anatofuz
parents:
diff changeset
227
anatofuz
parents:
diff changeset
228 .. code-block:: c
anatofuz
parents:
diff changeset
229
anatofuz
parents:
diff changeset
230 int test() {
anatofuz
parents:
diff changeset
231 int x;
anatofuz
parents:
diff changeset
232 return x; // warn
anatofuz
parents:
diff changeset
233 }
anatofuz
parents:
diff changeset
234
anatofuz
parents:
diff changeset
235 .. _cplusplus-checkers:
anatofuz
parents:
diff changeset
236
anatofuz
parents:
diff changeset
237
anatofuz
parents:
diff changeset
238 cplusplus
anatofuz
parents:
diff changeset
239 ^^^^^^^^^
anatofuz
parents:
diff changeset
240
anatofuz
parents:
diff changeset
241 C++ Checkers.
anatofuz
parents:
diff changeset
242
anatofuz
parents:
diff changeset
243 .. _cplusplus-InnerPointer:
anatofuz
parents:
diff changeset
244
anatofuz
parents:
diff changeset
245 cplusplus.InnerPointer (C++)
anatofuz
parents:
diff changeset
246 """"""""""""""""""""""""""""
anatofuz
parents:
diff changeset
247 Check for inner pointers of C++ containers used after re/deallocation.
anatofuz
parents:
diff changeset
248
anatofuz
parents:
diff changeset
249 Many container methods in the C++ standard library are known to invalidate
anatofuz
parents:
diff changeset
250 "references" (including actual references, iterators and raw pointers) to
anatofuz
parents:
diff changeset
251 elements of the container. Using such references after they are invalidated
anatofuz
parents:
diff changeset
252 causes undefined behavior, which is a common source of memory errors in C++ that
anatofuz
parents:
diff changeset
253 this checker is capable of finding.
anatofuz
parents:
diff changeset
254
anatofuz
parents:
diff changeset
255 The checker is currently limited to ``std::string`` objects and doesn't
anatofuz
parents:
diff changeset
256 recognize some of the more sophisticated approaches to passing unowned pointers
anatofuz
parents:
diff changeset
257 around, such as ``std::string_view``.
anatofuz
parents:
diff changeset
258
anatofuz
parents:
diff changeset
259 .. code-block:: cpp
anatofuz
parents:
diff changeset
260
anatofuz
parents:
diff changeset
261 void deref_after_assignment() {
anatofuz
parents:
diff changeset
262 std::string s = "llvm";
anatofuz
parents:
diff changeset
263 const char *c = s.data(); // note: pointer to inner buffer of 'std::string' obtained here
anatofuz
parents:
diff changeset
264 s = "clang"; // note: inner buffer of 'std::string' reallocated by call to 'operator='
anatofuz
parents:
diff changeset
265 consume(c); // warn: inner pointer of container used after re/deallocation
anatofuz
parents:
diff changeset
266 }
anatofuz
parents:
diff changeset
267
anatofuz
parents:
diff changeset
268 const char *return_temp(int x) {
anatofuz
parents:
diff changeset
269 return std::to_string(x).c_str(); // warn: inner pointer of container used after re/deallocation
anatofuz
parents:
diff changeset
270 // note: pointer to inner buffer of 'std::string' obtained here
anatofuz
parents:
diff changeset
271 // note: inner buffer of 'std::string' deallocated by call to destructor
anatofuz
parents:
diff changeset
272 }
anatofuz
parents:
diff changeset
273
anatofuz
parents:
diff changeset
274 .. _cplusplus-NewDelete:
anatofuz
parents:
diff changeset
275
anatofuz
parents:
diff changeset
276 cplusplus.NewDelete (C++)
anatofuz
parents:
diff changeset
277 """""""""""""""""""""""""
anatofuz
parents:
diff changeset
278 Check for double-free and use-after-free problems. Traces memory managed by new/delete.
anatofuz
parents:
diff changeset
279
anatofuz
parents:
diff changeset
280 .. literalinclude:: checkers/newdelete_example.cpp
anatofuz
parents:
diff changeset
281 :language: cpp
anatofuz
parents:
diff changeset
282
anatofuz
parents:
diff changeset
283 .. _cplusplus-NewDeleteLeaks:
anatofuz
parents:
diff changeset
284
anatofuz
parents:
diff changeset
285 cplusplus.NewDeleteLeaks (C++)
anatofuz
parents:
diff changeset
286 """"""""""""""""""""""""""""""
anatofuz
parents:
diff changeset
287 Check for memory leaks. Traces memory managed by new/delete.
anatofuz
parents:
diff changeset
288
anatofuz
parents:
diff changeset
289 .. code-block:: cpp
anatofuz
parents:
diff changeset
290
anatofuz
parents:
diff changeset
291 void test() {
anatofuz
parents:
diff changeset
292 int *p = new int;
anatofuz
parents:
diff changeset
293 } // warn
anatofuz
parents:
diff changeset
294
anatofuz
parents:
diff changeset
295 .. _cplusplus-PlacementNewChecker:
anatofuz
parents:
diff changeset
296
anatofuz
parents:
diff changeset
297 cplusplus.PlacementNewChecker (C++)
anatofuz
parents:
diff changeset
298 """""""""""""""""""""""""""""""""""
anatofuz
parents:
diff changeset
299 Check if default placement new is provided with pointers to sufficient storage capacity.
anatofuz
parents:
diff changeset
300
anatofuz
parents:
diff changeset
301 .. code-block:: cpp
anatofuz
parents:
diff changeset
302
anatofuz
parents:
diff changeset
303 #include <new>
anatofuz
parents:
diff changeset
304
anatofuz
parents:
diff changeset
305 void f() {
anatofuz
parents:
diff changeset
306 short s;
anatofuz
parents:
diff changeset
307 long *lp = ::new (&s) long; // warn
anatofuz
parents:
diff changeset
308 }
anatofuz
parents:
diff changeset
309
anatofuz
parents:
diff changeset
310 .. _cplusplus-SelfAssignment:
anatofuz
parents:
diff changeset
311
anatofuz
parents:
diff changeset
312 cplusplus.SelfAssignment (C++)
anatofuz
parents:
diff changeset
313 """"""""""""""""""""""""""""""
anatofuz
parents:
diff changeset
314 Checks C++ copy and move assignment operators for self assignment.
anatofuz
parents:
diff changeset
315
anatofuz
parents:
diff changeset
316 .. _deadcode-checkers:
anatofuz
parents:
diff changeset
317
anatofuz
parents:
diff changeset
318 deadcode
anatofuz
parents:
diff changeset
319 ^^^^^^^^
anatofuz
parents:
diff changeset
320
anatofuz
parents:
diff changeset
321 Dead Code Checkers.
anatofuz
parents:
diff changeset
322
anatofuz
parents:
diff changeset
323 .. _deadcode-DeadStores:
anatofuz
parents:
diff changeset
324
anatofuz
parents:
diff changeset
325 deadcode.DeadStores (C)
anatofuz
parents:
diff changeset
326 """""""""""""""""""""""
anatofuz
parents:
diff changeset
327 Check for values stored to variables that are never read afterwards.
anatofuz
parents:
diff changeset
328
anatofuz
parents:
diff changeset
329 .. code-block:: c
anatofuz
parents:
diff changeset
330
anatofuz
parents:
diff changeset
331 void test() {
anatofuz
parents:
diff changeset
332 int x;
anatofuz
parents:
diff changeset
333 x = 1; // warn
anatofuz
parents:
diff changeset
334 }
anatofuz
parents:
diff changeset
335
anatofuz
parents:
diff changeset
336 The ``WarnForDeadNestedAssignments`` option enables the checker to emit
anatofuz
parents:
diff changeset
337 warnings for nested dead assignments. You can disable with the
anatofuz
parents:
diff changeset
338 ``-analyzer-config deadcode.DeadStores:WarnForDeadNestedAssignments=false``.
anatofuz
parents:
diff changeset
339 *Defaults to true*.
anatofuz
parents:
diff changeset
340
anatofuz
parents:
diff changeset
341 Would warn for this e.g.:
anatofuz
parents:
diff changeset
342 if ((y = make_int())) {
anatofuz
parents:
diff changeset
343 }
anatofuz
parents:
diff changeset
344
anatofuz
parents:
diff changeset
345 .. _nullability-checkers:
anatofuz
parents:
diff changeset
346
anatofuz
parents:
diff changeset
347 nullability
anatofuz
parents:
diff changeset
348 ^^^^^^^^^^^
anatofuz
parents:
diff changeset
349
anatofuz
parents:
diff changeset
350 Objective C checkers that warn for null pointer passing and dereferencing errors.
anatofuz
parents:
diff changeset
351
anatofuz
parents:
diff changeset
352 .. _nullability-NullPassedToNonnull:
anatofuz
parents:
diff changeset
353
anatofuz
parents:
diff changeset
354 nullability.NullPassedToNonnull (ObjC)
anatofuz
parents:
diff changeset
355 """"""""""""""""""""""""""""""""""""""
anatofuz
parents:
diff changeset
356 Warns when a null pointer is passed to a pointer which has a _Nonnull type.
anatofuz
parents:
diff changeset
357
anatofuz
parents:
diff changeset
358 .. code-block:: objc
anatofuz
parents:
diff changeset
359
anatofuz
parents:
diff changeset
360 if (name != nil)
anatofuz
parents:
diff changeset
361 return;
anatofuz
parents:
diff changeset
362 // Warning: nil passed to a callee that requires a non-null 1st parameter
anatofuz
parents:
diff changeset
363 NSString *greeting = [@"Hello " stringByAppendingString:name];
anatofuz
parents:
diff changeset
364
anatofuz
parents:
diff changeset
365 .. _nullability-NullReturnedFromNonnull:
anatofuz
parents:
diff changeset
366
anatofuz
parents:
diff changeset
367 nullability.NullReturnedFromNonnull (ObjC)
anatofuz
parents:
diff changeset
368 """"""""""""""""""""""""""""""""""""""""""
anatofuz
parents:
diff changeset
369 Warns when a null pointer is returned from a function that has _Nonnull return type.
anatofuz
parents:
diff changeset
370
anatofuz
parents:
diff changeset
371 .. code-block:: objc
anatofuz
parents:
diff changeset
372
anatofuz
parents:
diff changeset
373 - (nonnull id)firstChild {
anatofuz
parents:
diff changeset
374 id result = nil;
anatofuz
parents:
diff changeset
375 if ([_children count] > 0)
anatofuz
parents:
diff changeset
376 result = _children[0];
anatofuz
parents:
diff changeset
377
anatofuz
parents:
diff changeset
378 // Warning: nil returned from a method that is expected
anatofuz
parents:
diff changeset
379 // to return a non-null value
anatofuz
parents:
diff changeset
380 return result;
anatofuz
parents:
diff changeset
381 }
anatofuz
parents:
diff changeset
382
anatofuz
parents:
diff changeset
383 .. _nullability-NullableDereferenced:
anatofuz
parents:
diff changeset
384
anatofuz
parents:
diff changeset
385 nullability.NullableDereferenced (ObjC)
anatofuz
parents:
diff changeset
386 """""""""""""""""""""""""""""""""""""""
anatofuz
parents:
diff changeset
387 Warns when a nullable pointer is dereferenced.
anatofuz
parents:
diff changeset
388
anatofuz
parents:
diff changeset
389 .. code-block:: objc
anatofuz
parents:
diff changeset
390
anatofuz
parents:
diff changeset
391 struct LinkedList {
anatofuz
parents:
diff changeset
392 int data;
anatofuz
parents:
diff changeset
393 struct LinkedList *next;
anatofuz
parents:
diff changeset
394 };
anatofuz
parents:
diff changeset
395
anatofuz
parents:
diff changeset
396 struct LinkedList * _Nullable getNext(struct LinkedList *l);
anatofuz
parents:
diff changeset
397
anatofuz
parents:
diff changeset
398 void updateNextData(struct LinkedList *list, int newData) {
anatofuz
parents:
diff changeset
399 struct LinkedList *next = getNext(list);
anatofuz
parents:
diff changeset
400 // Warning: Nullable pointer is dereferenced
anatofuz
parents:
diff changeset
401 next->data = 7;
anatofuz
parents:
diff changeset
402 }
anatofuz
parents:
diff changeset
403
anatofuz
parents:
diff changeset
404 .. _nullability-NullablePassedToNonnull:
anatofuz
parents:
diff changeset
405
anatofuz
parents:
diff changeset
406 nullability.NullablePassedToNonnull (ObjC)
anatofuz
parents:
diff changeset
407 """"""""""""""""""""""""""""""""""""""""""
anatofuz
parents:
diff changeset
408 Warns when a nullable pointer is passed to a pointer which has a _Nonnull type.
anatofuz
parents:
diff changeset
409
anatofuz
parents:
diff changeset
410 .. code-block:: objc
anatofuz
parents:
diff changeset
411
anatofuz
parents:
diff changeset
412 typedef struct Dummy { int val; } Dummy;
anatofuz
parents:
diff changeset
413 Dummy *_Nullable returnsNullable();
anatofuz
parents:
diff changeset
414 void takesNonnull(Dummy *_Nonnull);
anatofuz
parents:
diff changeset
415
anatofuz
parents:
diff changeset
416 void test() {
anatofuz
parents:
diff changeset
417 Dummy *p = returnsNullable();
anatofuz
parents:
diff changeset
418 takesNonnull(p); // warn
anatofuz
parents:
diff changeset
419 }
anatofuz
parents:
diff changeset
420
anatofuz
parents:
diff changeset
421 .. _nullability-NullableReturnedFromNonnull:
anatofuz
parents:
diff changeset
422
anatofuz
parents:
diff changeset
423 nullability.NullableReturnedFromNonnull (ObjC)
anatofuz
parents:
diff changeset
424 """"""""""""""""""""""""""""""""""""""""""""""
anatofuz
parents:
diff changeset
425 Warns when a nullable pointer is returned from a function that has _Nonnull return type.
anatofuz
parents:
diff changeset
426
anatofuz
parents:
diff changeset
427 .. _optin-checkers:
anatofuz
parents:
diff changeset
428
anatofuz
parents:
diff changeset
429 optin
anatofuz
parents:
diff changeset
430 ^^^^^
anatofuz
parents:
diff changeset
431
anatofuz
parents:
diff changeset
432 Checkers for portability, performance or coding style specific rules.
anatofuz
parents:
diff changeset
433
anatofuz
parents:
diff changeset
434 .. _optin-cplusplus-UninitializedObject:
anatofuz
parents:
diff changeset
435
anatofuz
parents:
diff changeset
436 optin.cplusplus.UninitializedObject (C++)
anatofuz
parents:
diff changeset
437 """""""""""""""""""""""""""""""""""""""""
anatofuz
parents:
diff changeset
438
anatofuz
parents:
diff changeset
439 This checker reports uninitialized fields in objects created after a constructor
anatofuz
parents:
diff changeset
440 call. It doesn't only find direct uninitialized fields, but rather makes a deep
anatofuz
parents:
diff changeset
441 inspection of the object, analyzing all of it's fields subfields.
anatofuz
parents:
diff changeset
442 The checker regards inherited fields as direct fields, so one will receive
anatofuz
parents:
diff changeset
443 warnings for uninitialized inherited data members as well.
anatofuz
parents:
diff changeset
444
anatofuz
parents:
diff changeset
445 .. code-block:: cpp
anatofuz
parents:
diff changeset
446
anatofuz
parents:
diff changeset
447 // With Pedantic and CheckPointeeInitialization set to true
anatofuz
parents:
diff changeset
448
anatofuz
parents:
diff changeset
449 struct A {
anatofuz
parents:
diff changeset
450 struct B {
anatofuz
parents:
diff changeset
451 int x; // note: uninitialized field 'this->b.x'
anatofuz
parents:
diff changeset
452 // note: uninitialized field 'this->bptr->x'
anatofuz
parents:
diff changeset
453 int y; // note: uninitialized field 'this->b.y'
anatofuz
parents:
diff changeset
454 // note: uninitialized field 'this->bptr->y'
anatofuz
parents:
diff changeset
455 };
anatofuz
parents:
diff changeset
456 int *iptr; // note: uninitialized pointer 'this->iptr'
anatofuz
parents:
diff changeset
457 B b;
anatofuz
parents:
diff changeset
458 B *bptr;
anatofuz
parents:
diff changeset
459 char *cptr; // note: uninitialized pointee 'this->cptr'
anatofuz
parents:
diff changeset
460
anatofuz
parents:
diff changeset
461 A (B *bptr, char *cptr) : bptr(bptr), cptr(cptr) {}
anatofuz
parents:
diff changeset
462 };
anatofuz
parents:
diff changeset
463
anatofuz
parents:
diff changeset
464 void f() {
anatofuz
parents:
diff changeset
465 A::B b;
anatofuz
parents:
diff changeset
466 char c;
anatofuz
parents:
diff changeset
467 A a(&b, &c); // warning: 6 uninitialized fields
anatofuz
parents:
diff changeset
468 // after the constructor call
anatofuz
parents:
diff changeset
469 }
anatofuz
parents:
diff changeset
470
anatofuz
parents:
diff changeset
471 // With Pedantic set to false and
anatofuz
parents:
diff changeset
472 // CheckPointeeInitialization set to true
anatofuz
parents:
diff changeset
473 // (every field is uninitialized)
anatofuz
parents:
diff changeset
474
anatofuz
parents:
diff changeset
475 struct A {
anatofuz
parents:
diff changeset
476 struct B {
anatofuz
parents:
diff changeset
477 int x;
anatofuz
parents:
diff changeset
478 int y;
anatofuz
parents:
diff changeset
479 };
anatofuz
parents:
diff changeset
480 int *iptr;
anatofuz
parents:
diff changeset
481 B b;
anatofuz
parents:
diff changeset
482 B *bptr;
anatofuz
parents:
diff changeset
483 char *cptr;
anatofuz
parents:
diff changeset
484
anatofuz
parents:
diff changeset
485 A (B *bptr, char *cptr) : bptr(bptr), cptr(cptr) {}
anatofuz
parents:
diff changeset
486 };
anatofuz
parents:
diff changeset
487
anatofuz
parents:
diff changeset
488 void f() {
anatofuz
parents:
diff changeset
489 A::B b;
anatofuz
parents:
diff changeset
490 char c;
anatofuz
parents:
diff changeset
491 A a(&b, &c); // no warning
anatofuz
parents:
diff changeset
492 }
anatofuz
parents:
diff changeset
493
anatofuz
parents:
diff changeset
494 // With Pedantic set to true and
anatofuz
parents:
diff changeset
495 // CheckPointeeInitialization set to false
anatofuz
parents:
diff changeset
496 // (pointees are regarded as initialized)
anatofuz
parents:
diff changeset
497
anatofuz
parents:
diff changeset
498 struct A {
anatofuz
parents:
diff changeset
499 struct B {
anatofuz
parents:
diff changeset
500 int x; // note: uninitialized field 'this->b.x'
anatofuz
parents:
diff changeset
501 int y; // note: uninitialized field 'this->b.y'
anatofuz
parents:
diff changeset
502 };
anatofuz
parents:
diff changeset
503 int *iptr; // note: uninitialized pointer 'this->iptr'
anatofuz
parents:
diff changeset
504 B b;
anatofuz
parents:
diff changeset
505 B *bptr;
anatofuz
parents:
diff changeset
506 char *cptr;
anatofuz
parents:
diff changeset
507
anatofuz
parents:
diff changeset
508 A (B *bptr, char *cptr) : bptr(bptr), cptr(cptr) {}
anatofuz
parents:
diff changeset
509 };
anatofuz
parents:
diff changeset
510
anatofuz
parents:
diff changeset
511 void f() {
anatofuz
parents:
diff changeset
512 A::B b;
anatofuz
parents:
diff changeset
513 char c;
anatofuz
parents:
diff changeset
514 A a(&b, &c); // warning: 3 uninitialized fields
anatofuz
parents:
diff changeset
515 // after the constructor call
anatofuz
parents:
diff changeset
516 }
anatofuz
parents:
diff changeset
517
anatofuz
parents:
diff changeset
518
anatofuz
parents:
diff changeset
519 **Options**
anatofuz
parents:
diff changeset
520
anatofuz
parents:
diff changeset
521 This checker has several options which can be set from command line (e.g.
anatofuz
parents:
diff changeset
522 ``-analyzer-config optin.cplusplus.UninitializedObject:Pedantic=true``):
anatofuz
parents:
diff changeset
523
anatofuz
parents:
diff changeset
524 * ``Pedantic`` (boolean). If to false, the checker won't emit warnings for
anatofuz
parents:
diff changeset
525 objects that don't have at least one initialized field. Defaults to false.
anatofuz
parents:
diff changeset
526
anatofuz
parents:
diff changeset
527 * ``NotesAsWarnings`` (boolean). If set to true, the checker will emit a
anatofuz
parents:
diff changeset
528 warning for each uninitialized field, as opposed to emitting one warning per
anatofuz
parents:
diff changeset
529 constructor call, and listing the uninitialized fields that belongs to it in
anatofuz
parents:
diff changeset
530 notes. *Defaults to false*.
anatofuz
parents:
diff changeset
531
anatofuz
parents:
diff changeset
532 * ``CheckPointeeInitialization`` (boolean). If set to false, the checker will
anatofuz
parents:
diff changeset
533 not analyze the pointee of pointer/reference fields, and will only check
anatofuz
parents:
diff changeset
534 whether the object itself is initialized. *Defaults to false*.
anatofuz
parents:
diff changeset
535
anatofuz
parents:
diff changeset
536 * ``IgnoreRecordsWithField`` (string). If supplied, the checker will not analyze
anatofuz
parents:
diff changeset
537 structures that have a field with a name or type name that matches the given
anatofuz
parents:
diff changeset
538 pattern. *Defaults to ""*.
anatofuz
parents:
diff changeset
539
anatofuz
parents:
diff changeset
540 .. _optin-cplusplus-VirtualCall:
anatofuz
parents:
diff changeset
541
anatofuz
parents:
diff changeset
542 optin.cplusplus.VirtualCall (C++)
anatofuz
parents:
diff changeset
543 """""""""""""""""""""""""""""""""
anatofuz
parents:
diff changeset
544 Check virtual function calls during construction or destruction.
anatofuz
parents:
diff changeset
545
anatofuz
parents:
diff changeset
546 .. code-block:: cpp
anatofuz
parents:
diff changeset
547
anatofuz
parents:
diff changeset
548 class A {
anatofuz
parents:
diff changeset
549 public:
anatofuz
parents:
diff changeset
550 A() {
anatofuz
parents:
diff changeset
551 f(); // warn
anatofuz
parents:
diff changeset
552 }
anatofuz
parents:
diff changeset
553 virtual void f();
anatofuz
parents:
diff changeset
554 };
anatofuz
parents:
diff changeset
555
anatofuz
parents:
diff changeset
556 class A {
anatofuz
parents:
diff changeset
557 public:
anatofuz
parents:
diff changeset
558 ~A() {
anatofuz
parents:
diff changeset
559 this->f(); // warn
anatofuz
parents:
diff changeset
560 }
anatofuz
parents:
diff changeset
561 virtual void f();
anatofuz
parents:
diff changeset
562 };
anatofuz
parents:
diff changeset
563
anatofuz
parents:
diff changeset
564 .. _optin-mpi-MPI-Checker:
anatofuz
parents:
diff changeset
565
anatofuz
parents:
diff changeset
566 optin.mpi.MPI-Checker (C)
anatofuz
parents:
diff changeset
567 """""""""""""""""""""""""
anatofuz
parents:
diff changeset
568 Checks MPI code.
anatofuz
parents:
diff changeset
569
anatofuz
parents:
diff changeset
570 .. code-block:: c
anatofuz
parents:
diff changeset
571
anatofuz
parents:
diff changeset
572 void test() {
anatofuz
parents:
diff changeset
573 double buf = 0;
anatofuz
parents:
diff changeset
574 MPI_Request sendReq1;
anatofuz
parents:
diff changeset
575 MPI_Ireduce(MPI_IN_PLACE, &buf, 1, MPI_DOUBLE, MPI_SUM,
anatofuz
parents:
diff changeset
576 0, MPI_COMM_WORLD, &sendReq1);
anatofuz
parents:
diff changeset
577 } // warn: request 'sendReq1' has no matching wait.
anatofuz
parents:
diff changeset
578
anatofuz
parents:
diff changeset
579 void test() {
anatofuz
parents:
diff changeset
580 double buf = 0;
anatofuz
parents:
diff changeset
581 MPI_Request sendReq;
anatofuz
parents:
diff changeset
582 MPI_Isend(&buf, 1, MPI_DOUBLE, 0, 0, MPI_COMM_WORLD, &sendReq);
anatofuz
parents:
diff changeset
583 MPI_Irecv(&buf, 1, MPI_DOUBLE, 0, 0, MPI_COMM_WORLD, &sendReq); // warn
anatofuz
parents:
diff changeset
584 MPI_Isend(&buf, 1, MPI_DOUBLE, 0, 0, MPI_COMM_WORLD, &sendReq); // warn
anatofuz
parents:
diff changeset
585 MPI_Wait(&sendReq, MPI_STATUS_IGNORE);
anatofuz
parents:
diff changeset
586 }
anatofuz
parents:
diff changeset
587
anatofuz
parents:
diff changeset
588 void missingNonBlocking() {
anatofuz
parents:
diff changeset
589 int rank = 0;
anatofuz
parents:
diff changeset
590 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
anatofuz
parents:
diff changeset
591 MPI_Request sendReq1[10][10][10];
anatofuz
parents:
diff changeset
592 MPI_Wait(&sendReq1[1][7][9], MPI_STATUS_IGNORE); // warn
anatofuz
parents:
diff changeset
593 }
anatofuz
parents:
diff changeset
594
anatofuz
parents:
diff changeset
595 .. _optin-osx-cocoa-localizability-EmptyLocalizationContextChecker:
anatofuz
parents:
diff changeset
596
anatofuz
parents:
diff changeset
597 optin.osx.cocoa.localizability.EmptyLocalizationContextChecker (ObjC)
anatofuz
parents:
diff changeset
598 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
anatofuz
parents:
diff changeset
599 Check that NSLocalizedString macros include a comment for context.
anatofuz
parents:
diff changeset
600
anatofuz
parents:
diff changeset
601 .. code-block:: objc
anatofuz
parents:
diff changeset
602
anatofuz
parents:
diff changeset
603 - (void)test {
anatofuz
parents:
diff changeset
604 NSString *string = NSLocalizedString(@"LocalizedString", nil); // warn
anatofuz
parents:
diff changeset
605 NSString *string2 = NSLocalizedString(@"LocalizedString", @" "); // warn
anatofuz
parents:
diff changeset
606 NSString *string3 = NSLocalizedStringWithDefaultValue(
anatofuz
parents:
diff changeset
607 @"LocalizedString", nil, [[NSBundle alloc] init], nil,@""); // warn
anatofuz
parents:
diff changeset
608 }
anatofuz
parents:
diff changeset
609
anatofuz
parents:
diff changeset
610 .. _optin-osx-cocoa-localizability-NonLocalizedStringChecker:
anatofuz
parents:
diff changeset
611
anatofuz
parents:
diff changeset
612 optin.osx.cocoa.localizability.NonLocalizedStringChecker (ObjC)
anatofuz
parents:
diff changeset
613 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
anatofuz
parents:
diff changeset
614 Warns about uses of non-localized NSStrings passed to UI methods expecting localized NSStrings.
anatofuz
parents:
diff changeset
615
anatofuz
parents:
diff changeset
616 .. code-block:: objc
anatofuz
parents:
diff changeset
617
anatofuz
parents:
diff changeset
618 NSString *alarmText =
anatofuz
parents:
diff changeset
619 NSLocalizedString(@"Enabled", @"Indicates alarm is turned on");
anatofuz
parents:
diff changeset
620 if (!isEnabled) {
anatofuz
parents:
diff changeset
621 alarmText = @"Disabled";
anatofuz
parents:
diff changeset
622 }
anatofuz
parents:
diff changeset
623 UILabel *alarmStateLabel = [[UILabel alloc] init];
anatofuz
parents:
diff changeset
624
anatofuz
parents:
diff changeset
625 // Warning: User-facing text should use localized string macro
anatofuz
parents:
diff changeset
626 [alarmStateLabel setText:alarmText];
anatofuz
parents:
diff changeset
627
anatofuz
parents:
diff changeset
628 .. _optin-performance-GCDAntipattern:
anatofuz
parents:
diff changeset
629
anatofuz
parents:
diff changeset
630 optin.performance.GCDAntipattern
anatofuz
parents:
diff changeset
631 """"""""""""""""""""""""""""""""
anatofuz
parents:
diff changeset
632 Check for performance anti-patterns when using Grand Central Dispatch.
anatofuz
parents:
diff changeset
633
anatofuz
parents:
diff changeset
634 .. _optin-performance-Padding:
anatofuz
parents:
diff changeset
635
anatofuz
parents:
diff changeset
636 optin.performance.Padding
anatofuz
parents:
diff changeset
637 """""""""""""""""""""""""
anatofuz
parents:
diff changeset
638 Check for excessively padded structs.
anatofuz
parents:
diff changeset
639
anatofuz
parents:
diff changeset
640 .. _optin-portability-UnixAPI:
anatofuz
parents:
diff changeset
641
anatofuz
parents:
diff changeset
642 optin.portability.UnixAPI
anatofuz
parents:
diff changeset
643 """""""""""""""""""""""""
anatofuz
parents:
diff changeset
644 Finds implementation-defined behavior in UNIX/Posix functions.
anatofuz
parents:
diff changeset
645
anatofuz
parents:
diff changeset
646
anatofuz
parents:
diff changeset
647 .. _security-checkers:
anatofuz
parents:
diff changeset
648
anatofuz
parents:
diff changeset
649 security
anatofuz
parents:
diff changeset
650 ^^^^^^^^
anatofuz
parents:
diff changeset
651
anatofuz
parents:
diff changeset
652 Security related checkers.
anatofuz
parents:
diff changeset
653
anatofuz
parents:
diff changeset
654 .. _security-FloatLoopCounter:
anatofuz
parents:
diff changeset
655
anatofuz
parents:
diff changeset
656 security.FloatLoopCounter (C)
anatofuz
parents:
diff changeset
657 """""""""""""""""""""""""""""
anatofuz
parents:
diff changeset
658 Warn on using a floating point value as a loop counter (CERT: FLP30-C, FLP30-CPP).
anatofuz
parents:
diff changeset
659
anatofuz
parents:
diff changeset
660 .. code-block:: c
anatofuz
parents:
diff changeset
661
anatofuz
parents:
diff changeset
662 void test() {
anatofuz
parents:
diff changeset
663 for (float x = 0.1f; x <= 1.0f; x += 0.1f) {} // warn
anatofuz
parents:
diff changeset
664 }
anatofuz
parents:
diff changeset
665
anatofuz
parents:
diff changeset
666 .. _security-insecureAPI-UncheckedReturn:
anatofuz
parents:
diff changeset
667
anatofuz
parents:
diff changeset
668 security.insecureAPI.UncheckedReturn (C)
anatofuz
parents:
diff changeset
669 """"""""""""""""""""""""""""""""""""""""
anatofuz
parents:
diff changeset
670 Warn on uses of functions whose return values must be always checked.
anatofuz
parents:
diff changeset
671
anatofuz
parents:
diff changeset
672 .. code-block:: c
anatofuz
parents:
diff changeset
673
anatofuz
parents:
diff changeset
674 void test() {
anatofuz
parents:
diff changeset
675 setuid(1); // warn
anatofuz
parents:
diff changeset
676 }
anatofuz
parents:
diff changeset
677
anatofuz
parents:
diff changeset
678 .. _security-insecureAPI-bcmp:
anatofuz
parents:
diff changeset
679
anatofuz
parents:
diff changeset
680 security.insecureAPI.bcmp (C)
anatofuz
parents:
diff changeset
681 """""""""""""""""""""""""""""
anatofuz
parents:
diff changeset
682 Warn on uses of the 'bcmp' function.
anatofuz
parents:
diff changeset
683
anatofuz
parents:
diff changeset
684 .. code-block:: c
anatofuz
parents:
diff changeset
685
anatofuz
parents:
diff changeset
686 void test() {
anatofuz
parents:
diff changeset
687 bcmp(ptr0, ptr1, n); // warn
anatofuz
parents:
diff changeset
688 }
anatofuz
parents:
diff changeset
689
anatofuz
parents:
diff changeset
690 .. _security-insecureAPI-bcopy:
anatofuz
parents:
diff changeset
691
anatofuz
parents:
diff changeset
692 security.insecureAPI.bcopy (C)
anatofuz
parents:
diff changeset
693 """"""""""""""""""""""""""""""
anatofuz
parents:
diff changeset
694 Warn on uses of the 'bcopy' function.
anatofuz
parents:
diff changeset
695
anatofuz
parents:
diff changeset
696 .. code-block:: c
anatofuz
parents:
diff changeset
697
anatofuz
parents:
diff changeset
698 void test() {
anatofuz
parents:
diff changeset
699 bcopy(src, dst, n); // warn
anatofuz
parents:
diff changeset
700 }
anatofuz
parents:
diff changeset
701
anatofuz
parents:
diff changeset
702 .. _security-insecureAPI-bzero:
anatofuz
parents:
diff changeset
703
anatofuz
parents:
diff changeset
704 security.insecureAPI.bzero (C)
anatofuz
parents:
diff changeset
705 """"""""""""""""""""""""""""""
anatofuz
parents:
diff changeset
706 Warn on uses of the 'bzero' function.
anatofuz
parents:
diff changeset
707
anatofuz
parents:
diff changeset
708 .. code-block:: c
anatofuz
parents:
diff changeset
709
anatofuz
parents:
diff changeset
710 void test() {
anatofuz
parents:
diff changeset
711 bzero(ptr, n); // warn
anatofuz
parents:
diff changeset
712 }
anatofuz
parents:
diff changeset
713
anatofuz
parents:
diff changeset
714 .. _security-insecureAPI-getpw:
anatofuz
parents:
diff changeset
715
anatofuz
parents:
diff changeset
716 security.insecureAPI.getpw (C)
anatofuz
parents:
diff changeset
717 """"""""""""""""""""""""""""""
anatofuz
parents:
diff changeset
718 Warn on uses of the 'getpw' function.
anatofuz
parents:
diff changeset
719
anatofuz
parents:
diff changeset
720 .. code-block:: c
anatofuz
parents:
diff changeset
721
anatofuz
parents:
diff changeset
722 void test() {
anatofuz
parents:
diff changeset
723 char buff[1024];
anatofuz
parents:
diff changeset
724 getpw(2, buff); // warn
anatofuz
parents:
diff changeset
725 }
anatofuz
parents:
diff changeset
726
anatofuz
parents:
diff changeset
727 .. _security-insecureAPI-gets:
anatofuz
parents:
diff changeset
728
anatofuz
parents:
diff changeset
729 security.insecureAPI.gets (C)
anatofuz
parents:
diff changeset
730 """""""""""""""""""""""""""""
anatofuz
parents:
diff changeset
731 Warn on uses of the 'gets' function.
anatofuz
parents:
diff changeset
732
anatofuz
parents:
diff changeset
733 .. code-block:: c
anatofuz
parents:
diff changeset
734
anatofuz
parents:
diff changeset
735 void test() {
anatofuz
parents:
diff changeset
736 char buff[1024];
anatofuz
parents:
diff changeset
737 gets(buff); // warn
anatofuz
parents:
diff changeset
738 }
anatofuz
parents:
diff changeset
739
anatofuz
parents:
diff changeset
740 .. _security-insecureAPI-mkstemp:
anatofuz
parents:
diff changeset
741
anatofuz
parents:
diff changeset
742 security.insecureAPI.mkstemp (C)
anatofuz
parents:
diff changeset
743 """"""""""""""""""""""""""""""""
anatofuz
parents:
diff changeset
744 Warn when 'mkstemp' is passed fewer than 6 X's in the format string.
anatofuz
parents:
diff changeset
745
anatofuz
parents:
diff changeset
746 .. code-block:: c
anatofuz
parents:
diff changeset
747
anatofuz
parents:
diff changeset
748 void test() {
anatofuz
parents:
diff changeset
749 mkstemp("XX"); // warn
anatofuz
parents:
diff changeset
750 }
anatofuz
parents:
diff changeset
751
anatofuz
parents:
diff changeset
752 .. _security-insecureAPI-mktemp:
anatofuz
parents:
diff changeset
753
anatofuz
parents:
diff changeset
754 security.insecureAPI.mktemp (C)
anatofuz
parents:
diff changeset
755 """""""""""""""""""""""""""""""
anatofuz
parents:
diff changeset
756 Warn on uses of the ``mktemp`` function.
anatofuz
parents:
diff changeset
757
anatofuz
parents:
diff changeset
758 .. code-block:: c
anatofuz
parents:
diff changeset
759
anatofuz
parents:
diff changeset
760 void test() {
anatofuz
parents:
diff changeset
761 char *x = mktemp("/tmp/zxcv"); // warn: insecure, use mkstemp
anatofuz
parents:
diff changeset
762 }
anatofuz
parents:
diff changeset
763
anatofuz
parents:
diff changeset
764 .. _security-insecureAPI-rand:
anatofuz
parents:
diff changeset
765
anatofuz
parents:
diff changeset
766 security.insecureAPI.rand (C)
anatofuz
parents:
diff changeset
767 """""""""""""""""""""""""""""
anatofuz
parents:
diff changeset
768 Warn on uses of inferior random number generating functions (only if arc4random function is available):
anatofuz
parents:
diff changeset
769 ``drand48, erand48, jrand48, lcong48, lrand48, mrand48, nrand48, random, rand_r``.
anatofuz
parents:
diff changeset
770
anatofuz
parents:
diff changeset
771 .. code-block:: c
anatofuz
parents:
diff changeset
772
anatofuz
parents:
diff changeset
773 void test() {
anatofuz
parents:
diff changeset
774 random(); // warn
anatofuz
parents:
diff changeset
775 }
anatofuz
parents:
diff changeset
776
anatofuz
parents:
diff changeset
777 .. _security-insecureAPI-strcpy:
anatofuz
parents:
diff changeset
778
anatofuz
parents:
diff changeset
779 security.insecureAPI.strcpy (C)
anatofuz
parents:
diff changeset
780 """""""""""""""""""""""""""""""
anatofuz
parents:
diff changeset
781 Warn on uses of the ``strcpy`` and ``strcat`` functions.
anatofuz
parents:
diff changeset
782
anatofuz
parents:
diff changeset
783 .. code-block:: c
anatofuz
parents:
diff changeset
784
anatofuz
parents:
diff changeset
785 void test() {
anatofuz
parents:
diff changeset
786 char x[4];
anatofuz
parents:
diff changeset
787 char *y = "abcd";
anatofuz
parents:
diff changeset
788
anatofuz
parents:
diff changeset
789 strcpy(x, y); // warn
anatofuz
parents:
diff changeset
790 }
anatofuz
parents:
diff changeset
791
anatofuz
parents:
diff changeset
792
anatofuz
parents:
diff changeset
793 .. _security-insecureAPI-vfork:
anatofuz
parents:
diff changeset
794
anatofuz
parents:
diff changeset
795 security.insecureAPI.vfork (C)
anatofuz
parents:
diff changeset
796 """"""""""""""""""""""""""""""
anatofuz
parents:
diff changeset
797 Warn on uses of the 'vfork' function.
anatofuz
parents:
diff changeset
798
anatofuz
parents:
diff changeset
799 .. code-block:: c
anatofuz
parents:
diff changeset
800
anatofuz
parents:
diff changeset
801 void test() {
anatofuz
parents:
diff changeset
802 vfork(); // warn
anatofuz
parents:
diff changeset
803 }
anatofuz
parents:
diff changeset
804
anatofuz
parents:
diff changeset
805 .. _security-insecureAPI-DeprecatedOrUnsafeBufferHandling:
anatofuz
parents:
diff changeset
806
anatofuz
parents:
diff changeset
807 security.insecureAPI.DeprecatedOrUnsafeBufferHandling (C)
anatofuz
parents:
diff changeset
808 """""""""""""""""""""""""""""""""""""""""""""""""""""""""
anatofuz
parents:
diff changeset
809 Warn on occurrences of unsafe or deprecated buffer handling functions, which now have a secure variant: ``sprintf, vsprintf, scanf, wscanf, fscanf, fwscanf, vscanf, vwscanf, vfscanf, vfwscanf, sscanf, swscanf, vsscanf, vswscanf, swprintf, snprintf, vswprintf, vsnprintf, memcpy, memmove, strncpy, strncat, memset``
anatofuz
parents:
diff changeset
810
anatofuz
parents:
diff changeset
811 .. code-block:: c
anatofuz
parents:
diff changeset
812
anatofuz
parents:
diff changeset
813 void test() {
anatofuz
parents:
diff changeset
814 char buf [5];
anatofuz
parents:
diff changeset
815 strncpy(buf, "a", 1); // warn
anatofuz
parents:
diff changeset
816 }
anatofuz
parents:
diff changeset
817
anatofuz
parents:
diff changeset
818 .. _unix-checkers:
anatofuz
parents:
diff changeset
819
anatofuz
parents:
diff changeset
820 unix
anatofuz
parents:
diff changeset
821 ^^^^
anatofuz
parents:
diff changeset
822 POSIX/Unix checkers.
anatofuz
parents:
diff changeset
823
anatofuz
parents:
diff changeset
824 .. _unix-API:
anatofuz
parents:
diff changeset
825
anatofuz
parents:
diff changeset
826 unix.API (C)
anatofuz
parents:
diff changeset
827 """"""""""""
anatofuz
parents:
diff changeset
828 Check calls to various UNIX/Posix functions: ``open, pthread_once, calloc, malloc, realloc, alloca``.
anatofuz
parents:
diff changeset
829
anatofuz
parents:
diff changeset
830 .. literalinclude:: checkers/unix_api_example.c
anatofuz
parents:
diff changeset
831 :language: c
anatofuz
parents:
diff changeset
832
anatofuz
parents:
diff changeset
833 .. _unix-Malloc:
anatofuz
parents:
diff changeset
834
anatofuz
parents:
diff changeset
835 unix.Malloc (C)
anatofuz
parents:
diff changeset
836 """""""""""""""
anatofuz
parents:
diff changeset
837 Check for memory leaks, double free, and use-after-free problems. Traces memory managed by malloc()/free().
anatofuz
parents:
diff changeset
838
anatofuz
parents:
diff changeset
839 .. literalinclude:: checkers/unix_malloc_example.c
anatofuz
parents:
diff changeset
840 :language: c
anatofuz
parents:
diff changeset
841
anatofuz
parents:
diff changeset
842 .. _unix-MallocSizeof:
anatofuz
parents:
diff changeset
843
anatofuz
parents:
diff changeset
844 unix.MallocSizeof (C)
anatofuz
parents:
diff changeset
845 """""""""""""""""""""
anatofuz
parents:
diff changeset
846 Check for dubious ``malloc`` arguments involving ``sizeof``.
anatofuz
parents:
diff changeset
847
anatofuz
parents:
diff changeset
848 .. code-block:: c
anatofuz
parents:
diff changeset
849
anatofuz
parents:
diff changeset
850 void test() {
anatofuz
parents:
diff changeset
851 long *p = malloc(sizeof(short));
anatofuz
parents:
diff changeset
852 // warn: result is converted to 'long *', which is
anatofuz
parents:
diff changeset
853 // incompatible with operand type 'short'
anatofuz
parents:
diff changeset
854 free(p);
anatofuz
parents:
diff changeset
855 }
anatofuz
parents:
diff changeset
856
anatofuz
parents:
diff changeset
857 .. _unix-MismatchedDeallocator:
anatofuz
parents:
diff changeset
858
anatofuz
parents:
diff changeset
859 unix.MismatchedDeallocator (C, C++)
anatofuz
parents:
diff changeset
860 """""""""""""""""""""""""""""""""""
anatofuz
parents:
diff changeset
861 Check for mismatched deallocators.
anatofuz
parents:
diff changeset
862
anatofuz
parents:
diff changeset
863 .. literalinclude:: checkers/mismatched_deallocator_example.cpp
anatofuz
parents:
diff changeset
864 :language: c
anatofuz
parents:
diff changeset
865
anatofuz
parents:
diff changeset
866 .. _unix-Vfork:
anatofuz
parents:
diff changeset
867
anatofuz
parents:
diff changeset
868 unix.Vfork (C)
anatofuz
parents:
diff changeset
869 """"""""""""""
anatofuz
parents:
diff changeset
870 Check for proper usage of ``vfork``.
anatofuz
parents:
diff changeset
871
anatofuz
parents:
diff changeset
872 .. code-block:: c
anatofuz
parents:
diff changeset
873
anatofuz
parents:
diff changeset
874 int test(int x) {
anatofuz
parents:
diff changeset
875 pid_t pid = vfork(); // warn
anatofuz
parents:
diff changeset
876 if (pid != 0)
anatofuz
parents:
diff changeset
877 return 0;
anatofuz
parents:
diff changeset
878
anatofuz
parents:
diff changeset
879 switch (x) {
anatofuz
parents:
diff changeset
880 case 0:
anatofuz
parents:
diff changeset
881 pid = 1;
anatofuz
parents:
diff changeset
882 execl("", "", 0);
anatofuz
parents:
diff changeset
883 _exit(1);
anatofuz
parents:
diff changeset
884 break;
anatofuz
parents:
diff changeset
885 case 1:
anatofuz
parents:
diff changeset
886 x = 0; // warn: this assignment is prohibited
anatofuz
parents:
diff changeset
887 break;
anatofuz
parents:
diff changeset
888 case 2:
anatofuz
parents:
diff changeset
889 foo(); // warn: this function call is prohibited
anatofuz
parents:
diff changeset
890 break;
anatofuz
parents:
diff changeset
891 default:
anatofuz
parents:
diff changeset
892 return 0; // warn: return is prohibited
anatofuz
parents:
diff changeset
893 }
anatofuz
parents:
diff changeset
894
anatofuz
parents:
diff changeset
895 while(1);
anatofuz
parents:
diff changeset
896 }
anatofuz
parents:
diff changeset
897
anatofuz
parents:
diff changeset
898 .. _unix-cstring-BadSizeArg:
anatofuz
parents:
diff changeset
899
anatofuz
parents:
diff changeset
900 unix.cstring.BadSizeArg (C)
anatofuz
parents:
diff changeset
901 """""""""""""""""""""""""""
anatofuz
parents:
diff changeset
902 Check the size argument passed into C string functions for common erroneous patterns. Use ``-Wno-strncat-size`` compiler option to mute other ``strncat``-related compiler warnings.
anatofuz
parents:
diff changeset
903
anatofuz
parents:
diff changeset
904 .. code-block:: c
anatofuz
parents:
diff changeset
905
anatofuz
parents:
diff changeset
906 void test() {
anatofuz
parents:
diff changeset
907 char dest[3];
anatofuz
parents:
diff changeset
908 strncat(dest, """""""""""""""""""""""""*", sizeof(dest));
anatofuz
parents:
diff changeset
909 // warn: potential buffer overflow
anatofuz
parents:
diff changeset
910 }
anatofuz
parents:
diff changeset
911
anatofuz
parents:
diff changeset
912 .. _unix-cstrisng-NullArg:
anatofuz
parents:
diff changeset
913
anatofuz
parents:
diff changeset
914 unix.cstrisng.NullArg (C)
anatofuz
parents:
diff changeset
915 """""""""""""""""""""""""
anatofuz
parents:
diff changeset
916 Check for null pointers being passed as arguments to C string functions:
anatofuz
parents:
diff changeset
917 ``strlen, strnlen, strcpy, strncpy, strcat, strncat, strcmp, strncmp, strcasecmp, strncasecmp``.
anatofuz
parents:
diff changeset
918
anatofuz
parents:
diff changeset
919 .. code-block:: c
anatofuz
parents:
diff changeset
920
anatofuz
parents:
diff changeset
921 int test() {
anatofuz
parents:
diff changeset
922 return strlen(0); // warn
anatofuz
parents:
diff changeset
923 }
anatofuz
parents:
diff changeset
924
anatofuz
parents:
diff changeset
925 .. _osx-checkers:
anatofuz
parents:
diff changeset
926
anatofuz
parents:
diff changeset
927 osx
anatofuz
parents:
diff changeset
928 ^^^
anatofuz
parents:
diff changeset
929 macOS checkers.
anatofuz
parents:
diff changeset
930
anatofuz
parents:
diff changeset
931 .. _osx-API:
anatofuz
parents:
diff changeset
932
anatofuz
parents:
diff changeset
933 osx.API (C)
anatofuz
parents:
diff changeset
934 """""""""""
anatofuz
parents:
diff changeset
935 Check for proper uses of various Apple APIs.
anatofuz
parents:
diff changeset
936
anatofuz
parents:
diff changeset
937 .. code-block:: objc
anatofuz
parents:
diff changeset
938
anatofuz
parents:
diff changeset
939 void test() {
anatofuz
parents:
diff changeset
940 dispatch_once_t pred = 0;
anatofuz
parents:
diff changeset
941 dispatch_once(&pred, ^(){}); // warn: dispatch_once uses local
anatofuz
parents:
diff changeset
942 }
anatofuz
parents:
diff changeset
943
anatofuz
parents:
diff changeset
944 .. _osx-NumberObjectConversion:
anatofuz
parents:
diff changeset
945
anatofuz
parents:
diff changeset
946 osx.NumberObjectConversion (C, C++, ObjC)
anatofuz
parents:
diff changeset
947 """""""""""""""""""""""""""""""""""""""""
anatofuz
parents:
diff changeset
948 Check for erroneous conversions of objects representing numbers into numbers.
anatofuz
parents:
diff changeset
949
anatofuz
parents:
diff changeset
950 .. code-block:: objc
anatofuz
parents:
diff changeset
951
anatofuz
parents:
diff changeset
952 NSNumber *photoCount = [albumDescriptor objectForKey:@"PhotoCount"];
anatofuz
parents:
diff changeset
953 // Warning: Comparing a pointer value of type 'NSNumber *'
anatofuz
parents:
diff changeset
954 // to a scalar integer value
anatofuz
parents:
diff changeset
955 if (photoCount > 0) {
anatofuz
parents:
diff changeset
956 [self displayPhotos];
anatofuz
parents:
diff changeset
957 }
anatofuz
parents:
diff changeset
958
anatofuz
parents:
diff changeset
959 .. _osx-ObjCProperty:
anatofuz
parents:
diff changeset
960
anatofuz
parents:
diff changeset
961 osx.ObjCProperty (ObjC)
anatofuz
parents:
diff changeset
962 """""""""""""""""""""""
anatofuz
parents:
diff changeset
963 Check for proper uses of Objective-C properties.
anatofuz
parents:
diff changeset
964
anatofuz
parents:
diff changeset
965 .. code-block:: objc
anatofuz
parents:
diff changeset
966
anatofuz
parents:
diff changeset
967 NSNumber *photoCount = [albumDescriptor objectForKey:@"PhotoCount"];
anatofuz
parents:
diff changeset
968 // Warning: Comparing a pointer value of type 'NSNumber *'
anatofuz
parents:
diff changeset
969 // to a scalar integer value
anatofuz
parents:
diff changeset
970 if (photoCount > 0) {
anatofuz
parents:
diff changeset
971 [self displayPhotos];
anatofuz
parents:
diff changeset
972 }
anatofuz
parents:
diff changeset
973
anatofuz
parents:
diff changeset
974
anatofuz
parents:
diff changeset
975 .. _osx-SecKeychainAPI:
anatofuz
parents:
diff changeset
976
anatofuz
parents:
diff changeset
977 osx.SecKeychainAPI (C)
anatofuz
parents:
diff changeset
978 """"""""""""""""""""""
anatofuz
parents:
diff changeset
979 Check for proper uses of Secure Keychain APIs.
anatofuz
parents:
diff changeset
980
anatofuz
parents:
diff changeset
981 .. literalinclude:: checkers/seckeychainapi_example.m
anatofuz
parents:
diff changeset
982 :language: objc
anatofuz
parents:
diff changeset
983
anatofuz
parents:
diff changeset
984 .. _osx-cocoa-AtSync:
anatofuz
parents:
diff changeset
985
anatofuz
parents:
diff changeset
986 osx.cocoa.AtSync (ObjC)
anatofuz
parents:
diff changeset
987 """""""""""""""""""""""
anatofuz
parents:
diff changeset
988 Check for nil pointers used as mutexes for @synchronized.
anatofuz
parents:
diff changeset
989
anatofuz
parents:
diff changeset
990 .. code-block:: objc
anatofuz
parents:
diff changeset
991
anatofuz
parents:
diff changeset
992 void test(id x) {
anatofuz
parents:
diff changeset
993 if (!x)
anatofuz
parents:
diff changeset
994 @synchronized(x) {} // warn: nil value used as mutex
anatofuz
parents:
diff changeset
995 }
anatofuz
parents:
diff changeset
996
anatofuz
parents:
diff changeset
997 void test() {
anatofuz
parents:
diff changeset
998 id y;
anatofuz
parents:
diff changeset
999 @synchronized(y) {} // warn: uninitialized value used as mutex
anatofuz
parents:
diff changeset
1000 }
anatofuz
parents:
diff changeset
1001
anatofuz
parents:
diff changeset
1002 .. _osx-cocoa-AutoreleaseWrite:
anatofuz
parents:
diff changeset
1003
anatofuz
parents:
diff changeset
1004 osx.cocoa.AutoreleaseWrite
anatofuz
parents:
diff changeset
1005 """"""""""""""""""""""""""
anatofuz
parents:
diff changeset
1006 Warn about potentially crashing writes to autoreleasing objects from different autoreleasing pools in Objective-C.
anatofuz
parents:
diff changeset
1007
anatofuz
parents:
diff changeset
1008 .. _osx-cocoa-ClassRelease:
anatofuz
parents:
diff changeset
1009
anatofuz
parents:
diff changeset
1010 osx.cocoa.ClassRelease (ObjC)
anatofuz
parents:
diff changeset
1011 """""""""""""""""""""""""""""
anatofuz
parents:
diff changeset
1012 Check for sending 'retain', 'release', or 'autorelease' directly to a Class.
anatofuz
parents:
diff changeset
1013
anatofuz
parents:
diff changeset
1014 .. code-block:: objc
anatofuz
parents:
diff changeset
1015
anatofuz
parents:
diff changeset
1016 @interface MyClass : NSObject
anatofuz
parents:
diff changeset
1017 @end
anatofuz
parents:
diff changeset
1018
anatofuz
parents:
diff changeset
1019 void test(void) {
anatofuz
parents:
diff changeset
1020 [MyClass release]; // warn
anatofuz
parents:
diff changeset
1021 }
anatofuz
parents:
diff changeset
1022
anatofuz
parents:
diff changeset
1023 .. _osx-cocoa-Dealloc:
anatofuz
parents:
diff changeset
1024
anatofuz
parents:
diff changeset
1025 osx.cocoa.Dealloc (ObjC)
anatofuz
parents:
diff changeset
1026 """"""""""""""""""""""""
anatofuz
parents:
diff changeset
1027 Warn about Objective-C classes that lack a correct implementation of -dealloc
anatofuz
parents:
diff changeset
1028
anatofuz
parents:
diff changeset
1029 .. literalinclude:: checkers/dealloc_example.m
anatofuz
parents:
diff changeset
1030 :language: objc
anatofuz
parents:
diff changeset
1031
anatofuz
parents:
diff changeset
1032 .. _osx-cocoa-IncompatibleMethodTypes:
anatofuz
parents:
diff changeset
1033
anatofuz
parents:
diff changeset
1034 osx.cocoa.IncompatibleMethodTypes (ObjC)
anatofuz
parents:
diff changeset
1035 """"""""""""""""""""""""""""""""""""""""
anatofuz
parents:
diff changeset
1036 Warn about Objective-C method signatures with type incompatibilities.
anatofuz
parents:
diff changeset
1037
anatofuz
parents:
diff changeset
1038 .. code-block:: objc
anatofuz
parents:
diff changeset
1039
anatofuz
parents:
diff changeset
1040 @interface MyClass1 : NSObject
anatofuz
parents:
diff changeset
1041 - (int)foo;
anatofuz
parents:
diff changeset
1042 @end
anatofuz
parents:
diff changeset
1043
anatofuz
parents:
diff changeset
1044 @implementation MyClass1
anatofuz
parents:
diff changeset
1045 - (int)foo { return 1; }
anatofuz
parents:
diff changeset
1046 @end
anatofuz
parents:
diff changeset
1047
anatofuz
parents:
diff changeset
1048 @interface MyClass2 : MyClass1
anatofuz
parents:
diff changeset
1049 - (float)foo;
anatofuz
parents:
diff changeset
1050 @end
anatofuz
parents:
diff changeset
1051
anatofuz
parents:
diff changeset
1052 @implementation MyClass2
anatofuz
parents:
diff changeset
1053 - (float)foo { return 1.0; } // warn
anatofuz
parents:
diff changeset
1054 @end
anatofuz
parents:
diff changeset
1055
anatofuz
parents:
diff changeset
1056 .. _osx-cocoa-Loops:
anatofuz
parents:
diff changeset
1057
anatofuz
parents:
diff changeset
1058 osx.cocoa.Loops
anatofuz
parents:
diff changeset
1059 """""""""""""""
anatofuz
parents:
diff changeset
1060 Improved modeling of loops using Cocoa collection types.
anatofuz
parents:
diff changeset
1061
anatofuz
parents:
diff changeset
1062 .. _osx-cocoa-MissingSuperCall:
anatofuz
parents:
diff changeset
1063
anatofuz
parents:
diff changeset
1064 osx.cocoa.MissingSuperCall (ObjC)
anatofuz
parents:
diff changeset
1065 """""""""""""""""""""""""""""""""
anatofuz
parents:
diff changeset
1066 Warn about Objective-C methods that lack a necessary call to super.
anatofuz
parents:
diff changeset
1067
anatofuz
parents:
diff changeset
1068 .. code-block:: objc
anatofuz
parents:
diff changeset
1069
anatofuz
parents:
diff changeset
1070 @interface Test : UIViewController
anatofuz
parents:
diff changeset
1071 @end
anatofuz
parents:
diff changeset
1072 @implementation test
anatofuz
parents:
diff changeset
1073 - (void)viewDidLoad {} // warn
anatofuz
parents:
diff changeset
1074 @end
anatofuz
parents:
diff changeset
1075
anatofuz
parents:
diff changeset
1076
anatofuz
parents:
diff changeset
1077 .. _osx-cocoa-NSAutoreleasePool:
anatofuz
parents:
diff changeset
1078
anatofuz
parents:
diff changeset
1079 osx.cocoa.NSAutoreleasePool (ObjC)
anatofuz
parents:
diff changeset
1080 """"""""""""""""""""""""""""""""""
anatofuz
parents:
diff changeset
1081 Warn for suboptimal uses of NSAutoreleasePool in Objective-C GC mode.
anatofuz
parents:
diff changeset
1082
anatofuz
parents:
diff changeset
1083 .. code-block:: objc
anatofuz
parents:
diff changeset
1084
anatofuz
parents:
diff changeset
1085 void test() {
anatofuz
parents:
diff changeset
1086 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
anatofuz
parents:
diff changeset
1087 [pool release]; // warn
anatofuz
parents:
diff changeset
1088 }
anatofuz
parents:
diff changeset
1089
anatofuz
parents:
diff changeset
1090 .. _osx-cocoa-NSError:
anatofuz
parents:
diff changeset
1091
anatofuz
parents:
diff changeset
1092 osx.cocoa.NSError (ObjC)
anatofuz
parents:
diff changeset
1093 """"""""""""""""""""""""
anatofuz
parents:
diff changeset
1094 Check usage of NSError parameters.
anatofuz
parents:
diff changeset
1095
anatofuz
parents:
diff changeset
1096 .. code-block:: objc
anatofuz
parents:
diff changeset
1097
anatofuz
parents:
diff changeset
1098 @interface A : NSObject
anatofuz
parents:
diff changeset
1099 - (void)foo:(NSError """""""""""""""""""""""")error;
anatofuz
parents:
diff changeset
1100 @end
anatofuz
parents:
diff changeset
1101
anatofuz
parents:
diff changeset
1102 @implementation A
anatofuz
parents:
diff changeset
1103 - (void)foo:(NSError """""""""""""""""""""""")error {
anatofuz
parents:
diff changeset
1104 // warn: method accepting NSError"""""""""""""""""""""""" should have a non-void
anatofuz
parents:
diff changeset
1105 // return value
anatofuz
parents:
diff changeset
1106 }
anatofuz
parents:
diff changeset
1107 @end
anatofuz
parents:
diff changeset
1108
anatofuz
parents:
diff changeset
1109 @interface A : NSObject
anatofuz
parents:
diff changeset
1110 - (BOOL)foo:(NSError """""""""""""""""""""""")error;
anatofuz
parents:
diff changeset
1111 @end
anatofuz
parents:
diff changeset
1112
anatofuz
parents:
diff changeset
1113 @implementation A
anatofuz
parents:
diff changeset
1114 - (BOOL)foo:(NSError """""""""""""""""""""""")error {
anatofuz
parents:
diff changeset
1115 *error = 0; // warn: potential null dereference
anatofuz
parents:
diff changeset
1116 return 0;
anatofuz
parents:
diff changeset
1117 }
anatofuz
parents:
diff changeset
1118 @end
anatofuz
parents:
diff changeset
1119
anatofuz
parents:
diff changeset
1120 .. _osx-cocoa-NilArg:
anatofuz
parents:
diff changeset
1121
anatofuz
parents:
diff changeset
1122 osx.cocoa.NilArg (ObjC)
anatofuz
parents:
diff changeset
1123 """""""""""""""""""""""
anatofuz
parents:
diff changeset
1124 Check for prohibited nil arguments to ObjC method calls.
anatofuz
parents:
diff changeset
1125
anatofuz
parents:
diff changeset
1126 - caseInsensitiveCompare:
anatofuz
parents:
diff changeset
1127 - compare:
anatofuz
parents:
diff changeset
1128 - compare:options:
anatofuz
parents:
diff changeset
1129 - compare:options:range:
anatofuz
parents:
diff changeset
1130 - compare:options:range:locale:
anatofuz
parents:
diff changeset
1131 - componentsSeparatedByCharactersInSet:
anatofuz
parents:
diff changeset
1132 - initWithFormat:
anatofuz
parents:
diff changeset
1133
anatofuz
parents:
diff changeset
1134 .. code-block:: objc
anatofuz
parents:
diff changeset
1135
anatofuz
parents:
diff changeset
1136 NSComparisonResult test(NSString *s) {
anatofuz
parents:
diff changeset
1137 NSString *aString = nil;
anatofuz
parents:
diff changeset
1138 return [s caseInsensitiveCompare:aString];
anatofuz
parents:
diff changeset
1139 // warn: argument to 'NSString' method
anatofuz
parents:
diff changeset
1140 // 'caseInsensitiveCompare:' cannot be nil
anatofuz
parents:
diff changeset
1141 }
anatofuz
parents:
diff changeset
1142
anatofuz
parents:
diff changeset
1143
anatofuz
parents:
diff changeset
1144 .. _osx-cocoa-NonNilReturnValue:
anatofuz
parents:
diff changeset
1145
anatofuz
parents:
diff changeset
1146 osx.cocoa.NonNilReturnValue
anatofuz
parents:
diff changeset
1147 """""""""""""""""""""""""""
anatofuz
parents:
diff changeset
1148 Models the APIs that are guaranteed to return a non-nil value.
anatofuz
parents:
diff changeset
1149
anatofuz
parents:
diff changeset
1150 .. _osx-cocoa-ObjCGenerics:
anatofuz
parents:
diff changeset
1151
anatofuz
parents:
diff changeset
1152 osx.cocoa.ObjCGenerics (ObjC)
anatofuz
parents:
diff changeset
1153 """""""""""""""""""""""""""""
anatofuz
parents:
diff changeset
1154 Check for type errors when using Objective-C generics.
anatofuz
parents:
diff changeset
1155
anatofuz
parents:
diff changeset
1156 .. code-block:: objc
anatofuz
parents:
diff changeset
1157
anatofuz
parents:
diff changeset
1158 NSMutableArray *names = [NSMutableArray array];
anatofuz
parents:
diff changeset
1159 NSMutableArray *birthDates = names;
anatofuz
parents:
diff changeset
1160
anatofuz
parents:
diff changeset
1161 // Warning: Conversion from value of type 'NSDate *'
anatofuz
parents:
diff changeset
1162 // to incompatible type 'NSString *'
anatofuz
parents:
diff changeset
1163 [birthDates addObject: [NSDate date]];
anatofuz
parents:
diff changeset
1164
anatofuz
parents:
diff changeset
1165 .. _osx-cocoa-RetainCount:
anatofuz
parents:
diff changeset
1166
anatofuz
parents:
diff changeset
1167 osx.cocoa.RetainCount (ObjC)
anatofuz
parents:
diff changeset
1168 """"""""""""""""""""""""""""
anatofuz
parents:
diff changeset
1169 Check for leaks and improper reference count management
anatofuz
parents:
diff changeset
1170
anatofuz
parents:
diff changeset
1171 .. code-block:: objc
anatofuz
parents:
diff changeset
1172
anatofuz
parents:
diff changeset
1173 void test() {
anatofuz
parents:
diff changeset
1174 NSString *s = [[NSString alloc] init]; // warn
anatofuz
parents:
diff changeset
1175 }
anatofuz
parents:
diff changeset
1176
anatofuz
parents:
diff changeset
1177 CFStringRef test(char *bytes) {
anatofuz
parents:
diff changeset
1178 return CFStringCreateWithCStringNoCopy(
anatofuz
parents:
diff changeset
1179 0, bytes, NSNEXTSTEPStringEncoding, 0); // warn
anatofuz
parents:
diff changeset
1180 }
anatofuz
parents:
diff changeset
1181
anatofuz
parents:
diff changeset
1182
anatofuz
parents:
diff changeset
1183 .. _osx-cocoa-RunLoopAutoreleaseLeak:
anatofuz
parents:
diff changeset
1184
anatofuz
parents:
diff changeset
1185 osx.cocoa.RunLoopAutoreleaseLeak
anatofuz
parents:
diff changeset
1186 """"""""""""""""""""""""""""""""
anatofuz
parents:
diff changeset
1187 Check for leaked memory in autorelease pools that will never be drained.
anatofuz
parents:
diff changeset
1188
anatofuz
parents:
diff changeset
1189 .. _osx-cocoa-SelfInit:
anatofuz
parents:
diff changeset
1190
anatofuz
parents:
diff changeset
1191 osx.cocoa.SelfInit (ObjC)
anatofuz
parents:
diff changeset
1192 """""""""""""""""""""""""
anatofuz
parents:
diff changeset
1193 Check that 'self' is properly initialized inside an initializer method.
anatofuz
parents:
diff changeset
1194
anatofuz
parents:
diff changeset
1195 .. code-block:: objc
anatofuz
parents:
diff changeset
1196
anatofuz
parents:
diff changeset
1197 @interface MyObj : NSObject {
anatofuz
parents:
diff changeset
1198 id x;
anatofuz
parents:
diff changeset
1199 }
anatofuz
parents:
diff changeset
1200 - (id)init;
anatofuz
parents:
diff changeset
1201 @end
anatofuz
parents:
diff changeset
1202
anatofuz
parents:
diff changeset
1203 @implementation MyObj
anatofuz
parents:
diff changeset
1204 - (id)init {
anatofuz
parents:
diff changeset
1205 [super init];
anatofuz
parents:
diff changeset
1206 x = 0; // warn: instance variable used while 'self' is not
anatofuz
parents:
diff changeset
1207 // initialized
anatofuz
parents:
diff changeset
1208 return 0;
anatofuz
parents:
diff changeset
1209 }
anatofuz
parents:
diff changeset
1210 @end
anatofuz
parents:
diff changeset
1211
anatofuz
parents:
diff changeset
1212 @interface MyObj : NSObject
anatofuz
parents:
diff changeset
1213 - (id)init;
anatofuz
parents:
diff changeset
1214 @end
anatofuz
parents:
diff changeset
1215
anatofuz
parents:
diff changeset
1216 @implementation MyObj
anatofuz
parents:
diff changeset
1217 - (id)init {
anatofuz
parents:
diff changeset
1218 [super init];
anatofuz
parents:
diff changeset
1219 return self; // warn: returning uninitialized 'self'
anatofuz
parents:
diff changeset
1220 }
anatofuz
parents:
diff changeset
1221 @end
anatofuz
parents:
diff changeset
1222
anatofuz
parents:
diff changeset
1223 .. _osx-cocoa-SuperDealloc:
anatofuz
parents:
diff changeset
1224
anatofuz
parents:
diff changeset
1225 osx.cocoa.SuperDealloc (ObjC)
anatofuz
parents:
diff changeset
1226 """""""""""""""""""""""""""""
anatofuz
parents:
diff changeset
1227 Warn about improper use of '[super dealloc]' in Objective-C.
anatofuz
parents:
diff changeset
1228
anatofuz
parents:
diff changeset
1229 .. code-block:: objc
anatofuz
parents:
diff changeset
1230
anatofuz
parents:
diff changeset
1231 @interface SuperDeallocThenReleaseIvarClass : NSObject {
anatofuz
parents:
diff changeset
1232 NSObject *_ivar;
anatofuz
parents:
diff changeset
1233 }
anatofuz
parents:
diff changeset
1234 @end
anatofuz
parents:
diff changeset
1235
anatofuz
parents:
diff changeset
1236 @implementation SuperDeallocThenReleaseIvarClass
anatofuz
parents:
diff changeset
1237 - (void)dealloc {
anatofuz
parents:
diff changeset
1238 [super dealloc];
anatofuz
parents:
diff changeset
1239 [_ivar release]; // warn
anatofuz
parents:
diff changeset
1240 }
anatofuz
parents:
diff changeset
1241 @end
anatofuz
parents:
diff changeset
1242
anatofuz
parents:
diff changeset
1243 .. _osx-cocoa-UnusedIvars:
anatofuz
parents:
diff changeset
1244
anatofuz
parents:
diff changeset
1245 osx.cocoa.UnusedIvars (ObjC)
anatofuz
parents:
diff changeset
1246 """"""""""""""""""""""""""""
anatofuz
parents:
diff changeset
1247 Warn about private ivars that are never used.
anatofuz
parents:
diff changeset
1248
anatofuz
parents:
diff changeset
1249 .. code-block:: objc
anatofuz
parents:
diff changeset
1250
anatofuz
parents:
diff changeset
1251 @interface MyObj : NSObject {
anatofuz
parents:
diff changeset
1252 @private
anatofuz
parents:
diff changeset
1253 id x; // warn
anatofuz
parents:
diff changeset
1254 }
anatofuz
parents:
diff changeset
1255 @end
anatofuz
parents:
diff changeset
1256
anatofuz
parents:
diff changeset
1257 @implementation MyObj
anatofuz
parents:
diff changeset
1258 @end
anatofuz
parents:
diff changeset
1259
anatofuz
parents:
diff changeset
1260 .. _osx-cocoa-VariadicMethodTypes:
anatofuz
parents:
diff changeset
1261
anatofuz
parents:
diff changeset
1262 osx.cocoa.VariadicMethodTypes (ObjC)
anatofuz
parents:
diff changeset
1263 """"""""""""""""""""""""""""""""""""
anatofuz
parents:
diff changeset
1264 Check for passing non-Objective-C types to variadic collection
anatofuz
parents:
diff changeset
1265 initialization methods that expect only Objective-C types.
anatofuz
parents:
diff changeset
1266
anatofuz
parents:
diff changeset
1267 .. code-block:: objc
anatofuz
parents:
diff changeset
1268
anatofuz
parents:
diff changeset
1269 void test() {
anatofuz
parents:
diff changeset
1270 [NSSet setWithObjects:@"Foo", "Bar", nil];
anatofuz
parents:
diff changeset
1271 // warn: argument should be an ObjC pointer type, not 'char *'
anatofuz
parents:
diff changeset
1272 }
anatofuz
parents:
diff changeset
1273
anatofuz
parents:
diff changeset
1274 .. _osx-coreFoundation-CFError:
anatofuz
parents:
diff changeset
1275
anatofuz
parents:
diff changeset
1276 osx.coreFoundation.CFError (C)
anatofuz
parents:
diff changeset
1277 """"""""""""""""""""""""""""""
anatofuz
parents:
diff changeset
1278 Check usage of CFErrorRef* parameters
anatofuz
parents:
diff changeset
1279
anatofuz
parents:
diff changeset
1280 .. code-block:: c
anatofuz
parents:
diff changeset
1281
anatofuz
parents:
diff changeset
1282 void test(CFErrorRef *error) {
anatofuz
parents:
diff changeset
1283 // warn: function accepting CFErrorRef* should have a
anatofuz
parents:
diff changeset
1284 // non-void return
anatofuz
parents:
diff changeset
1285 }
anatofuz
parents:
diff changeset
1286
anatofuz
parents:
diff changeset
1287 int foo(CFErrorRef *error) {
anatofuz
parents:
diff changeset
1288 *error = 0; // warn: potential null dereference
anatofuz
parents:
diff changeset
1289 return 0;
anatofuz
parents:
diff changeset
1290 }
anatofuz
parents:
diff changeset
1291
anatofuz
parents:
diff changeset
1292 .. _osx-coreFoundation-CFNumber:
anatofuz
parents:
diff changeset
1293
anatofuz
parents:
diff changeset
1294 osx.coreFoundation.CFNumber (C)
anatofuz
parents:
diff changeset
1295 """""""""""""""""""""""""""""""
anatofuz
parents:
diff changeset
1296 Check for proper uses of CFNumber APIs.
anatofuz
parents:
diff changeset
1297
anatofuz
parents:
diff changeset
1298 .. code-block:: c
anatofuz
parents:
diff changeset
1299
anatofuz
parents:
diff changeset
1300 CFNumberRef test(unsigned char x) {
anatofuz
parents:
diff changeset
1301 return CFNumberCreate(0, kCFNumberSInt16Type, &x);
anatofuz
parents:
diff changeset
1302 // warn: 8 bit integer is used to initialize a 16 bit integer
anatofuz
parents:
diff changeset
1303 }
anatofuz
parents:
diff changeset
1304
anatofuz
parents:
diff changeset
1305 .. _osx-coreFoundation-CFRetainRelease:
anatofuz
parents:
diff changeset
1306
anatofuz
parents:
diff changeset
1307 osx.coreFoundation.CFRetainRelease (C)
anatofuz
parents:
diff changeset
1308 """"""""""""""""""""""""""""""""""""""
anatofuz
parents:
diff changeset
1309 Check for null arguments to CFRetain/CFRelease/CFMakeCollectable.
anatofuz
parents:
diff changeset
1310
anatofuz
parents:
diff changeset
1311 .. code-block:: c
anatofuz
parents:
diff changeset
1312
anatofuz
parents:
diff changeset
1313 void test(CFTypeRef p) {
anatofuz
parents:
diff changeset
1314 if (!p)
anatofuz
parents:
diff changeset
1315 CFRetain(p); // warn
anatofuz
parents:
diff changeset
1316 }
anatofuz
parents:
diff changeset
1317
anatofuz
parents:
diff changeset
1318 void test(int x, CFTypeRef p) {
anatofuz
parents:
diff changeset
1319 if (p)
anatofuz
parents:
diff changeset
1320 return;
anatofuz
parents:
diff changeset
1321
anatofuz
parents:
diff changeset
1322 CFRelease(p); // warn
anatofuz
parents:
diff changeset
1323 }
anatofuz
parents:
diff changeset
1324
anatofuz
parents:
diff changeset
1325 .. _osx-coreFoundation-containers-OutOfBounds:
anatofuz
parents:
diff changeset
1326
anatofuz
parents:
diff changeset
1327 osx.coreFoundation.containers.OutOfBounds (C)
anatofuz
parents:
diff changeset
1328 """""""""""""""""""""""""""""""""""""""""""""
anatofuz
parents:
diff changeset
1329 Checks for index out-of-bounds when using 'CFArray' API.
anatofuz
parents:
diff changeset
1330
anatofuz
parents:
diff changeset
1331 .. code-block:: c
anatofuz
parents:
diff changeset
1332
anatofuz
parents:
diff changeset
1333 void test() {
anatofuz
parents:
diff changeset
1334 CFArrayRef A = CFArrayCreate(0, 0, 0, &kCFTypeArrayCallBacks);
anatofuz
parents:
diff changeset
1335 CFArrayGetValueAtIndex(A, 0); // warn
anatofuz
parents:
diff changeset
1336 }
anatofuz
parents:
diff changeset
1337
anatofuz
parents:
diff changeset
1338 .. _osx-coreFoundation-containers-PointerSizedValues:
anatofuz
parents:
diff changeset
1339
anatofuz
parents:
diff changeset
1340 osx.coreFoundation.containers.PointerSizedValues (C)
anatofuz
parents:
diff changeset
1341 """"""""""""""""""""""""""""""""""""""""""""""""""""
anatofuz
parents:
diff changeset
1342 Warns if 'CFArray', 'CFDictionary', 'CFSet' are created with non-pointer-size values.
anatofuz
parents:
diff changeset
1343
anatofuz
parents:
diff changeset
1344 .. code-block:: c
anatofuz
parents:
diff changeset
1345
anatofuz
parents:
diff changeset
1346 void test() {
anatofuz
parents:
diff changeset
1347 int x[] = { 1 };
anatofuz
parents:
diff changeset
1348 CFArrayRef A = CFArrayCreate(0, (const void """""""""""""""""""""""")x, 1,
anatofuz
parents:
diff changeset
1349 &kCFTypeArrayCallBacks); // warn
anatofuz
parents:
diff changeset
1350 }
anatofuz
parents:
diff changeset
1351
anatofuz
parents:
diff changeset
1352 Fuchsia
anatofuz
parents:
diff changeset
1353 ^^^^^^^
anatofuz
parents:
diff changeset
1354
anatofuz
parents:
diff changeset
1355 Fuchsia is an open source capability-based operating system currently being
anatofuz
parents:
diff changeset
1356 developed by Google. This section describes checkers that can find various
anatofuz
parents:
diff changeset
1357 misuses of Fuchsia APIs.
anatofuz
parents:
diff changeset
1358
anatofuz
parents:
diff changeset
1359 .. _fuchsia-HandleChecker:
anatofuz
parents:
diff changeset
1360
anatofuz
parents:
diff changeset
1361 fuchsia.HandleChecker
anatofuz
parents:
diff changeset
1362 """"""""""""""""""""""""""""
anatofuz
parents:
diff changeset
1363 Handles identify resources. Similar to pointers they can be leaked,
anatofuz
parents:
diff changeset
1364 double freed, or use after freed. This check attempts to find such problems.
anatofuz
parents:
diff changeset
1365
anatofuz
parents:
diff changeset
1366 .. code-block:: cpp
anatofuz
parents:
diff changeset
1367
anatofuz
parents:
diff changeset
1368 void checkLeak08(int tag) {
anatofuz
parents:
diff changeset
1369 zx_handle_t sa, sb;
anatofuz
parents:
diff changeset
1370 zx_channel_create(0, &sa, &sb);
anatofuz
parents:
diff changeset
1371 if (tag)
anatofuz
parents:
diff changeset
1372 zx_handle_close(sa);
anatofuz
parents:
diff changeset
1373 use(sb); // Warn: Potential leak of handle
anatofuz
parents:
diff changeset
1374 zx_handle_close(sb);
anatofuz
parents:
diff changeset
1375 }
anatofuz
parents:
diff changeset
1376
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
1377 WebKit
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
1378 ^^^^^^
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
1379
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
1380 WebKit is an open-source web browser engine available for macOS, iOS and Linux.
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
1381 This section describes checkers that can find issues in WebKit codebase.
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
1382
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
1383 Most of the checkers focus on memory management for which WebKit uses custom implementation of reference counted smartpointers.
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
1384 Checker are formulated in terms related to ref-counting:
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
1385 * *Ref-counted type* is either ``Ref<T>`` or ``RefPtr<T>``.
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
1386 * *Ref-countable type* is any type that implements ``ref()`` and ``deref()`` methods as ``RefPtr<>`` is a template (i. e. relies on duck typing).
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
1387 * *Uncounted type* is ref-countable but not ref-counted type.
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
1388
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
1389 .. _webkit-RefCntblBaseVirtualDtor:
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
1390
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
1391 webkit.RefCntblBaseVirtualDtor
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
1392 """"""""""""""""""""""""""""""""""""
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
1393 All uncounted types used as base classes must have a virtual destructor.
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
1394
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
1395 Ref-counted types hold their ref-countable data by a raw pointer and allow implicit upcasting from ref-counted pointer to derived type to ref-counted pointer to base type. This might lead to an object of (dynamic) derived type being deleted via pointer to the base class type which C++ standard defines as UB in case the base class doesn't have virtual destructor ``[expr.delete]``.
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
1396
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
1397 .. code-block:: cpp
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
1398
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
1399 struct RefCntblBase {
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
1400 void ref() {}
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
1401 void deref() {}
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
1402 };
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
1403
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
1404 struct Derived : RefCntblBase { }; // warn
150
anatofuz
parents:
diff changeset
1405
anatofuz
parents:
diff changeset
1406 .. _alpha-checkers:
anatofuz
parents:
diff changeset
1407
anatofuz
parents:
diff changeset
1408 Experimental Checkers
anatofuz
parents:
diff changeset
1409 ---------------------
anatofuz
parents:
diff changeset
1410
anatofuz
parents:
diff changeset
1411 *These are checkers with known issues or limitations that keep them from being on by default. They are likely to have false positives. Bug reports and especially patches are welcome.*
anatofuz
parents:
diff changeset
1412
anatofuz
parents:
diff changeset
1413 alpha.clone
anatofuz
parents:
diff changeset
1414 ^^^^^^^^^^^
anatofuz
parents:
diff changeset
1415
anatofuz
parents:
diff changeset
1416 .. _alpha-clone-CloneChecker:
anatofuz
parents:
diff changeset
1417
anatofuz
parents:
diff changeset
1418 alpha.clone.CloneChecker (C, C++, ObjC)
anatofuz
parents:
diff changeset
1419 """""""""""""""""""""""""""""""""""""""
anatofuz
parents:
diff changeset
1420 Reports similar pieces of code.
anatofuz
parents:
diff changeset
1421
anatofuz
parents:
diff changeset
1422 .. code-block:: c
anatofuz
parents:
diff changeset
1423
anatofuz
parents:
diff changeset
1424 void log();
anatofuz
parents:
diff changeset
1425
anatofuz
parents:
diff changeset
1426 int max(int a, int b) { // warn
anatofuz
parents:
diff changeset
1427 log();
anatofuz
parents:
diff changeset
1428 if (a > b)
anatofuz
parents:
diff changeset
1429 return a;
anatofuz
parents:
diff changeset
1430 return b;
anatofuz
parents:
diff changeset
1431 }
anatofuz
parents:
diff changeset
1432
anatofuz
parents:
diff changeset
1433 int maxClone(int x, int y) { // similar code here
anatofuz
parents:
diff changeset
1434 log();
anatofuz
parents:
diff changeset
1435 if (x > y)
anatofuz
parents:
diff changeset
1436 return x;
anatofuz
parents:
diff changeset
1437 return y;
anatofuz
parents:
diff changeset
1438 }
anatofuz
parents:
diff changeset
1439
anatofuz
parents:
diff changeset
1440 .. _alpha-core-BoolAssignment:
anatofuz
parents:
diff changeset
1441
anatofuz
parents:
diff changeset
1442 alpha.core.BoolAssignment (ObjC)
anatofuz
parents:
diff changeset
1443 """"""""""""""""""""""""""""""""
anatofuz
parents:
diff changeset
1444 Warn about assigning non-{0,1} values to boolean variables.
anatofuz
parents:
diff changeset
1445
anatofuz
parents:
diff changeset
1446 .. code-block:: objc
anatofuz
parents:
diff changeset
1447
anatofuz
parents:
diff changeset
1448 void test() {
anatofuz
parents:
diff changeset
1449 BOOL b = -1; // warn
anatofuz
parents:
diff changeset
1450 }
anatofuz
parents:
diff changeset
1451
anatofuz
parents:
diff changeset
1452 alpha.core
anatofuz
parents:
diff changeset
1453 ^^^^^^^^^^
anatofuz
parents:
diff changeset
1454
anatofuz
parents:
diff changeset
1455 .. _alpha-core-CallAndMessageUnInitRefArg:
anatofuz
parents:
diff changeset
1456
anatofuz
parents:
diff changeset
1457 alpha.core.CallAndMessageUnInitRefArg (C,C++, ObjC)
anatofuz
parents:
diff changeset
1458 """""""""""""""""""""""""""""""""""""""""""""""""""
anatofuz
parents:
diff changeset
1459 Check for logical errors for function calls and Objective-C
anatofuz
parents:
diff changeset
1460 message expressions (e.g., uninitialized arguments, null function pointers, and pointer to undefined variables).
anatofuz
parents:
diff changeset
1461
anatofuz
parents:
diff changeset
1462 .. code-block:: c
anatofuz
parents:
diff changeset
1463
anatofuz
parents:
diff changeset
1464 void test(void) {
anatofuz
parents:
diff changeset
1465 int t;
anatofuz
parents:
diff changeset
1466 int &p = t;
anatofuz
parents:
diff changeset
1467 int &s = p;
anatofuz
parents:
diff changeset
1468 int &q = s;
anatofuz
parents:
diff changeset
1469 foo(q); // warn
anatofuz
parents:
diff changeset
1470 }
anatofuz
parents:
diff changeset
1471
anatofuz
parents:
diff changeset
1472 void test(void) {
anatofuz
parents:
diff changeset
1473 int x;
anatofuz
parents:
diff changeset
1474 foo(&x); // warn
anatofuz
parents:
diff changeset
1475 }
anatofuz
parents:
diff changeset
1476
anatofuz
parents:
diff changeset
1477 .. _alpha-core-CastSize:
anatofuz
parents:
diff changeset
1478
anatofuz
parents:
diff changeset
1479 alpha.core.CastSize (C)
anatofuz
parents:
diff changeset
1480 """""""""""""""""""""""
anatofuz
parents:
diff changeset
1481 Check when casting a malloc'ed type ``T``, whether the size is a multiple of the size of ``T``.
anatofuz
parents:
diff changeset
1482
anatofuz
parents:
diff changeset
1483 .. code-block:: c
anatofuz
parents:
diff changeset
1484
anatofuz
parents:
diff changeset
1485 void test() {
anatofuz
parents:
diff changeset
1486 int *x = (int *) malloc(11); // warn
anatofuz
parents:
diff changeset
1487 }
anatofuz
parents:
diff changeset
1488
anatofuz
parents:
diff changeset
1489 .. _alpha-core-CastToStruct:
anatofuz
parents:
diff changeset
1490
anatofuz
parents:
diff changeset
1491 alpha.core.CastToStruct (C, C++)
anatofuz
parents:
diff changeset
1492 """"""""""""""""""""""""""""""""
anatofuz
parents:
diff changeset
1493 Check for cast from non-struct pointer to struct pointer.
anatofuz
parents:
diff changeset
1494
anatofuz
parents:
diff changeset
1495 .. code-block:: cpp
anatofuz
parents:
diff changeset
1496
anatofuz
parents:
diff changeset
1497 // C
anatofuz
parents:
diff changeset
1498 struct s {};
anatofuz
parents:
diff changeset
1499
anatofuz
parents:
diff changeset
1500 void test(int *p) {
anatofuz
parents:
diff changeset
1501 struct s *ps = (struct s *) p; // warn
anatofuz
parents:
diff changeset
1502 }
anatofuz
parents:
diff changeset
1503
anatofuz
parents:
diff changeset
1504 // C++
anatofuz
parents:
diff changeset
1505 class c {};
anatofuz
parents:
diff changeset
1506
anatofuz
parents:
diff changeset
1507 void test(int *p) {
anatofuz
parents:
diff changeset
1508 c *pc = (c *) p; // warn
anatofuz
parents:
diff changeset
1509 }
anatofuz
parents:
diff changeset
1510
anatofuz
parents:
diff changeset
1511 .. _alpha-core-Conversion:
anatofuz
parents:
diff changeset
1512
anatofuz
parents:
diff changeset
1513 alpha.core.Conversion (C, C++, ObjC)
anatofuz
parents:
diff changeset
1514 """"""""""""""""""""""""""""""""""""
anatofuz
parents:
diff changeset
1515 Loss of sign/precision in implicit conversions.
anatofuz
parents:
diff changeset
1516
anatofuz
parents:
diff changeset
1517 .. code-block:: c
anatofuz
parents:
diff changeset
1518
anatofuz
parents:
diff changeset
1519 void test(unsigned U, signed S) {
anatofuz
parents:
diff changeset
1520 if (S > 10) {
anatofuz
parents:
diff changeset
1521 if (U < S) {
anatofuz
parents:
diff changeset
1522 }
anatofuz
parents:
diff changeset
1523 }
anatofuz
parents:
diff changeset
1524 if (S < -10) {
anatofuz
parents:
diff changeset
1525 if (U < S) { // warn (loss of sign)
anatofuz
parents:
diff changeset
1526 }
anatofuz
parents:
diff changeset
1527 }
anatofuz
parents:
diff changeset
1528 }
anatofuz
parents:
diff changeset
1529
anatofuz
parents:
diff changeset
1530 void test() {
anatofuz
parents:
diff changeset
1531 long long A = 1LL << 60;
anatofuz
parents:
diff changeset
1532 short X = A; // warn (loss of precision)
anatofuz
parents:
diff changeset
1533 }
anatofuz
parents:
diff changeset
1534
anatofuz
parents:
diff changeset
1535 .. _alpha-core-DynamicTypeChecker:
anatofuz
parents:
diff changeset
1536
anatofuz
parents:
diff changeset
1537 alpha.core.DynamicTypeChecker (ObjC)
anatofuz
parents:
diff changeset
1538 """"""""""""""""""""""""""""""""""""
anatofuz
parents:
diff changeset
1539 Check for cases where the dynamic and the static type of an object are unrelated.
anatofuz
parents:
diff changeset
1540
anatofuz
parents:
diff changeset
1541
anatofuz
parents:
diff changeset
1542 .. code-block:: objc
anatofuz
parents:
diff changeset
1543
anatofuz
parents:
diff changeset
1544 id date = [NSDate date];
anatofuz
parents:
diff changeset
1545
anatofuz
parents:
diff changeset
1546 // Warning: Object has a dynamic type 'NSDate *' which is
anatofuz
parents:
diff changeset
1547 // incompatible with static type 'NSNumber *'"
anatofuz
parents:
diff changeset
1548 NSNumber *number = date;
anatofuz
parents:
diff changeset
1549 [number doubleValue];
anatofuz
parents:
diff changeset
1550
anatofuz
parents:
diff changeset
1551 .. _alpha-core-FixedAddr:
anatofuz
parents:
diff changeset
1552
anatofuz
parents:
diff changeset
1553 alpha.core.FixedAddr (C)
anatofuz
parents:
diff changeset
1554 """"""""""""""""""""""""
anatofuz
parents:
diff changeset
1555 Check for assignment of a fixed address to a pointer.
anatofuz
parents:
diff changeset
1556
anatofuz
parents:
diff changeset
1557 .. code-block:: c
anatofuz
parents:
diff changeset
1558
anatofuz
parents:
diff changeset
1559 void test() {
anatofuz
parents:
diff changeset
1560 int *p;
anatofuz
parents:
diff changeset
1561 p = (int *) 0x10000; // warn
anatofuz
parents:
diff changeset
1562 }
anatofuz
parents:
diff changeset
1563
anatofuz
parents:
diff changeset
1564 .. _alpha-core-IdenticalExpr:
anatofuz
parents:
diff changeset
1565
anatofuz
parents:
diff changeset
1566 alpha.core.IdenticalExpr (C, C++)
anatofuz
parents:
diff changeset
1567 """""""""""""""""""""""""""""""""
anatofuz
parents:
diff changeset
1568 Warn about unintended use of identical expressions in operators.
anatofuz
parents:
diff changeset
1569
anatofuz
parents:
diff changeset
1570 .. code-block:: cpp
anatofuz
parents:
diff changeset
1571
anatofuz
parents:
diff changeset
1572 // C
anatofuz
parents:
diff changeset
1573 void test() {
anatofuz
parents:
diff changeset
1574 int a = 5;
anatofuz
parents:
diff changeset
1575 int b = a | 4 | a; // warn: identical expr on both sides
anatofuz
parents:
diff changeset
1576 }
anatofuz
parents:
diff changeset
1577
anatofuz
parents:
diff changeset
1578 // C++
anatofuz
parents:
diff changeset
1579 bool f(void);
anatofuz
parents:
diff changeset
1580
anatofuz
parents:
diff changeset
1581 void test(bool b) {
anatofuz
parents:
diff changeset
1582 int i = 10;
anatofuz
parents:
diff changeset
1583 if (f()) { // warn: true and false branches are identical
anatofuz
parents:
diff changeset
1584 do {
anatofuz
parents:
diff changeset
1585 i--;
anatofuz
parents:
diff changeset
1586 } while (f());
anatofuz
parents:
diff changeset
1587 } else {
anatofuz
parents:
diff changeset
1588 do {
anatofuz
parents:
diff changeset
1589 i--;
anatofuz
parents:
diff changeset
1590 } while (f());
anatofuz
parents:
diff changeset
1591 }
anatofuz
parents:
diff changeset
1592 }
anatofuz
parents:
diff changeset
1593
anatofuz
parents:
diff changeset
1594 .. _alpha-core-PointerArithm:
anatofuz
parents:
diff changeset
1595
anatofuz
parents:
diff changeset
1596 alpha.core.PointerArithm (C)
anatofuz
parents:
diff changeset
1597 """"""""""""""""""""""""""""
anatofuz
parents:
diff changeset
1598 Check for pointer arithmetic on locations other than array elements.
anatofuz
parents:
diff changeset
1599
anatofuz
parents:
diff changeset
1600 .. code-block:: c
anatofuz
parents:
diff changeset
1601
anatofuz
parents:
diff changeset
1602 void test() {
anatofuz
parents:
diff changeset
1603 int x;
anatofuz
parents:
diff changeset
1604 int *p;
anatofuz
parents:
diff changeset
1605 p = &x + 1; // warn
anatofuz
parents:
diff changeset
1606 }
anatofuz
parents:
diff changeset
1607
anatofuz
parents:
diff changeset
1608 .. _alpha-core-PointerSub:
anatofuz
parents:
diff changeset
1609
anatofuz
parents:
diff changeset
1610 alpha.core.PointerSub (C)
anatofuz
parents:
diff changeset
1611 """""""""""""""""""""""""
anatofuz
parents:
diff changeset
1612 Check for pointer subtractions on two pointers pointing to different memory chunks.
anatofuz
parents:
diff changeset
1613
anatofuz
parents:
diff changeset
1614 .. code-block:: c
anatofuz
parents:
diff changeset
1615
anatofuz
parents:
diff changeset
1616 void test() {
anatofuz
parents:
diff changeset
1617 int x, y;
anatofuz
parents:
diff changeset
1618 int d = &y - &x; // warn
anatofuz
parents:
diff changeset
1619 }
anatofuz
parents:
diff changeset
1620
anatofuz
parents:
diff changeset
1621 .. _alpha-core-SizeofPtr:
anatofuz
parents:
diff changeset
1622
anatofuz
parents:
diff changeset
1623 alpha.core.SizeofPtr (C)
anatofuz
parents:
diff changeset
1624 """"""""""""""""""""""""
anatofuz
parents:
diff changeset
1625 Warn about unintended use of ``sizeof()`` on pointer expressions.
anatofuz
parents:
diff changeset
1626
anatofuz
parents:
diff changeset
1627 .. code-block:: c
anatofuz
parents:
diff changeset
1628
anatofuz
parents:
diff changeset
1629 struct s {};
anatofuz
parents:
diff changeset
1630
anatofuz
parents:
diff changeset
1631 int test(struct s *p) {
anatofuz
parents:
diff changeset
1632 return sizeof(p);
anatofuz
parents:
diff changeset
1633 // warn: sizeof(ptr) can produce an unexpected result
anatofuz
parents:
diff changeset
1634 }
anatofuz
parents:
diff changeset
1635
anatofuz
parents:
diff changeset
1636 .. _alpha-core-StackAddressAsyncEscape:
anatofuz
parents:
diff changeset
1637
anatofuz
parents:
diff changeset
1638 alpha.core.StackAddressAsyncEscape (C)
anatofuz
parents:
diff changeset
1639 """"""""""""""""""""""""""""""""""""""
anatofuz
parents:
diff changeset
1640 Check that addresses to stack memory do not escape the function that involves dispatch_after or dispatch_async.
anatofuz
parents:
diff changeset
1641 This checker is a part of ``core.StackAddressEscape``, but is temporarily disabled until some false positives are fixed.
anatofuz
parents:
diff changeset
1642
anatofuz
parents:
diff changeset
1643 .. code-block:: c
anatofuz
parents:
diff changeset
1644
anatofuz
parents:
diff changeset
1645 dispatch_block_t test_block_inside_block_async_leak() {
anatofuz
parents:
diff changeset
1646 int x = 123;
anatofuz
parents:
diff changeset
1647 void (^inner)(void) = ^void(void) {
anatofuz
parents:
diff changeset
1648 int y = x;
anatofuz
parents:
diff changeset
1649 ++y;
anatofuz
parents:
diff changeset
1650 };
anatofuz
parents:
diff changeset
1651 void (^outer)(void) = ^void(void) {
anatofuz
parents:
diff changeset
1652 int z = x;
anatofuz
parents:
diff changeset
1653 ++z;
anatofuz
parents:
diff changeset
1654 inner();
anatofuz
parents:
diff changeset
1655 };
anatofuz
parents:
diff changeset
1656 return outer; // warn: address of stack-allocated block is captured by a
anatofuz
parents:
diff changeset
1657 // returned block
anatofuz
parents:
diff changeset
1658 }
anatofuz
parents:
diff changeset
1659
anatofuz
parents:
diff changeset
1660 .. _alpha-core-TestAfterDivZero:
anatofuz
parents:
diff changeset
1661
anatofuz
parents:
diff changeset
1662 alpha.core.TestAfterDivZero (C)
anatofuz
parents:
diff changeset
1663 """""""""""""""""""""""""""""""
anatofuz
parents:
diff changeset
1664 Check for division by variable that is later compared against 0.
anatofuz
parents:
diff changeset
1665 Either the comparison is useless or there is division by zero.
anatofuz
parents:
diff changeset
1666
anatofuz
parents:
diff changeset
1667 .. code-block:: c
anatofuz
parents:
diff changeset
1668
anatofuz
parents:
diff changeset
1669 void test(int x) {
anatofuz
parents:
diff changeset
1670 var = 77 / x;
anatofuz
parents:
diff changeset
1671 if (x == 0) { } // warn
anatofuz
parents:
diff changeset
1672 }
anatofuz
parents:
diff changeset
1673
anatofuz
parents:
diff changeset
1674 alpha.cplusplus
anatofuz
parents:
diff changeset
1675 ^^^^^^^^^^^^^^^
anatofuz
parents:
diff changeset
1676
anatofuz
parents:
diff changeset
1677 .. _alpha-cplusplus-DeleteWithNonVirtualDtor:
anatofuz
parents:
diff changeset
1678
anatofuz
parents:
diff changeset
1679 alpha.cplusplus.DeleteWithNonVirtualDtor (C++)
anatofuz
parents:
diff changeset
1680 """"""""""""""""""""""""""""""""""""""""""""""
anatofuz
parents:
diff changeset
1681 Reports destructions of polymorphic objects with a non-virtual destructor in their base class.
anatofuz
parents:
diff changeset
1682
anatofuz
parents:
diff changeset
1683 .. code-block:: cpp
anatofuz
parents:
diff changeset
1684
anatofuz
parents:
diff changeset
1685 NonVirtual *create() {
anatofuz
parents:
diff changeset
1686 NonVirtual *x = new NVDerived(); // note: conversion from derived to base
anatofuz
parents:
diff changeset
1687 // happened here
anatofuz
parents:
diff changeset
1688 return x;
anatofuz
parents:
diff changeset
1689 }
anatofuz
parents:
diff changeset
1690
anatofuz
parents:
diff changeset
1691 void sink(NonVirtual *x) {
anatofuz
parents:
diff changeset
1692 delete x; // warn: destruction of a polymorphic object with no virtual
anatofuz
parents:
diff changeset
1693 // destructor
anatofuz
parents:
diff changeset
1694 }
anatofuz
parents:
diff changeset
1695
anatofuz
parents:
diff changeset
1696 .. _alpha-cplusplus-EnumCastOutOfRange:
anatofuz
parents:
diff changeset
1697
anatofuz
parents:
diff changeset
1698 alpha.cplusplus.EnumCastOutOfRange (C++)
anatofuz
parents:
diff changeset
1699 """"""""""""""""""""""""""""""""""""""""
anatofuz
parents:
diff changeset
1700 Check for integer to enumeration casts that could result in undefined values.
anatofuz
parents:
diff changeset
1701
anatofuz
parents:
diff changeset
1702 .. code-block:: cpp
anatofuz
parents:
diff changeset
1703
anatofuz
parents:
diff changeset
1704 enum TestEnum {
anatofuz
parents:
diff changeset
1705 A = 0
anatofuz
parents:
diff changeset
1706 };
anatofuz
parents:
diff changeset
1707
anatofuz
parents:
diff changeset
1708 void foo() {
anatofuz
parents:
diff changeset
1709 TestEnum t = static_cast(-1);
anatofuz
parents:
diff changeset
1710 // warn: the value provided to the cast expression is not in
anatofuz
parents:
diff changeset
1711 the valid range of values for the enum
anatofuz
parents:
diff changeset
1712
anatofuz
parents:
diff changeset
1713 .. _alpha-cplusplus-InvalidatedIterator:
anatofuz
parents:
diff changeset
1714
anatofuz
parents:
diff changeset
1715 alpha.cplusplus.InvalidatedIterator (C++)
anatofuz
parents:
diff changeset
1716 """""""""""""""""""""""""""""""""""""""""
anatofuz
parents:
diff changeset
1717 Check for use of invalidated iterators.
anatofuz
parents:
diff changeset
1718
anatofuz
parents:
diff changeset
1719 .. code-block:: cpp
anatofuz
parents:
diff changeset
1720
anatofuz
parents:
diff changeset
1721 void bad_copy_assign_operator_list1(std::list &L1,
anatofuz
parents:
diff changeset
1722 const std::list &L2) {
anatofuz
parents:
diff changeset
1723 auto i0 = L1.cbegin();
anatofuz
parents:
diff changeset
1724 L1 = L2;
anatofuz
parents:
diff changeset
1725 *i0; // warn: invalidated iterator accessed
anatofuz
parents:
diff changeset
1726 }
anatofuz
parents:
diff changeset
1727
anatofuz
parents:
diff changeset
1728
anatofuz
parents:
diff changeset
1729 .. _alpha-cplusplus-IteratorRange:
anatofuz
parents:
diff changeset
1730
anatofuz
parents:
diff changeset
1731 alpha.cplusplus.IteratorRange (C++)
anatofuz
parents:
diff changeset
1732 """""""""""""""""""""""""""""""""""
anatofuz
parents:
diff changeset
1733 Check for iterators used outside their valid ranges.
anatofuz
parents:
diff changeset
1734
anatofuz
parents:
diff changeset
1735 .. code-block:: cpp
anatofuz
parents:
diff changeset
1736
anatofuz
parents:
diff changeset
1737 void simple_bad_end(const std::vector &v) {
anatofuz
parents:
diff changeset
1738 auto i = v.end();
anatofuz
parents:
diff changeset
1739 *i; // warn: iterator accessed outside of its range
anatofuz
parents:
diff changeset
1740 }
anatofuz
parents:
diff changeset
1741
anatofuz
parents:
diff changeset
1742 .. _alpha-cplusplus-MismatchedIterator:
anatofuz
parents:
diff changeset
1743
anatofuz
parents:
diff changeset
1744 alpha.cplusplus.MismatchedIterator (C++)
anatofuz
parents:
diff changeset
1745 """"""""""""""""""""""""""""""""""""""""
anatofuz
parents:
diff changeset
1746 Check for use of iterators of different containers where iterators of the same container are expected.
anatofuz
parents:
diff changeset
1747
anatofuz
parents:
diff changeset
1748 .. code-block:: cpp
anatofuz
parents:
diff changeset
1749
anatofuz
parents:
diff changeset
1750 void bad_insert3(std::vector &v1, std::vector &v2) {
anatofuz
parents:
diff changeset
1751 v2.insert(v1.cbegin(), v2.cbegin(), v2.cend()); // warn: container accessed
anatofuz
parents:
diff changeset
1752 // using foreign
anatofuz
parents:
diff changeset
1753 // iterator argument
anatofuz
parents:
diff changeset
1754 v1.insert(v1.cbegin(), v1.cbegin(), v2.cend()); // warn: iterators of
anatofuz
parents:
diff changeset
1755 // different containers
anatofuz
parents:
diff changeset
1756 // used where the same
anatofuz
parents:
diff changeset
1757 // container is
anatofuz
parents:
diff changeset
1758 // expected
anatofuz
parents:
diff changeset
1759 v1.insert(v1.cbegin(), v2.cbegin(), v1.cend()); // warn: iterators of
anatofuz
parents:
diff changeset
1760 // different containers
anatofuz
parents:
diff changeset
1761 // used where the same
anatofuz
parents:
diff changeset
1762 // container is
anatofuz
parents:
diff changeset
1763 // expected
anatofuz
parents:
diff changeset
1764 }
anatofuz
parents:
diff changeset
1765
anatofuz
parents:
diff changeset
1766 .. _alpha-cplusplus-MisusedMovedObject:
anatofuz
parents:
diff changeset
1767
anatofuz
parents:
diff changeset
1768 alpha.cplusplus.MisusedMovedObject (C++)
anatofuz
parents:
diff changeset
1769 """"""""""""""""""""""""""""""""""""""""
anatofuz
parents:
diff changeset
1770 Method calls on a moved-from object and copying a moved-from object will be reported.
anatofuz
parents:
diff changeset
1771
anatofuz
parents:
diff changeset
1772
anatofuz
parents:
diff changeset
1773 .. code-block:: cpp
anatofuz
parents:
diff changeset
1774
anatofuz
parents:
diff changeset
1775 struct A {
anatofuz
parents:
diff changeset
1776 void foo() {}
anatofuz
parents:
diff changeset
1777 };
anatofuz
parents:
diff changeset
1778
anatofuz
parents:
diff changeset
1779 void f() {
anatofuz
parents:
diff changeset
1780 A a;
anatofuz
parents:
diff changeset
1781 A b = std::move(a); // note: 'a' became 'moved-from' here
anatofuz
parents:
diff changeset
1782 a.foo(); // warn: method call on a 'moved-from' object 'a'
anatofuz
parents:
diff changeset
1783 }
anatofuz
parents:
diff changeset
1784
anatofuz
parents:
diff changeset
1785 alpha.deadcode
anatofuz
parents:
diff changeset
1786 ^^^^^^^^^^^^^^
anatofuz
parents:
diff changeset
1787 .. _alpha-deadcode-UnreachableCode:
anatofuz
parents:
diff changeset
1788
anatofuz
parents:
diff changeset
1789 alpha.deadcode.UnreachableCode (C, C++)
anatofuz
parents:
diff changeset
1790 """""""""""""""""""""""""""""""""""""""
anatofuz
parents:
diff changeset
1791 Check unreachable code.
anatofuz
parents:
diff changeset
1792
anatofuz
parents:
diff changeset
1793 .. code-block:: cpp
anatofuz
parents:
diff changeset
1794
anatofuz
parents:
diff changeset
1795 // C
anatofuz
parents:
diff changeset
1796 int test() {
anatofuz
parents:
diff changeset
1797 int x = 1;
anatofuz
parents:
diff changeset
1798 while(x);
anatofuz
parents:
diff changeset
1799 return x; // warn
anatofuz
parents:
diff changeset
1800 }
anatofuz
parents:
diff changeset
1801
anatofuz
parents:
diff changeset
1802 // C++
anatofuz
parents:
diff changeset
1803 void test() {
anatofuz
parents:
diff changeset
1804 int a = 2;
anatofuz
parents:
diff changeset
1805
anatofuz
parents:
diff changeset
1806 while (a > 1)
anatofuz
parents:
diff changeset
1807 a--;
anatofuz
parents:
diff changeset
1808
anatofuz
parents:
diff changeset
1809 if (a > 1)
anatofuz
parents:
diff changeset
1810 a++; // warn
anatofuz
parents:
diff changeset
1811 }
anatofuz
parents:
diff changeset
1812
anatofuz
parents:
diff changeset
1813 // Objective-C
anatofuz
parents:
diff changeset
1814 void test(id x) {
anatofuz
parents:
diff changeset
1815 return;
anatofuz
parents:
diff changeset
1816 [x retain]; // warn
anatofuz
parents:
diff changeset
1817 }
anatofuz
parents:
diff changeset
1818
anatofuz
parents:
diff changeset
1819 alpha.llvm
anatofuz
parents:
diff changeset
1820 ^^^^^^^^^^
anatofuz
parents:
diff changeset
1821
anatofuz
parents:
diff changeset
1822 .. _alpha-llvm-Conventions:
anatofuz
parents:
diff changeset
1823
anatofuz
parents:
diff changeset
1824 alpha.llvm.Conventions
anatofuz
parents:
diff changeset
1825 """"""""""""""""""""""
anatofuz
parents:
diff changeset
1826
anatofuz
parents:
diff changeset
1827 Check code for LLVM codebase conventions:
anatofuz
parents:
diff changeset
1828
anatofuz
parents:
diff changeset
1829 * A StringRef should not be bound to a temporary std::string whose lifetime is shorter than the StringRef's.
anatofuz
parents:
diff changeset
1830 * Clang AST nodes should not have fields that can allocate memory.
anatofuz
parents:
diff changeset
1831
anatofuz
parents:
diff changeset
1832
anatofuz
parents:
diff changeset
1833 alpha.osx
anatofuz
parents:
diff changeset
1834 ^^^^^^^^^
anatofuz
parents:
diff changeset
1835
anatofuz
parents:
diff changeset
1836 .. _alpha-osx-cocoa-DirectIvarAssignment:
anatofuz
parents:
diff changeset
1837
anatofuz
parents:
diff changeset
1838 alpha.osx.cocoa.DirectIvarAssignment (ObjC)
anatofuz
parents:
diff changeset
1839 """""""""""""""""""""""""""""""""""""""""""
anatofuz
parents:
diff changeset
1840 Check for direct assignments to instance variables.
anatofuz
parents:
diff changeset
1841
anatofuz
parents:
diff changeset
1842
anatofuz
parents:
diff changeset
1843 .. code-block:: objc
anatofuz
parents:
diff changeset
1844
anatofuz
parents:
diff changeset
1845 @interface MyClass : NSObject {}
anatofuz
parents:
diff changeset
1846 @property (readonly) id A;
anatofuz
parents:
diff changeset
1847 - (void) foo;
anatofuz
parents:
diff changeset
1848 @end
anatofuz
parents:
diff changeset
1849
anatofuz
parents:
diff changeset
1850 @implementation MyClass
anatofuz
parents:
diff changeset
1851 - (void) foo {
anatofuz
parents:
diff changeset
1852 _A = 0; // warn
anatofuz
parents:
diff changeset
1853 }
anatofuz
parents:
diff changeset
1854 @end
anatofuz
parents:
diff changeset
1855
anatofuz
parents:
diff changeset
1856 .. _alpha-osx-cocoa-DirectIvarAssignmentForAnnotatedFunctions:
anatofuz
parents:
diff changeset
1857
anatofuz
parents:
diff changeset
1858 alpha.osx.cocoa.DirectIvarAssignmentForAnnotatedFunctions (ObjC)
anatofuz
parents:
diff changeset
1859 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
anatofuz
parents:
diff changeset
1860 Check for direct assignments to instance variables in
anatofuz
parents:
diff changeset
1861 the methods annotated with ``objc_no_direct_instance_variable_assignment``.
anatofuz
parents:
diff changeset
1862
anatofuz
parents:
diff changeset
1863 .. code-block:: objc
anatofuz
parents:
diff changeset
1864
anatofuz
parents:
diff changeset
1865 @interface MyClass : NSObject {}
anatofuz
parents:
diff changeset
1866 @property (readonly) id A;
anatofuz
parents:
diff changeset
1867 - (void) fAnnotated __attribute__((
anatofuz
parents:
diff changeset
1868 annotate("objc_no_direct_instance_variable_assignment")));
anatofuz
parents:
diff changeset
1869 - (void) fNotAnnotated;
anatofuz
parents:
diff changeset
1870 @end
anatofuz
parents:
diff changeset
1871
anatofuz
parents:
diff changeset
1872 @implementation MyClass
anatofuz
parents:
diff changeset
1873 - (void) fAnnotated {
anatofuz
parents:
diff changeset
1874 _A = 0; // warn
anatofuz
parents:
diff changeset
1875 }
anatofuz
parents:
diff changeset
1876 - (void) fNotAnnotated {
anatofuz
parents:
diff changeset
1877 _A = 0; // no warn
anatofuz
parents:
diff changeset
1878 }
anatofuz
parents:
diff changeset
1879 @end
anatofuz
parents:
diff changeset
1880
anatofuz
parents:
diff changeset
1881
anatofuz
parents:
diff changeset
1882 .. _alpha-osx-cocoa-InstanceVariableInvalidation:
anatofuz
parents:
diff changeset
1883
anatofuz
parents:
diff changeset
1884 alpha.osx.cocoa.InstanceVariableInvalidation (ObjC)
anatofuz
parents:
diff changeset
1885 """""""""""""""""""""""""""""""""""""""""""""""""""
anatofuz
parents:
diff changeset
1886 Check that the invalidatable instance variables are
anatofuz
parents:
diff changeset
1887 invalidated in the methods annotated with objc_instance_variable_invalidator.
anatofuz
parents:
diff changeset
1888
anatofuz
parents:
diff changeset
1889 .. code-block:: objc
anatofuz
parents:
diff changeset
1890
anatofuz
parents:
diff changeset
1891 @protocol Invalidation <NSObject>
anatofuz
parents:
diff changeset
1892 - (void) invalidate
anatofuz
parents:
diff changeset
1893 __attribute__((annotate("objc_instance_variable_invalidator")));
anatofuz
parents:
diff changeset
1894 @end
anatofuz
parents:
diff changeset
1895
anatofuz
parents:
diff changeset
1896 @interface InvalidationImpObj : NSObject <Invalidation>
anatofuz
parents:
diff changeset
1897 @end
anatofuz
parents:
diff changeset
1898
anatofuz
parents:
diff changeset
1899 @interface SubclassInvalidationImpObj : InvalidationImpObj {
anatofuz
parents:
diff changeset
1900 InvalidationImpObj *var;
anatofuz
parents:
diff changeset
1901 }
anatofuz
parents:
diff changeset
1902 - (void)invalidate;
anatofuz
parents:
diff changeset
1903 @end
anatofuz
parents:
diff changeset
1904
anatofuz
parents:
diff changeset
1905 @implementation SubclassInvalidationImpObj
anatofuz
parents:
diff changeset
1906 - (void) invalidate {}
anatofuz
parents:
diff changeset
1907 @end
anatofuz
parents:
diff changeset
1908 // warn: var needs to be invalidated or set to nil
anatofuz
parents:
diff changeset
1909
anatofuz
parents:
diff changeset
1910 .. _alpha-osx-cocoa-MissingInvalidationMethod:
anatofuz
parents:
diff changeset
1911
anatofuz
parents:
diff changeset
1912 alpha.osx.cocoa.MissingInvalidationMethod (ObjC)
anatofuz
parents:
diff changeset
1913 """"""""""""""""""""""""""""""""""""""""""""""""
anatofuz
parents:
diff changeset
1914 Check that the invalidation methods are present in classes that contain invalidatable instance variables.
anatofuz
parents:
diff changeset
1915
anatofuz
parents:
diff changeset
1916 .. code-block:: objc
anatofuz
parents:
diff changeset
1917
anatofuz
parents:
diff changeset
1918 @protocol Invalidation <NSObject>
anatofuz
parents:
diff changeset
1919 - (void)invalidate
anatofuz
parents:
diff changeset
1920 __attribute__((annotate("objc_instance_variable_invalidator")));
anatofuz
parents:
diff changeset
1921 @end
anatofuz
parents:
diff changeset
1922
anatofuz
parents:
diff changeset
1923 @interface NeedInvalidation : NSObject <Invalidation>
anatofuz
parents:
diff changeset
1924 @end
anatofuz
parents:
diff changeset
1925
anatofuz
parents:
diff changeset
1926 @interface MissingInvalidationMethodDecl : NSObject {
anatofuz
parents:
diff changeset
1927 NeedInvalidation *Var; // warn
anatofuz
parents:
diff changeset
1928 }
anatofuz
parents:
diff changeset
1929 @end
anatofuz
parents:
diff changeset
1930
anatofuz
parents:
diff changeset
1931 @implementation MissingInvalidationMethodDecl
anatofuz
parents:
diff changeset
1932 @end
anatofuz
parents:
diff changeset
1933
anatofuz
parents:
diff changeset
1934 .. _alpha-osx-cocoa-localizability-PluralMisuseChecker:
anatofuz
parents:
diff changeset
1935
anatofuz
parents:
diff changeset
1936 alpha.osx.cocoa.localizability.PluralMisuseChecker (ObjC)
anatofuz
parents:
diff changeset
1937 """""""""""""""""""""""""""""""""""""""""""""""""""""""""
anatofuz
parents:
diff changeset
1938 Warns against using one vs. many plural pattern in code when generating localized strings.
anatofuz
parents:
diff changeset
1939
anatofuz
parents:
diff changeset
1940 .. code-block:: objc
anatofuz
parents:
diff changeset
1941
anatofuz
parents:
diff changeset
1942 NSString *reminderText =
anatofuz
parents:
diff changeset
1943 NSLocalizedString(@"None", @"Indicates no reminders");
anatofuz
parents:
diff changeset
1944 if (reminderCount == 1) {
anatofuz
parents:
diff changeset
1945 // Warning: Plural cases are not supported across all languages.
anatofuz
parents:
diff changeset
1946 // Use a .stringsdict file instead
anatofuz
parents:
diff changeset
1947 reminderText =
anatofuz
parents:
diff changeset
1948 NSLocalizedString(@"1 Reminder", @"Indicates single reminder");
anatofuz
parents:
diff changeset
1949 } else if (reminderCount >= 2) {
anatofuz
parents:
diff changeset
1950 // Warning: Plural cases are not supported across all languages.
anatofuz
parents:
diff changeset
1951 // Use a .stringsdict file instead
anatofuz
parents:
diff changeset
1952 reminderText =
anatofuz
parents:
diff changeset
1953 [NSString stringWithFormat:
anatofuz
parents:
diff changeset
1954 NSLocalizedString(@"%@ Reminders", @"Indicates multiple reminders"),
anatofuz
parents:
diff changeset
1955 reminderCount];
anatofuz
parents:
diff changeset
1956 }
anatofuz
parents:
diff changeset
1957
anatofuz
parents:
diff changeset
1958 alpha.security
anatofuz
parents:
diff changeset
1959 ^^^^^^^^^^^^^^
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
1960
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
1961
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
1962 alpha.security.cert
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
1963 ^^^^^^^^^^^^^^^^^^^
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
1964
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
1965 SEI CERT checkers which tries to find errors based on their `C coding rules <https://wiki.sei.cmu.edu/confluence/display/c/2+Rules>`_.
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
1966
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
1967 .. _alpha-security-cert-pos-checkers:
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
1968
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
1969 alpha.security.cert.pos
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
1970 ^^^^^^^^^^^^^^^^^^^^^^^
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
1971
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
1972 SEI CERT checkers of `POSIX C coding rules <https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=87152405>`_.
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
1973
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
1974 .. _alpha-security-cert-pos-34c:
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
1975
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
1976 alpha.security.cert.pos.34c
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
1977 """""""""""""""""""""""""""
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
1978 Finds calls to the ``putenv`` function which pass a pointer to an automatic variable as the argument.
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
1979
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
1980 .. code-block:: c
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
1981
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
1982 int func(const char *var) {
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
1983 char env[1024];
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
1984 int retval = snprintf(env, sizeof(env),"TEST=%s", var);
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
1985 if (retval < 0 || (size_t)retval >= sizeof(env)) {
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
1986 /* Handle error */
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
1987 }
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
1988
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
1989 return putenv(env); // putenv function should not be called with auto variables
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
1990 }
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
1991
150
anatofuz
parents:
diff changeset
1992 .. _alpha-security-ArrayBound:
anatofuz
parents:
diff changeset
1993
anatofuz
parents:
diff changeset
1994 alpha.security.ArrayBound (C)
anatofuz
parents:
diff changeset
1995 """""""""""""""""""""""""""""
anatofuz
parents:
diff changeset
1996 Warn about buffer overflows (older checker).
anatofuz
parents:
diff changeset
1997
anatofuz
parents:
diff changeset
1998 .. code-block:: c
anatofuz
parents:
diff changeset
1999
anatofuz
parents:
diff changeset
2000 void test() {
anatofuz
parents:
diff changeset
2001 char *s = "";
anatofuz
parents:
diff changeset
2002 char c = s[1]; // warn
anatofuz
parents:
diff changeset
2003 }
anatofuz
parents:
diff changeset
2004
anatofuz
parents:
diff changeset
2005 struct seven_words {
anatofuz
parents:
diff changeset
2006 int c[7];
anatofuz
parents:
diff changeset
2007 };
anatofuz
parents:
diff changeset
2008
anatofuz
parents:
diff changeset
2009 void test() {
anatofuz
parents:
diff changeset
2010 struct seven_words a, *p;
anatofuz
parents:
diff changeset
2011 p = &a;
anatofuz
parents:
diff changeset
2012 p[0] = a;
anatofuz
parents:
diff changeset
2013 p[1] = a;
anatofuz
parents:
diff changeset
2014 p[2] = a; // warn
anatofuz
parents:
diff changeset
2015 }
anatofuz
parents:
diff changeset
2016
anatofuz
parents:
diff changeset
2017 // note: requires unix.Malloc or
anatofuz
parents:
diff changeset
2018 // alpha.unix.MallocWithAnnotations checks enabled.
anatofuz
parents:
diff changeset
2019 void test() {
anatofuz
parents:
diff changeset
2020 int *p = malloc(12);
anatofuz
parents:
diff changeset
2021 p[3] = 4; // warn
anatofuz
parents:
diff changeset
2022 }
anatofuz
parents:
diff changeset
2023
anatofuz
parents:
diff changeset
2024 void test() {
anatofuz
parents:
diff changeset
2025 char a[2];
anatofuz
parents:
diff changeset
2026 int *b = (int*)a;
anatofuz
parents:
diff changeset
2027 b[1] = 3; // warn
anatofuz
parents:
diff changeset
2028 }
anatofuz
parents:
diff changeset
2029
anatofuz
parents:
diff changeset
2030 .. _alpha-security-ArrayBoundV2:
anatofuz
parents:
diff changeset
2031
anatofuz
parents:
diff changeset
2032 alpha.security.ArrayBoundV2 (C)
anatofuz
parents:
diff changeset
2033 """""""""""""""""""""""""""""""
anatofuz
parents:
diff changeset
2034 Warn about buffer overflows (newer checker).
anatofuz
parents:
diff changeset
2035
anatofuz
parents:
diff changeset
2036 .. code-block:: c
anatofuz
parents:
diff changeset
2037
anatofuz
parents:
diff changeset
2038 void test() {
anatofuz
parents:
diff changeset
2039 char *s = "";
anatofuz
parents:
diff changeset
2040 char c = s[1]; // warn
anatofuz
parents:
diff changeset
2041 }
anatofuz
parents:
diff changeset
2042
anatofuz
parents:
diff changeset
2043 void test() {
anatofuz
parents:
diff changeset
2044 int buf[100];
anatofuz
parents:
diff changeset
2045 int *p = buf;
anatofuz
parents:
diff changeset
2046 p = p + 99;
anatofuz
parents:
diff changeset
2047 p[1] = 1; // warn
anatofuz
parents:
diff changeset
2048 }
anatofuz
parents:
diff changeset
2049
anatofuz
parents:
diff changeset
2050 // note: compiler has internal check for this.
anatofuz
parents:
diff changeset
2051 // Use -Wno-array-bounds to suppress compiler warning.
anatofuz
parents:
diff changeset
2052 void test() {
anatofuz
parents:
diff changeset
2053 int buf[100][100];
anatofuz
parents:
diff changeset
2054 buf[0][-1] = 1; // warn
anatofuz
parents:
diff changeset
2055 }
anatofuz
parents:
diff changeset
2056
anatofuz
parents:
diff changeset
2057 // note: requires alpha.security.taint check turned on.
anatofuz
parents:
diff changeset
2058 void test() {
anatofuz
parents:
diff changeset
2059 char s[] = "abc";
anatofuz
parents:
diff changeset
2060 int x = getchar();
anatofuz
parents:
diff changeset
2061 char c = s[x]; // warn: index is tainted
anatofuz
parents:
diff changeset
2062 }
anatofuz
parents:
diff changeset
2063
anatofuz
parents:
diff changeset
2064 .. _alpha-security-MallocOverflow:
anatofuz
parents:
diff changeset
2065
anatofuz
parents:
diff changeset
2066 alpha.security.MallocOverflow (C)
anatofuz
parents:
diff changeset
2067 """""""""""""""""""""""""""""""""
anatofuz
parents:
diff changeset
2068 Check for overflows in the arguments to malloc().
anatofuz
parents:
diff changeset
2069
anatofuz
parents:
diff changeset
2070 .. code-block:: c
anatofuz
parents:
diff changeset
2071
anatofuz
parents:
diff changeset
2072 void test(int n) {
anatofuz
parents:
diff changeset
2073 void *p = malloc(n * sizeof(int)); // warn
anatofuz
parents:
diff changeset
2074 }
anatofuz
parents:
diff changeset
2075
anatofuz
parents:
diff changeset
2076 void test2(int n) {
anatofuz
parents:
diff changeset
2077 if (n > 100) // gives an upper-bound
anatofuz
parents:
diff changeset
2078 return;
anatofuz
parents:
diff changeset
2079 void *p = malloc(n * sizeof(int)); // no warning
anatofuz
parents:
diff changeset
2080 }
anatofuz
parents:
diff changeset
2081
anatofuz
parents:
diff changeset
2082 .. _alpha-security-MmapWriteExec:
anatofuz
parents:
diff changeset
2083
anatofuz
parents:
diff changeset
2084 alpha.security.MmapWriteExec (C)
anatofuz
parents:
diff changeset
2085 """"""""""""""""""""""""""""""""
anatofuz
parents:
diff changeset
2086 Warn on mmap() calls that are both writable and executable.
anatofuz
parents:
diff changeset
2087
anatofuz
parents:
diff changeset
2088 .. code-block:: c
anatofuz
parents:
diff changeset
2089
anatofuz
parents:
diff changeset
2090 void test(int n) {
anatofuz
parents:
diff changeset
2091 void *c = mmap(NULL, 32, PROT_READ | PROT_WRITE | PROT_EXEC,
anatofuz
parents:
diff changeset
2092 MAP_PRIVATE | MAP_ANON, -1, 0);
anatofuz
parents:
diff changeset
2093 // warn: Both PROT_WRITE and PROT_EXEC flags are set. This can lead to
anatofuz
parents:
diff changeset
2094 // exploitable memory regions, which could be overwritten with malicious
anatofuz
parents:
diff changeset
2095 // code
anatofuz
parents:
diff changeset
2096 }
anatofuz
parents:
diff changeset
2097
anatofuz
parents:
diff changeset
2098 .. _alpha-security-ReturnPtrRange:
anatofuz
parents:
diff changeset
2099
anatofuz
parents:
diff changeset
2100 alpha.security.ReturnPtrRange (C)
anatofuz
parents:
diff changeset
2101 """""""""""""""""""""""""""""""""
anatofuz
parents:
diff changeset
2102 Check for an out-of-bound pointer being returned to callers.
anatofuz
parents:
diff changeset
2103
anatofuz
parents:
diff changeset
2104 .. code-block:: c
anatofuz
parents:
diff changeset
2105
anatofuz
parents:
diff changeset
2106 static int A[10];
anatofuz
parents:
diff changeset
2107
anatofuz
parents:
diff changeset
2108 int *test() {
anatofuz
parents:
diff changeset
2109 int *p = A + 10;
anatofuz
parents:
diff changeset
2110 return p; // warn
anatofuz
parents:
diff changeset
2111 }
anatofuz
parents:
diff changeset
2112
anatofuz
parents:
diff changeset
2113 int test(void) {
anatofuz
parents:
diff changeset
2114 int x;
anatofuz
parents:
diff changeset
2115 return x; // warn: undefined or garbage returned
anatofuz
parents:
diff changeset
2116 }
anatofuz
parents:
diff changeset
2117
anatofuz
parents:
diff changeset
2118 .. _alpha-security-taint-TaintPropagation:
anatofuz
parents:
diff changeset
2119
anatofuz
parents:
diff changeset
2120 alpha.security.taint.TaintPropagation (C, C++)
anatofuz
parents:
diff changeset
2121 """"""""""""""""""""""""""""""""""""""""""""""
anatofuz
parents:
diff changeset
2122 Generate taint information used by other checkers.
anatofuz
parents:
diff changeset
2123 A data is tainted when it comes from an unreliable source.
anatofuz
parents:
diff changeset
2124
anatofuz
parents:
diff changeset
2125 .. code-block:: c
anatofuz
parents:
diff changeset
2126
anatofuz
parents:
diff changeset
2127 void test() {
anatofuz
parents:
diff changeset
2128 char x = getchar(); // 'x' marked as tainted
anatofuz
parents:
diff changeset
2129 system(&x); // warn: untrusted data is passed to a system call
anatofuz
parents:
diff changeset
2130 }
anatofuz
parents:
diff changeset
2131
anatofuz
parents:
diff changeset
2132 // note: compiler internally checks if the second param to
anatofuz
parents:
diff changeset
2133 // sprintf is a string literal or not.
anatofuz
parents:
diff changeset
2134 // Use -Wno-format-security to suppress compiler warning.
anatofuz
parents:
diff changeset
2135 void test() {
anatofuz
parents:
diff changeset
2136 char s[10], buf[10];
anatofuz
parents:
diff changeset
2137 fscanf(stdin, "%s", s); // 's' marked as tainted
anatofuz
parents:
diff changeset
2138
anatofuz
parents:
diff changeset
2139 sprintf(buf, s); // warn: untrusted data as a format string
anatofuz
parents:
diff changeset
2140 }
anatofuz
parents:
diff changeset
2141
anatofuz
parents:
diff changeset
2142 void test() {
anatofuz
parents:
diff changeset
2143 size_t ts;
anatofuz
parents:
diff changeset
2144 scanf("%zd", &ts); // 'ts' marked as tainted
anatofuz
parents:
diff changeset
2145 int *p = (int *)malloc(ts * sizeof(int));
anatofuz
parents:
diff changeset
2146 // warn: untrusted data as buffer size
anatofuz
parents:
diff changeset
2147 }
anatofuz
parents:
diff changeset
2148
anatofuz
parents:
diff changeset
2149 alpha.unix
anatofuz
parents:
diff changeset
2150 ^^^^^^^^^^^
anatofuz
parents:
diff changeset
2151
anatofuz
parents:
diff changeset
2152 .. _alpha-unix-BlockInCriticalSection:
anatofuz
parents:
diff changeset
2153
anatofuz
parents:
diff changeset
2154 alpha.unix.BlockInCriticalSection (C)
anatofuz
parents:
diff changeset
2155 """""""""""""""""""""""""""""""""""""
anatofuz
parents:
diff changeset
2156 Check for calls to blocking functions inside a critical section.
anatofuz
parents:
diff changeset
2157 Applies to: ``lock, unlock, sleep, getc, fgets, read, recv, pthread_mutex_lock,``
anatofuz
parents:
diff changeset
2158 `` pthread_mutex_unlock, mtx_lock, mtx_timedlock, mtx_trylock, mtx_unlock, lock_guard, unique_lock``
anatofuz
parents:
diff changeset
2159
anatofuz
parents:
diff changeset
2160 .. code-block:: c
anatofuz
parents:
diff changeset
2161
anatofuz
parents:
diff changeset
2162 void test() {
anatofuz
parents:
diff changeset
2163 std::mutex m;
anatofuz
parents:
diff changeset
2164 m.lock();
anatofuz
parents:
diff changeset
2165 sleep(3); // warn: a blocking function sleep is called inside a critical
anatofuz
parents:
diff changeset
2166 // section
anatofuz
parents:
diff changeset
2167 m.unlock();
anatofuz
parents:
diff changeset
2168 }
anatofuz
parents:
diff changeset
2169
anatofuz
parents:
diff changeset
2170 .. _alpha-unix-Chroot:
anatofuz
parents:
diff changeset
2171
anatofuz
parents:
diff changeset
2172 alpha.unix.Chroot (C)
anatofuz
parents:
diff changeset
2173 """""""""""""""""""""
anatofuz
parents:
diff changeset
2174 Check improper use of chroot.
anatofuz
parents:
diff changeset
2175
anatofuz
parents:
diff changeset
2176 .. code-block:: c
anatofuz
parents:
diff changeset
2177
anatofuz
parents:
diff changeset
2178 void f();
anatofuz
parents:
diff changeset
2179
anatofuz
parents:
diff changeset
2180 void test() {
anatofuz
parents:
diff changeset
2181 chroot("/usr/local");
anatofuz
parents:
diff changeset
2182 f(); // warn: no call of chdir("/") immediately after chroot
anatofuz
parents:
diff changeset
2183 }
anatofuz
parents:
diff changeset
2184
anatofuz
parents:
diff changeset
2185 .. _alpha-unix-PthreadLock:
anatofuz
parents:
diff changeset
2186
anatofuz
parents:
diff changeset
2187 alpha.unix.PthreadLock (C)
anatofuz
parents:
diff changeset
2188 """"""""""""""""""""""""""
anatofuz
parents:
diff changeset
2189 Simple lock -> unlock checker.
anatofuz
parents:
diff changeset
2190 Applies to: ``pthread_mutex_lock, pthread_rwlock_rdlock, pthread_rwlock_wrlock, lck_mtx_lock, lck_rw_lock_exclusive``
anatofuz
parents:
diff changeset
2191 ``lck_rw_lock_shared, pthread_mutex_trylock, pthread_rwlock_tryrdlock, pthread_rwlock_tryrwlock, lck_mtx_try_lock,
anatofuz
parents:
diff changeset
2192 lck_rw_try_lock_exclusive, lck_rw_try_lock_shared, pthread_mutex_unlock, pthread_rwlock_unlock, lck_mtx_unlock, lck_rw_done``.
anatofuz
parents:
diff changeset
2193
anatofuz
parents:
diff changeset
2194
anatofuz
parents:
diff changeset
2195 .. code-block:: c
anatofuz
parents:
diff changeset
2196
anatofuz
parents:
diff changeset
2197 pthread_mutex_t mtx;
anatofuz
parents:
diff changeset
2198
anatofuz
parents:
diff changeset
2199 void test() {
anatofuz
parents:
diff changeset
2200 pthread_mutex_lock(&mtx);
anatofuz
parents:
diff changeset
2201 pthread_mutex_lock(&mtx);
anatofuz
parents:
diff changeset
2202 // warn: this lock has already been acquired
anatofuz
parents:
diff changeset
2203 }
anatofuz
parents:
diff changeset
2204
anatofuz
parents:
diff changeset
2205 lck_mtx_t lck1, lck2;
anatofuz
parents:
diff changeset
2206
anatofuz
parents:
diff changeset
2207 void test() {
anatofuz
parents:
diff changeset
2208 lck_mtx_lock(&lck1);
anatofuz
parents:
diff changeset
2209 lck_mtx_lock(&lck2);
anatofuz
parents:
diff changeset
2210 lck_mtx_unlock(&lck1);
anatofuz
parents:
diff changeset
2211 // warn: this was not the most recently acquired lock
anatofuz
parents:
diff changeset
2212 }
anatofuz
parents:
diff changeset
2213
anatofuz
parents:
diff changeset
2214 lck_mtx_t lck1, lck2;
anatofuz
parents:
diff changeset
2215
anatofuz
parents:
diff changeset
2216 void test() {
anatofuz
parents:
diff changeset
2217 if (lck_mtx_try_lock(&lck1) == 0)
anatofuz
parents:
diff changeset
2218 return;
anatofuz
parents:
diff changeset
2219
anatofuz
parents:
diff changeset
2220 lck_mtx_lock(&lck2);
anatofuz
parents:
diff changeset
2221 lck_mtx_unlock(&lck1);
anatofuz
parents:
diff changeset
2222 // warn: this was not the most recently acquired lock
anatofuz
parents:
diff changeset
2223 }
anatofuz
parents:
diff changeset
2224
anatofuz
parents:
diff changeset
2225 .. _alpha-unix-SimpleStream:
anatofuz
parents:
diff changeset
2226
anatofuz
parents:
diff changeset
2227 alpha.unix.SimpleStream (C)
anatofuz
parents:
diff changeset
2228 """""""""""""""""""""""""""
anatofuz
parents:
diff changeset
2229 Check for misuses of stream APIs. Check for misuses of stream APIs: ``fopen, fclose``
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
2230 (demo checker, the subject of the demo (`Slides <https://llvm.org/devmtg/2012-11/Zaks-Rose-Checker24Hours.pdf>`_ ,
150
anatofuz
parents:
diff changeset
2231 `Video <https://youtu.be/kdxlsP5QVPw>`_) by Anna Zaks and Jordan Rose presented at the
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
2232 `2012 LLVM Developers' Meeting <https://llvm.org/devmtg/2012-11/>`_).
150
anatofuz
parents:
diff changeset
2233
anatofuz
parents:
diff changeset
2234 .. code-block:: c
anatofuz
parents:
diff changeset
2235
anatofuz
parents:
diff changeset
2236 void test() {
anatofuz
parents:
diff changeset
2237 FILE *F = fopen("myfile.txt", "w");
anatofuz
parents:
diff changeset
2238 } // warn: opened file is never closed
anatofuz
parents:
diff changeset
2239
anatofuz
parents:
diff changeset
2240 void test() {
anatofuz
parents:
diff changeset
2241 FILE *F = fopen("myfile.txt", "w");
anatofuz
parents:
diff changeset
2242
anatofuz
parents:
diff changeset
2243 if (F)
anatofuz
parents:
diff changeset
2244 fclose(F);
anatofuz
parents:
diff changeset
2245
anatofuz
parents:
diff changeset
2246 fclose(F); // warn: closing a previously closed file stream
anatofuz
parents:
diff changeset
2247 }
anatofuz
parents:
diff changeset
2248
anatofuz
parents:
diff changeset
2249 .. _alpha-unix-Stream:
anatofuz
parents:
diff changeset
2250
anatofuz
parents:
diff changeset
2251 alpha.unix.Stream (C)
anatofuz
parents:
diff changeset
2252 """""""""""""""""""""
anatofuz
parents:
diff changeset
2253 Check stream handling functions: ``fopen, tmpfile, fclose, fread, fwrite, fseek, ftell, rewind, fgetpos,``
anatofuz
parents:
diff changeset
2254 ``fsetpos, clearerr, feof, ferror, fileno``.
anatofuz
parents:
diff changeset
2255
anatofuz
parents:
diff changeset
2256 .. code-block:: c
anatofuz
parents:
diff changeset
2257
anatofuz
parents:
diff changeset
2258 void test() {
anatofuz
parents:
diff changeset
2259 FILE *p = fopen("foo", "r");
anatofuz
parents:
diff changeset
2260 } // warn: opened file is never closed
anatofuz
parents:
diff changeset
2261
anatofuz
parents:
diff changeset
2262 void test() {
anatofuz
parents:
diff changeset
2263 FILE *p = fopen("foo", "r");
anatofuz
parents:
diff changeset
2264 fseek(p, 1, SEEK_SET); // warn: stream pointer might be NULL
anatofuz
parents:
diff changeset
2265 fclose(p);
anatofuz
parents:
diff changeset
2266 }
anatofuz
parents:
diff changeset
2267
anatofuz
parents:
diff changeset
2268 void test() {
anatofuz
parents:
diff changeset
2269 FILE *p = fopen("foo", "r");
anatofuz
parents:
diff changeset
2270
anatofuz
parents:
diff changeset
2271 if (p)
anatofuz
parents:
diff changeset
2272 fseek(p, 1, 3);
anatofuz
parents:
diff changeset
2273 // warn: third arg should be SEEK_SET, SEEK_END, or SEEK_CUR
anatofuz
parents:
diff changeset
2274
anatofuz
parents:
diff changeset
2275 fclose(p);
anatofuz
parents:
diff changeset
2276 }
anatofuz
parents:
diff changeset
2277
anatofuz
parents:
diff changeset
2278 void test() {
anatofuz
parents:
diff changeset
2279 FILE *p = fopen("foo", "r");
anatofuz
parents:
diff changeset
2280 fclose(p);
anatofuz
parents:
diff changeset
2281 fclose(p); // warn: already closed
anatofuz
parents:
diff changeset
2282 }
anatofuz
parents:
diff changeset
2283
anatofuz
parents:
diff changeset
2284 void test() {
anatofuz
parents:
diff changeset
2285 FILE *p = tmpfile();
anatofuz
parents:
diff changeset
2286 ftell(p); // warn: stream pointer might be NULL
anatofuz
parents:
diff changeset
2287 fclose(p);
anatofuz
parents:
diff changeset
2288 }
anatofuz
parents:
diff changeset
2289
anatofuz
parents:
diff changeset
2290
anatofuz
parents:
diff changeset
2291 .. _alpha-unix-cstring-BufferOverlap:
anatofuz
parents:
diff changeset
2292
anatofuz
parents:
diff changeset
2293 alpha.unix.cstring.BufferOverlap (C)
anatofuz
parents:
diff changeset
2294 """"""""""""""""""""""""""""""""""""
anatofuz
parents:
diff changeset
2295 Checks for overlap in two buffer arguments. Applies to: ``memcpy, mempcpy``.
anatofuz
parents:
diff changeset
2296
anatofuz
parents:
diff changeset
2297 .. code-block:: c
anatofuz
parents:
diff changeset
2298
anatofuz
parents:
diff changeset
2299 void test() {
anatofuz
parents:
diff changeset
2300 int a[4] = {0};
anatofuz
parents:
diff changeset
2301 memcpy(a + 2, a + 1, 8); // warn
anatofuz
parents:
diff changeset
2302 }
anatofuz
parents:
diff changeset
2303
anatofuz
parents:
diff changeset
2304 .. _alpha-unix-cstring-NotNullTerminated:
anatofuz
parents:
diff changeset
2305
anatofuz
parents:
diff changeset
2306 alpha.unix.cstring.NotNullTerminated (C)
anatofuz
parents:
diff changeset
2307 """"""""""""""""""""""""""""""""""""""""
anatofuz
parents:
diff changeset
2308 Check for arguments which are not null-terminated strings; applies to: ``strlen, strnlen, strcpy, strncpy, strcat, strncat``.
anatofuz
parents:
diff changeset
2309
anatofuz
parents:
diff changeset
2310 .. code-block:: c
anatofuz
parents:
diff changeset
2311
anatofuz
parents:
diff changeset
2312 void test() {
anatofuz
parents:
diff changeset
2313 int y = strlen((char *)&test); // warn
anatofuz
parents:
diff changeset
2314 }
anatofuz
parents:
diff changeset
2315
anatofuz
parents:
diff changeset
2316 .. _alpha-unix-cstring-OutOfBounds:
anatofuz
parents:
diff changeset
2317
anatofuz
parents:
diff changeset
2318 alpha.unix.cstring.OutOfBounds (C)
anatofuz
parents:
diff changeset
2319 """"""""""""""""""""""""""""""""""
anatofuz
parents:
diff changeset
2320 Check for out-of-bounds access in string functions; applies to:`` strncopy, strncat``.
anatofuz
parents:
diff changeset
2321
anatofuz
parents:
diff changeset
2322
anatofuz
parents:
diff changeset
2323 .. code-block:: c
anatofuz
parents:
diff changeset
2324
anatofuz
parents:
diff changeset
2325 void test() {
anatofuz
parents:
diff changeset
2326 int y = strlen((char *)&test); // warn
anatofuz
parents:
diff changeset
2327 }
anatofuz
parents:
diff changeset
2328
anatofuz
parents:
diff changeset
2329 .. _alpha-nondeterminism-PointerIteration:
anatofuz
parents:
diff changeset
2330
anatofuz
parents:
diff changeset
2331 alpha.nondeterminism.PointerIteration (C++)
anatofuz
parents:
diff changeset
2332 """""""""""""""""""""""""""""""""""""""""""
anatofuz
parents:
diff changeset
2333 Check for non-determinism caused by iterating unordered containers of pointers.
anatofuz
parents:
diff changeset
2334
anatofuz
parents:
diff changeset
2335 .. code-block:: c
anatofuz
parents:
diff changeset
2336
anatofuz
parents:
diff changeset
2337 void test() {
anatofuz
parents:
diff changeset
2338 int a = 1, b = 2;
anatofuz
parents:
diff changeset
2339 std::unordered_set<int *> UnorderedPtrSet = {&a, &b};
anatofuz
parents:
diff changeset
2340
anatofuz
parents:
diff changeset
2341 for (auto i : UnorderedPtrSet) // warn
anatofuz
parents:
diff changeset
2342 f(i);
anatofuz
parents:
diff changeset
2343 }
anatofuz
parents:
diff changeset
2344
anatofuz
parents:
diff changeset
2345 .. _alpha-nondeterminism-PointerSorting:
anatofuz
parents:
diff changeset
2346
anatofuz
parents:
diff changeset
2347 alpha.nondeterminism.PointerSorting (C++)
anatofuz
parents:
diff changeset
2348 """""""""""""""""""""""""""""""""""""""""
anatofuz
parents:
diff changeset
2349 Check for non-determinism caused by sorting of pointers.
anatofuz
parents:
diff changeset
2350
anatofuz
parents:
diff changeset
2351 .. code-block:: c
anatofuz
parents:
diff changeset
2352
anatofuz
parents:
diff changeset
2353 void test() {
anatofuz
parents:
diff changeset
2354 int a = 1, b = 2;
anatofuz
parents:
diff changeset
2355 std::vector<int *> V = {&a, &b};
anatofuz
parents:
diff changeset
2356 std::sort(V.begin(), V.end()); // warn
anatofuz
parents:
diff changeset
2357 }
anatofuz
parents:
diff changeset
2358
anatofuz
parents:
diff changeset
2359
anatofuz
parents:
diff changeset
2360 Debug Checkers
anatofuz
parents:
diff changeset
2361 ---------------
anatofuz
parents:
diff changeset
2362
anatofuz
parents:
diff changeset
2363 .. _debug-checkers:
anatofuz
parents:
diff changeset
2364
anatofuz
parents:
diff changeset
2365
anatofuz
parents:
diff changeset
2366 debug
anatofuz
parents:
diff changeset
2367 ^^^^^
anatofuz
parents:
diff changeset
2368
anatofuz
parents:
diff changeset
2369 Checkers used for debugging the analyzer.
anatofuz
parents:
diff changeset
2370 :doc:`developer-docs/DebugChecks` page contains a detailed description.
anatofuz
parents:
diff changeset
2371
anatofuz
parents:
diff changeset
2372 .. _debug-AnalysisOrder:
anatofuz
parents:
diff changeset
2373
anatofuz
parents:
diff changeset
2374 debug.AnalysisOrder
anatofuz
parents:
diff changeset
2375 """""""""""""""""""
anatofuz
parents:
diff changeset
2376 Print callbacks that are called during analysis in order.
anatofuz
parents:
diff changeset
2377
anatofuz
parents:
diff changeset
2378 .. _debug-ConfigDumper:
anatofuz
parents:
diff changeset
2379
anatofuz
parents:
diff changeset
2380 debug.ConfigDumper
anatofuz
parents:
diff changeset
2381 """"""""""""""""""
anatofuz
parents:
diff changeset
2382 Dump config table.
anatofuz
parents:
diff changeset
2383
anatofuz
parents:
diff changeset
2384 .. _debug-DumpCFG Display:
anatofuz
parents:
diff changeset
2385
anatofuz
parents:
diff changeset
2386 debug.DumpCFG Display
anatofuz
parents:
diff changeset
2387 """""""""""""""""""""
anatofuz
parents:
diff changeset
2388 Control-Flow Graphs.
anatofuz
parents:
diff changeset
2389
anatofuz
parents:
diff changeset
2390 .. _debug-DumpCallGraph:
anatofuz
parents:
diff changeset
2391
anatofuz
parents:
diff changeset
2392 debug.DumpCallGraph
anatofuz
parents:
diff changeset
2393 """""""""""""""""""
anatofuz
parents:
diff changeset
2394 Display Call Graph.
anatofuz
parents:
diff changeset
2395
anatofuz
parents:
diff changeset
2396 .. _debug-DumpCalls:
anatofuz
parents:
diff changeset
2397
anatofuz
parents:
diff changeset
2398 debug.DumpCalls
anatofuz
parents:
diff changeset
2399 """""""""""""""
anatofuz
parents:
diff changeset
2400 Print calls as they are traversed by the engine.
anatofuz
parents:
diff changeset
2401
anatofuz
parents:
diff changeset
2402 .. _debug-DumpDominators:
anatofuz
parents:
diff changeset
2403
anatofuz
parents:
diff changeset
2404 debug.DumpDominators
anatofuz
parents:
diff changeset
2405 """"""""""""""""""""
anatofuz
parents:
diff changeset
2406 Print the dominance tree for a given CFG.
anatofuz
parents:
diff changeset
2407
anatofuz
parents:
diff changeset
2408 .. _debug-DumpLiveVars:
anatofuz
parents:
diff changeset
2409
anatofuz
parents:
diff changeset
2410 debug.DumpLiveVars
anatofuz
parents:
diff changeset
2411 """"""""""""""""""
anatofuz
parents:
diff changeset
2412 Print results of live variable analysis.
anatofuz
parents:
diff changeset
2413
anatofuz
parents:
diff changeset
2414 .. _debug-DumpTraversal:
anatofuz
parents:
diff changeset
2415
anatofuz
parents:
diff changeset
2416 debug.DumpTraversal
anatofuz
parents:
diff changeset
2417 """""""""""""""""""
anatofuz
parents:
diff changeset
2418 Print branch conditions as they are traversed by the engine.
anatofuz
parents:
diff changeset
2419
anatofuz
parents:
diff changeset
2420 .. _debug-ExprInspection:
anatofuz
parents:
diff changeset
2421
anatofuz
parents:
diff changeset
2422 debug.ExprInspection
anatofuz
parents:
diff changeset
2423 """"""""""""""""""""
anatofuz
parents:
diff changeset
2424 Check the analyzer's understanding of expressions.
anatofuz
parents:
diff changeset
2425
anatofuz
parents:
diff changeset
2426 .. _debug-Stats:
anatofuz
parents:
diff changeset
2427
anatofuz
parents:
diff changeset
2428 debug.Stats
anatofuz
parents:
diff changeset
2429 """""""""""
anatofuz
parents:
diff changeset
2430 Emit warnings with analyzer statistics.
anatofuz
parents:
diff changeset
2431
anatofuz
parents:
diff changeset
2432 .. _debug-TaintTest:
anatofuz
parents:
diff changeset
2433
anatofuz
parents:
diff changeset
2434 debug.TaintTest
anatofuz
parents:
diff changeset
2435 """""""""""""""
anatofuz
parents:
diff changeset
2436 Mark tainted symbols as such.
anatofuz
parents:
diff changeset
2437
anatofuz
parents:
diff changeset
2438 .. _debug-ViewCFG:
anatofuz
parents:
diff changeset
2439
anatofuz
parents:
diff changeset
2440 debug.ViewCFG
anatofuz
parents:
diff changeset
2441 """""""""""""
anatofuz
parents:
diff changeset
2442 View Control-Flow Graphs using GraphViz.
anatofuz
parents:
diff changeset
2443
anatofuz
parents:
diff changeset
2444 .. _debug-ViewCallGraph:
anatofuz
parents:
diff changeset
2445
anatofuz
parents:
diff changeset
2446 debug.ViewCallGraph
anatofuz
parents:
diff changeset
2447 """""""""""""""""""
anatofuz
parents:
diff changeset
2448 View Call Graph using GraphViz.
anatofuz
parents:
diff changeset
2449
anatofuz
parents:
diff changeset
2450 .. _debug-ViewExplodedGraph:
anatofuz
parents:
diff changeset
2451
anatofuz
parents:
diff changeset
2452 debug.ViewExplodedGraph
anatofuz
parents:
diff changeset
2453 """""""""""""""""""""""
anatofuz
parents:
diff changeset
2454 View Exploded Graphs using GraphViz.
anatofuz
parents:
diff changeset
2455