xref: /minix3/external/bsd/llvm/dist/clang/www/analyzer/alpha_checks.html (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
2*0a6a1f1dSLionel Sambuc          "http://www.w3.org/TR/html4/strict.dtd">
3*0a6a1f1dSLionel Sambuc<html>
4*0a6a1f1dSLionel Sambuc<head>
5*0a6a1f1dSLionel Sambuc  <title>Alpha Checks</title>
6*0a6a1f1dSLionel Sambuc  <link type="text/css" rel="stylesheet" href="menu.css">
7*0a6a1f1dSLionel Sambuc  <link type="text/css" rel="stylesheet" href="content.css">
8*0a6a1f1dSLionel Sambuc  <script type="text/javascript" src="scripts/menu.js"></script>
9*0a6a1f1dSLionel Sambuc  <script type="text/javascript" src="scripts/expandcollapse.js"></script>
10*0a6a1f1dSLionel Sambuc  <style type="text/css">
11*0a6a1f1dSLionel Sambuc  tr:first-child { width:20%; }
12*0a6a1f1dSLionel Sambuc  </style>
13*0a6a1f1dSLionel Sambuc</head>
14*0a6a1f1dSLionel Sambuc<body onload="initExpandCollapse()">
15*0a6a1f1dSLionel Sambuc
16*0a6a1f1dSLionel Sambuc<div id="page">
17*0a6a1f1dSLionel Sambuc<!--#include virtual="menu.html.incl"-->
18*0a6a1f1dSLionel Sambuc
19*0a6a1f1dSLionel Sambuc<div id="content">
20*0a6a1f1dSLionel Sambuc<h1>Alpha Checkers</h1>
21*0a6a1f1dSLionel SambucExperimental checkers in addition to the <a href = "available_checks.html">
22*0a6a1f1dSLionel SambucDefault Checkers</a>. These are checkers with known issues or limitations that
23*0a6a1f1dSLionel Sambuckeep them from being on by default. They are likely to have false positives.
24*0a6a1f1dSLionel SambucBug reports are welcome but will likely not be investigated for some time.
25*0a6a1f1dSLionel SambucPatches welcome!
26*0a6a1f1dSLionel Sambuc<ul>
27*0a6a1f1dSLionel Sambuc<li><a href="#core_alpha_checkers">Core Alpha Checkers</a></li>
28*0a6a1f1dSLionel Sambuc<li><a href="#cplusplus_alpha_checkers">C++ Alpha Checkers</a></li>
29*0a6a1f1dSLionel Sambuc<li><a href="#deadcode_alpha_checkers">Dead Code Alpha Checkers</a></li>
30*0a6a1f1dSLionel Sambuc<li><a href="#osx_alpha_checkers">OS X Alpha Checkers</a></li>
31*0a6a1f1dSLionel Sambuc<li><a href="#security_alpha_checkers">Security Alpha Checkers</a></li>
32*0a6a1f1dSLionel Sambuc<li><a href="#unix_alpha_checkers">Unix Alpha Checkers</a></li>
33*0a6a1f1dSLionel Sambuc</ul>
34*0a6a1f1dSLionel Sambuc
35*0a6a1f1dSLionel Sambuc<!------------------------------ core alpha ----------------------------------->
36*0a6a1f1dSLionel Sambuc<h3 id="core_alpha_checkers">Core Alpha Checkers</h3>
37*0a6a1f1dSLionel Sambuc<table class="checkers">
38*0a6a1f1dSLionel Sambuc<colgroup><col class="namedescr"><col class="example"></colgroup>
39*0a6a1f1dSLionel Sambuc<thead><tr><td>Name, Description</td><td>Example</td></tr></thead>
40*0a6a1f1dSLionel Sambuc
41*0a6a1f1dSLionel Sambuc<tbody>
42*0a6a1f1dSLionel Sambuc<tr><td><div class="namedescr expandable"><span class="name">
43*0a6a1f1dSLionel Sambucalpha.core.BoolAssignment</span><span class="lang">
44*0a6a1f1dSLionel Sambuc(ObjC)</span><div class="descr">
45*0a6a1f1dSLionel SambucWarn about assigning non-{0,1} values to boolean variables.</div></div></td>
46*0a6a1f1dSLionel Sambuc<td><div class="exampleContainer expandable">
47*0a6a1f1dSLionel Sambuc<div class="example"><pre>
48*0a6a1f1dSLionel Sambucvoid test() {
49*0a6a1f1dSLionel Sambuc  BOOL b = -1; // warn
50*0a6a1f1dSLionel Sambuc}
51*0a6a1f1dSLionel Sambuc</pre></div></div></td></tr>
52*0a6a1f1dSLionel Sambuc
53*0a6a1f1dSLionel Sambuc
54*0a6a1f1dSLionel Sambuc<tr><td><div class="namedescr expandable"><span class="name">
55*0a6a1f1dSLionel Sambucalpha.core.CastSize</span><span class="lang">
56*0a6a1f1dSLionel Sambuc(C)</span><div class="descr">
57*0a6a1f1dSLionel SambucCheck when casting a malloc'ed type T, whether the size is a multiple of the
58*0a6a1f1dSLionel Sambucsize of T (Works only with <span class="name">unix.Malloc</span>
59*0a6a1f1dSLionel Sambucor <span class="name">alpha.unix.MallocWithAnnotations</span>
60*0a6a1f1dSLionel Sambucchecks enabled).</div></div></td>
61*0a6a1f1dSLionel Sambuc<td><div class="exampleContainer expandable">
62*0a6a1f1dSLionel Sambuc<div class="example"><pre>
63*0a6a1f1dSLionel Sambucvoid test() {
64*0a6a1f1dSLionel Sambuc  int *x = (int *)malloc(11); // warn
65*0a6a1f1dSLionel Sambuc}
66*0a6a1f1dSLionel Sambuc</pre></div></div></td></tr>
67*0a6a1f1dSLionel Sambuc
68*0a6a1f1dSLionel Sambuc
69*0a6a1f1dSLionel Sambuc<tr><td><div class="namedescr expandable"><span class="name">
70*0a6a1f1dSLionel Sambucalpha.core.CastToStruct</span><span class="lang">
71*0a6a1f1dSLionel Sambuc(C, C++)</span><div class="descr">
72*0a6a1f1dSLionel SambucCheck for cast from non-struct pointer to struct pointer.</div></div></td>
73*0a6a1f1dSLionel Sambuc<td><div class="exampleContainer expandable">
74*0a6a1f1dSLionel Sambuc<div class="example"><pre>
75*0a6a1f1dSLionel Sambuc// C
76*0a6a1f1dSLionel Sambucstruct s {};
77*0a6a1f1dSLionel Sambuc
78*0a6a1f1dSLionel Sambucvoid test(int *p) {
79*0a6a1f1dSLionel Sambuc  struct s *ps = (struct s *) p; // warn
80*0a6a1f1dSLionel Sambuc}
81*0a6a1f1dSLionel Sambuc</pre></div><div class="separator"></div>
82*0a6a1f1dSLionel Sambuc<div class="example"><pre>
83*0a6a1f1dSLionel Sambuc// C++
84*0a6a1f1dSLionel Sambucclass c {};
85*0a6a1f1dSLionel Sambuc
86*0a6a1f1dSLionel Sambucvoid test(int *p) {
87*0a6a1f1dSLionel Sambuc  c *pc = (c *) p; // warn
88*0a6a1f1dSLionel Sambuc}
89*0a6a1f1dSLionel Sambuc</pre></div></div></td></tr>
90*0a6a1f1dSLionel Sambuc
91*0a6a1f1dSLionel Sambuc
92*0a6a1f1dSLionel Sambuc<tr><td><div class="namedescr expandable"><span class="name">
93*0a6a1f1dSLionel Sambucalpha.core.FixedAddr</span><span class="lang">
94*0a6a1f1dSLionel Sambuc(C)</span><div class="descr">
95*0a6a1f1dSLionel SambucCheck for assignment of a fixed address to a pointer.</div></div></td>
96*0a6a1f1dSLionel Sambuc<td><div class="exampleContainer expandable">
97*0a6a1f1dSLionel Sambuc<div class="example"><pre>
98*0a6a1f1dSLionel Sambucvoid test() {
99*0a6a1f1dSLionel Sambuc  int *p;
100*0a6a1f1dSLionel Sambuc  p = (int *) 0x10000; // warn
101*0a6a1f1dSLionel Sambuc}
102*0a6a1f1dSLionel Sambuc</pre></div></div></td></tr>
103*0a6a1f1dSLionel Sambuc
104*0a6a1f1dSLionel Sambuc
105*0a6a1f1dSLionel Sambuc<tr><td><div class="namedescr expandable"><span class="name">
106*0a6a1f1dSLionel Sambucalpha.core.IdenticalExpr</span><span class="lang">
107*0a6a1f1dSLionel Sambuc(C, C++)</span><div class="descr">
108*0a6a1f1dSLionel SambucWarn about suspicious uses of identical expressions.</div></div></td>
109*0a6a1f1dSLionel Sambuc<td><div class="exampleContainer expandable">
110*0a6a1f1dSLionel Sambuc<div class="example"><pre>
111*0a6a1f1dSLionel Sambuc// C
112*0a6a1f1dSLionel Sambucvoid test() {
113*0a6a1f1dSLionel Sambuc  int a = 5;
114*0a6a1f1dSLionel Sambuc  int b = a | 4 | a; // warn: identical expr on both sides
115*0a6a1f1dSLionel Sambuc}
116*0a6a1f1dSLionel Sambuc</pre></div><div class="separator"></div>
117*0a6a1f1dSLionel Sambuc<div class="example"><pre>
118*0a6a1f1dSLionel Sambuc// C++
119*0a6a1f1dSLionel Sambucbool f(void);
120*0a6a1f1dSLionel Sambuc
121*0a6a1f1dSLionel Sambucvoid test(bool b) {
122*0a6a1f1dSLionel Sambuc  int i = 10;
123*0a6a1f1dSLionel Sambuc  if (f()) { // warn: true and false branches are identical
124*0a6a1f1dSLionel Sambuc    do {
125*0a6a1f1dSLionel Sambuc      i--;
126*0a6a1f1dSLionel Sambuc    } while (f());
127*0a6a1f1dSLionel Sambuc  } else {
128*0a6a1f1dSLionel Sambuc    do {
129*0a6a1f1dSLionel Sambuc      i--;
130*0a6a1f1dSLionel Sambuc    } while (f());
131*0a6a1f1dSLionel Sambuc  }
132*0a6a1f1dSLionel Sambuc}
133*0a6a1f1dSLionel Sambuc</pre></div></div></td></tr>
134*0a6a1f1dSLionel Sambuc
135*0a6a1f1dSLionel Sambuc
136*0a6a1f1dSLionel Sambuc<tr><td><div class="namedescr expandable"><span class="name">
137*0a6a1f1dSLionel Sambucalpha.core.PointerArithm</span><span class="lang">
138*0a6a1f1dSLionel Sambuc(C)</span><div class="descr">
139*0a6a1f1dSLionel SambucCheck for pointer arithmetic on locations other than array
140*0a6a1f1dSLionel Sambucelements.</div></div></td>
141*0a6a1f1dSLionel Sambuc<td><div class="exampleContainer expandable">
142*0a6a1f1dSLionel Sambuc<div class="example"><pre>
143*0a6a1f1dSLionel Sambucvoid test() {
144*0a6a1f1dSLionel Sambuc  int x;
145*0a6a1f1dSLionel Sambuc  int *p;
146*0a6a1f1dSLionel Sambuc  p = &amp;x + 1; // warn
147*0a6a1f1dSLionel Sambuc}
148*0a6a1f1dSLionel Sambuc</pre></div></div></td></tr>
149*0a6a1f1dSLionel Sambuc
150*0a6a1f1dSLionel Sambuc
151*0a6a1f1dSLionel Sambuc<tr><td><div class="namedescr expandable"><span class="name">
152*0a6a1f1dSLionel Sambucalpha.core.PointerSub</span><span class="lang">
153*0a6a1f1dSLionel Sambuc(C)</span><div class="descr">
154*0a6a1f1dSLionel SambucCheck for pointer subtractions on two pointers pointing to different memory
155*0a6a1f1dSLionel Sambucchunks.</div></div></td>
156*0a6a1f1dSLionel Sambuc<td><div class="exampleContainer expandable">
157*0a6a1f1dSLionel Sambuc<div class="example"><pre>
158*0a6a1f1dSLionel Sambucvoid test() {
159*0a6a1f1dSLionel Sambuc  int x, y;
160*0a6a1f1dSLionel Sambuc  int d = &amp;y - &amp;x; // warn
161*0a6a1f1dSLionel Sambuc}
162*0a6a1f1dSLionel Sambuc</pre></div></div></td></tr>
163*0a6a1f1dSLionel Sambuc
164*0a6a1f1dSLionel Sambuc
165*0a6a1f1dSLionel Sambuc<tr><td><div class="namedescr expandable"><span class="name">
166*0a6a1f1dSLionel Sambucalpha.core.SizeofPtr</span><span class="lang">
167*0a6a1f1dSLionel Sambuc(C)</span><div class="descr">
168*0a6a1f1dSLionel SambucWarn about unintended use of <code>sizeof()</code> on pointer
169*0a6a1f1dSLionel Sambucexpressions.</div></div></td>
170*0a6a1f1dSLionel Sambuc<td><div class="exampleContainer expandable">
171*0a6a1f1dSLionel Sambuc<div class="example"><pre>
172*0a6a1f1dSLionel Sambucstruct s {};
173*0a6a1f1dSLionel Sambuc
174*0a6a1f1dSLionel Sambucint test(struct s *p) {
175*0a6a1f1dSLionel Sambuc  return sizeof(p);
176*0a6a1f1dSLionel Sambuc    // warn: sizeof(ptr) can produce an unexpected result
177*0a6a1f1dSLionel Sambuc}
178*0a6a1f1dSLionel Sambuc</pre></div></div></td></tr>
179*0a6a1f1dSLionel Sambuc
180*0a6a1f1dSLionel Sambuc</tbody></table>
181*0a6a1f1dSLionel Sambuc
182*0a6a1f1dSLionel Sambuc<!--------------------------- cplusplus alpha --------------------------------->
183*0a6a1f1dSLionel Sambuc<h3 id="cplusplus_alpha_checkers">C++ Alpha Checkers</h3>
184*0a6a1f1dSLionel Sambuc<table class="checkers">
185*0a6a1f1dSLionel Sambuc<colgroup><col class="namedescr"><col class="example"></colgroup>
186*0a6a1f1dSLionel Sambuc<thead><tr><td>Name, Description</td><td>Example</td></tr></thead>
187*0a6a1f1dSLionel Sambuc
188*0a6a1f1dSLionel Sambuc<tbody>
189*0a6a1f1dSLionel Sambuc<tr><td><div class="namedescr expandable"><span class="name">
190*0a6a1f1dSLionel Sambucalpha.cplusplus.NewDeleteLeaks</span><span class="lang">
191*0a6a1f1dSLionel Sambuc(C++)</span><div class="descr">
192*0a6a1f1dSLionel SambucCheck for memory leaks. Traces memory managed by <code>new</code>/<code>
193*0a6a1f1dSLionel Sambucdelete</code>.</div></div></td>
194*0a6a1f1dSLionel Sambuc<td><div class="exampleContainer expandable">
195*0a6a1f1dSLionel Sambuc<div class="example"><pre>
196*0a6a1f1dSLionel Sambucvoid test() {
197*0a6a1f1dSLionel Sambuc  int *p = new int;
198*0a6a1f1dSLionel Sambuc} // warn
199*0a6a1f1dSLionel Sambuc</pre></div></div></td></tr>
200*0a6a1f1dSLionel Sambuc
201*0a6a1f1dSLionel Sambuc
202*0a6a1f1dSLionel Sambuc<tr><td><div class="namedescr expandable"><span class="name">
203*0a6a1f1dSLionel Sambucalpha.cplusplus.VirtualCall</span><span class="lang">
204*0a6a1f1dSLionel Sambuc(C++)</span><div class="descr">
205*0a6a1f1dSLionel SambucCheck virtual member function calls during construction or
206*0a6a1f1dSLionel Sambucdestruction.</div></div></td>
207*0a6a1f1dSLionel Sambuc<td><div class="exampleContainer expandable">
208*0a6a1f1dSLionel Sambuc<div class="example"><pre>
209*0a6a1f1dSLionel Sambucclass A {
210*0a6a1f1dSLionel Sambucpublic:
211*0a6a1f1dSLionel Sambuc  A() {
212*0a6a1f1dSLionel Sambuc    f(); // warn
213*0a6a1f1dSLionel Sambuc  }
214*0a6a1f1dSLionel Sambuc  virtual void f();
215*0a6a1f1dSLionel Sambuc};
216*0a6a1f1dSLionel Sambuc</pre></div><div class="separator"></div>
217*0a6a1f1dSLionel Sambuc<div class="example"><pre>
218*0a6a1f1dSLionel Sambucclass A {
219*0a6a1f1dSLionel Sambucpublic:
220*0a6a1f1dSLionel Sambuc  ~A() {
221*0a6a1f1dSLionel Sambuc    this-&gt;f(); // warn
222*0a6a1f1dSLionel Sambuc  }
223*0a6a1f1dSLionel Sambuc  virtual void f();
224*0a6a1f1dSLionel Sambuc};
225*0a6a1f1dSLionel Sambuc</pre></div></div></td></tr>
226*0a6a1f1dSLionel Sambuc
227*0a6a1f1dSLionel Sambuc</tbody></table>
228*0a6a1f1dSLionel Sambuc
229*0a6a1f1dSLionel Sambuc<!--------------------------- dead code alpha --------------------------------->
230*0a6a1f1dSLionel Sambuc<h3 id="deadcode_alpha_checkers">Dead Code Alpha Checkers</h3>
231*0a6a1f1dSLionel Sambuc<table class="checkers">
232*0a6a1f1dSLionel Sambuc<colgroup><col class="namedescr"><col class="example"></colgroup>
233*0a6a1f1dSLionel Sambuc<thead><tr><td>Name, Description</td><td>Example</td></tr></thead>
234*0a6a1f1dSLionel Sambuc
235*0a6a1f1dSLionel Sambuc<tbody>
236*0a6a1f1dSLionel Sambuc<tr><td><div class="namedescr expandable"><span class="name">
237*0a6a1f1dSLionel Sambucalpha.deadcode.UnreachableCode</span><span class="lang">
238*0a6a1f1dSLionel Sambuc(C, C++, ObjC)</span><div class="descr">
239*0a6a1f1dSLionel SambucCheck unreachable code.</div></div></td>
240*0a6a1f1dSLionel Sambuc<td><div class="exampleContainer expandable">
241*0a6a1f1dSLionel Sambuc<div class="example"><pre>
242*0a6a1f1dSLionel Sambuc// C
243*0a6a1f1dSLionel Sambucint test() {
244*0a6a1f1dSLionel Sambuc  int x = 1;
245*0a6a1f1dSLionel Sambuc  while(x);
246*0a6a1f1dSLionel Sambuc  return x; // warn
247*0a6a1f1dSLionel Sambuc}
248*0a6a1f1dSLionel Sambuc</pre></div><div class="separator"></div>
249*0a6a1f1dSLionel Sambuc<div class="example"><pre>
250*0a6a1f1dSLionel Sambuc// C++
251*0a6a1f1dSLionel Sambucvoid test() {
252*0a6a1f1dSLionel Sambuc  int a = 2;
253*0a6a1f1dSLionel Sambuc
254*0a6a1f1dSLionel Sambuc  while (a > 1)
255*0a6a1f1dSLionel Sambuc    a--;
256*0a6a1f1dSLionel Sambuc
257*0a6a1f1dSLionel Sambuc  if (a > 1)
258*0a6a1f1dSLionel Sambuc    a++; // warn
259*0a6a1f1dSLionel Sambuc}
260*0a6a1f1dSLionel Sambuc</pre></div><div class="separator"></div>
261*0a6a1f1dSLionel Sambuc<div class="example"><pre>
262*0a6a1f1dSLionel Sambuc// Objective-C
263*0a6a1f1dSLionel Sambucvoid test(id x) {
264*0a6a1f1dSLionel Sambuc  return;
265*0a6a1f1dSLionel Sambuc  [x retain]; // warn
266*0a6a1f1dSLionel Sambuc}
267*0a6a1f1dSLionel Sambuc</pre></div></div></td></tr>
268*0a6a1f1dSLionel Sambuc</tbody></table>
269*0a6a1f1dSLionel Sambuc
270*0a6a1f1dSLionel Sambuc<!---------------------------- OS X alpha -------------------------------------->
271*0a6a1f1dSLionel Sambuc<h3 id="osx_alpha_checkers">OS X Alpha Checkers</h3>
272*0a6a1f1dSLionel Sambuc<table class="checkers">
273*0a6a1f1dSLionel Sambuc<colgroup><col class="namedescr"><col class="example"></colgroup>
274*0a6a1f1dSLionel Sambuc<thead><tr><td>Name, Description</td><td>Example</td></tr></thead>
275*0a6a1f1dSLionel Sambuc
276*0a6a1f1dSLionel Sambuc<tbody>
277*0a6a1f1dSLionel Sambuc<tr><td><div class="namedescr expandable"><span class="name">
278*0a6a1f1dSLionel Sambucalpha.osx.cocoa.Dealloc</span><span class="lang">
279*0a6a1f1dSLionel Sambuc(ObjC)</span><div class="descr">
280*0a6a1f1dSLionel SambucWarn about Objective-C classes that lack a correct implementation
281*0a6a1f1dSLionel Sambucof <code>-dealloc</code>.
282*0a6a1f1dSLionel Sambuc</div></div></td>
283*0a6a1f1dSLionel Sambuc<td><div class="exampleContainer expandable">
284*0a6a1f1dSLionel Sambuc<div class="example"><pre>
285*0a6a1f1dSLionel Sambuc@interface MyObject : NSObject {
286*0a6a1f1dSLionel Sambuc  id _myproperty;
287*0a6a1f1dSLionel Sambuc}
288*0a6a1f1dSLionel Sambuc@end
289*0a6a1f1dSLionel Sambuc
290*0a6a1f1dSLionel Sambuc@implementation MyObject // warn: lacks 'dealloc'
291*0a6a1f1dSLionel Sambuc@end
292*0a6a1f1dSLionel Sambuc</pre></div><div class="separator"></div>
293*0a6a1f1dSLionel Sambuc<div class="example"><pre>
294*0a6a1f1dSLionel Sambuc@interface MyObject : NSObject {}
295*0a6a1f1dSLionel Sambuc@property(assign) id myproperty;
296*0a6a1f1dSLionel Sambuc@end
297*0a6a1f1dSLionel Sambuc
298*0a6a1f1dSLionel Sambuc@implementation MyObject // warn: does not send 'dealloc' to super
299*0a6a1f1dSLionel Sambuc- (void)dealloc {
300*0a6a1f1dSLionel Sambuc  self.myproperty = 0;
301*0a6a1f1dSLionel Sambuc}
302*0a6a1f1dSLionel Sambuc@end
303*0a6a1f1dSLionel Sambuc</pre></div><div class="separator"></div>
304*0a6a1f1dSLionel Sambuc<div class="example"><pre>
305*0a6a1f1dSLionel Sambuc@interface MyObject : NSObject {
306*0a6a1f1dSLionel Sambuc  id _myproperty;
307*0a6a1f1dSLionel Sambuc}
308*0a6a1f1dSLionel Sambuc@property(retain) id myproperty;
309*0a6a1f1dSLionel Sambuc@end
310*0a6a1f1dSLionel Sambuc
311*0a6a1f1dSLionel Sambuc@implementation MyObject
312*0a6a1f1dSLionel Sambuc@synthesize myproperty = _myproperty;
313*0a6a1f1dSLionel Sambuc  // warn: var was retained but wasn't released
314*0a6a1f1dSLionel Sambuc- (void)dealloc {
315*0a6a1f1dSLionel Sambuc  [super dealloc];
316*0a6a1f1dSLionel Sambuc}
317*0a6a1f1dSLionel Sambuc@end
318*0a6a1f1dSLionel Sambuc</pre></div><div class="separator"></div>
319*0a6a1f1dSLionel Sambuc<div class="example"><pre>
320*0a6a1f1dSLionel Sambuc@interface MyObject : NSObject {
321*0a6a1f1dSLionel Sambuc  id _myproperty;
322*0a6a1f1dSLionel Sambuc}
323*0a6a1f1dSLionel Sambuc@property(assign) id myproperty;
324*0a6a1f1dSLionel Sambuc@end
325*0a6a1f1dSLionel Sambuc
326*0a6a1f1dSLionel Sambuc@implementation MyObject
327*0a6a1f1dSLionel Sambuc@synthesize myproperty = _myproperty;
328*0a6a1f1dSLionel Sambuc  // warn: var wasn't retained but was released
329*0a6a1f1dSLionel Sambuc- (void)dealloc {
330*0a6a1f1dSLionel Sambuc  [_myproperty release];
331*0a6a1f1dSLionel Sambuc  [super dealloc];
332*0a6a1f1dSLionel Sambuc}
333*0a6a1f1dSLionel Sambuc@end
334*0a6a1f1dSLionel Sambuc</pre></div></div></td></tr>
335*0a6a1f1dSLionel Sambuc
336*0a6a1f1dSLionel Sambuc
337*0a6a1f1dSLionel Sambuc<tr><td><div class="namedescr expandable"><span class="name">
338*0a6a1f1dSLionel Sambucalpha.osx.cocoa.DirectIvarAssignment</span><span class="lang">
339*0a6a1f1dSLionel Sambuc(ObjC)</span><div class="descr">
340*0a6a1f1dSLionel SambucCheck that Objective C properties follow the following rule: the property
341*0a6a1f1dSLionel Sambucshould be set with the setter, not though a direct assignment.</div></div></td>
342*0a6a1f1dSLionel Sambuc<td><div class="exampleContainer expandable">
343*0a6a1f1dSLionel Sambuc<div class="example"><pre>
344*0a6a1f1dSLionel Sambuc@interface MyClass : NSObject {}
345*0a6a1f1dSLionel Sambuc@property (readonly) id A;
346*0a6a1f1dSLionel Sambuc- (void) foo;
347*0a6a1f1dSLionel Sambuc@end
348*0a6a1f1dSLionel Sambuc
349*0a6a1f1dSLionel Sambuc@implementation MyClass
350*0a6a1f1dSLionel Sambuc- (void) foo {
351*0a6a1f1dSLionel Sambuc  _A = 0; // warn
352*0a6a1f1dSLionel Sambuc}
353*0a6a1f1dSLionel Sambuc@end
354*0a6a1f1dSLionel Sambuc</pre></div></div></td></tr>
355*0a6a1f1dSLionel Sambuc
356*0a6a1f1dSLionel Sambuc
357*0a6a1f1dSLionel Sambuc<tr><td><div class="namedescr expandable"><span class="name">
358*0a6a1f1dSLionel Sambucalpha.osx.cocoa.DirectIvarAssignmentForAnnotatedFunctions</span><span class="lang">
359*0a6a1f1dSLionel Sambuc(ObjC)</span><div class="descr">
360*0a6a1f1dSLionel SambucCheck for direct assignments to instance variables in the methods annotated
361*0a6a1f1dSLionel Sambucwith <code>objc_no_direct_instance_variable_assignment</code>.</div></div></td>
362*0a6a1f1dSLionel Sambuc<td><div class="exampleContainer expandable">
363*0a6a1f1dSLionel Sambuc<div class="example"><pre>
364*0a6a1f1dSLionel Sambuc@interface MyClass : NSObject {}
365*0a6a1f1dSLionel Sambuc@property (readonly) id A;
366*0a6a1f1dSLionel Sambuc- (void) fAnnotated __attribute__((
367*0a6a1f1dSLionel Sambuc    annotate("objc_no_direct_instance_variable_assignment")));
368*0a6a1f1dSLionel Sambuc- (void) fNotAnnotated;
369*0a6a1f1dSLionel Sambuc@end
370*0a6a1f1dSLionel Sambuc
371*0a6a1f1dSLionel Sambuc@implementation MyClass
372*0a6a1f1dSLionel Sambuc- (void) fAnnotated {
373*0a6a1f1dSLionel Sambuc  _A = 0; // warn
374*0a6a1f1dSLionel Sambuc}
375*0a6a1f1dSLionel Sambuc- (void) fNotAnnotated {
376*0a6a1f1dSLionel Sambuc  _A = 0; // no warn
377*0a6a1f1dSLionel Sambuc}
378*0a6a1f1dSLionel Sambuc@end
379*0a6a1f1dSLionel Sambuc</pre></div></div></td></tr>
380*0a6a1f1dSLionel Sambuc
381*0a6a1f1dSLionel Sambuc
382*0a6a1f1dSLionel Sambuc<tr><td><div class="namedescr expandable"><span class="name">
383*0a6a1f1dSLionel Sambucalpha.osx.cocoa.InstanceVariableInvalidation</span><span class="lang">
384*0a6a1f1dSLionel Sambuc(ObjC)</span><div class="descr">
385*0a6a1f1dSLionel SambucCheck that the invalidatable instance variables are invalidated in the methods
386*0a6a1f1dSLionel Sambucannotated with <code>objc_instance_variable_invalidator</code>.</div></div></td>
387*0a6a1f1dSLionel Sambuc<td><div class="exampleContainer expandable">
388*0a6a1f1dSLionel Sambuc<div class="example"><pre>
389*0a6a1f1dSLionel Sambuc@protocol Invalidation &lt;NSObject&gt;
390*0a6a1f1dSLionel Sambuc- (void) invalidate
391*0a6a1f1dSLionel Sambuc  __attribute__((annotate("objc_instance_variable_invalidator")));
392*0a6a1f1dSLionel Sambuc@end
393*0a6a1f1dSLionel Sambuc
394*0a6a1f1dSLionel Sambuc@interface InvalidationImpObj : NSObject &lt;Invalidation&gt;
395*0a6a1f1dSLionel Sambuc@end
396*0a6a1f1dSLionel Sambuc
397*0a6a1f1dSLionel Sambuc@interface SubclassInvalidationImpObj : InvalidationImpObj {
398*0a6a1f1dSLionel Sambuc  InvalidationImpObj *var;
399*0a6a1f1dSLionel Sambuc}
400*0a6a1f1dSLionel Sambuc- (void)invalidate;
401*0a6a1f1dSLionel Sambuc@end
402*0a6a1f1dSLionel Sambuc
403*0a6a1f1dSLionel Sambuc@implementation SubclassInvalidationImpObj
404*0a6a1f1dSLionel Sambuc- (void) invalidate {}
405*0a6a1f1dSLionel Sambuc@end
406*0a6a1f1dSLionel Sambuc// warn: var needs to be invalidated or set to nil
407*0a6a1f1dSLionel Sambuc</pre></div></div></td></tr>
408*0a6a1f1dSLionel Sambuc
409*0a6a1f1dSLionel Sambuc
410*0a6a1f1dSLionel Sambuc<tr><td><div class="namedescr expandable"><span class="name">
411*0a6a1f1dSLionel Sambucalpha.osx.cocoa.MissingInvalidationMethod</span><span class="lang">
412*0a6a1f1dSLionel Sambuc(ObjC)</span><div class="descr">
413*0a6a1f1dSLionel SambucCheck that the invalidation methods are present in classes that contain
414*0a6a1f1dSLionel Sambucinvalidatable instance variables.</div></div></td>
415*0a6a1f1dSLionel Sambuc<td><div class="exampleContainer expandable">
416*0a6a1f1dSLionel Sambuc<div class="example"><pre>
417*0a6a1f1dSLionel Sambuc@protocol Invalidation &lt;NSObject&gt;
418*0a6a1f1dSLionel Sambuc- (void)invalidate
419*0a6a1f1dSLionel Sambuc  __attribute__((annotate("objc_instance_variable_invalidator")));
420*0a6a1f1dSLionel Sambuc@end
421*0a6a1f1dSLionel Sambuc
422*0a6a1f1dSLionel Sambuc@interface NeedInvalidation : NSObject &lt;Invalidation&gt;
423*0a6a1f1dSLionel Sambuc@end
424*0a6a1f1dSLionel Sambuc
425*0a6a1f1dSLionel Sambuc@interface MissingInvalidationMethodDecl : NSObject {
426*0a6a1f1dSLionel Sambuc  NeedInvalidation *Var; // warn
427*0a6a1f1dSLionel Sambuc}
428*0a6a1f1dSLionel Sambuc@end
429*0a6a1f1dSLionel Sambuc
430*0a6a1f1dSLionel Sambuc@implementation MissingInvalidationMethodDecl
431*0a6a1f1dSLionel Sambuc@end
432*0a6a1f1dSLionel Sambuc</pre></div></div></td></tr>
433*0a6a1f1dSLionel Sambuc
434*0a6a1f1dSLionel Sambuc</tbody></table>
435*0a6a1f1dSLionel Sambuc
436*0a6a1f1dSLionel Sambuc<!------------------------- security alpha ------------------------------------>
437*0a6a1f1dSLionel Sambuc<h3 id="security_alpha_checkers">Security Alpha Checkers</h3>
438*0a6a1f1dSLionel Sambuc<table class="checkers">
439*0a6a1f1dSLionel Sambuc<colgroup><col class="namedescr"><col class="example"></colgroup>
440*0a6a1f1dSLionel Sambuc<thead><tr><td>Name, Description</td><td>Example</td></tr></thead>
441*0a6a1f1dSLionel Sambuc
442*0a6a1f1dSLionel Sambuc<tbody>
443*0a6a1f1dSLionel Sambuc<tr><td><div class="namedescr expandable"><span class="name">
444*0a6a1f1dSLionel Sambucalpha.security.ArrayBound</span><span class="lang">
445*0a6a1f1dSLionel Sambuc(C)</span><div class="descr">
446*0a6a1f1dSLionel SambucWarn about buffer overflows (older checker).</div></div></td>
447*0a6a1f1dSLionel Sambuc<td><div class="exampleContainer expandable">
448*0a6a1f1dSLionel Sambuc<div class="example"><pre>
449*0a6a1f1dSLionel Sambucvoid test() {
450*0a6a1f1dSLionel Sambuc  char *s = "";
451*0a6a1f1dSLionel Sambuc  char c = s[1]; // warn
452*0a6a1f1dSLionel Sambuc}
453*0a6a1f1dSLionel Sambuc</pre></div><div class="separator"></div>
454*0a6a1f1dSLionel Sambuc<div class="example"><pre>
455*0a6a1f1dSLionel Sambucstruct seven_words {
456*0a6a1f1dSLionel Sambuc  int c[7];
457*0a6a1f1dSLionel Sambuc};
458*0a6a1f1dSLionel Sambuc
459*0a6a1f1dSLionel Sambucvoid test() {
460*0a6a1f1dSLionel Sambuc  struct seven_words a, *p;
461*0a6a1f1dSLionel Sambuc  p = &a;
462*0a6a1f1dSLionel Sambuc  p[0] = a;
463*0a6a1f1dSLionel Sambuc  p[1] = a;
464*0a6a1f1dSLionel Sambuc  p[2] = a; // warn
465*0a6a1f1dSLionel Sambuc}
466*0a6a1f1dSLionel Sambuc</pre></div><div class="separator"></div>
467*0a6a1f1dSLionel Sambuc<div class="example"><pre>
468*0a6a1f1dSLionel Sambuc// note: requires unix.Malloc or
469*0a6a1f1dSLionel Sambuc// alpha.unix.MallocWithAnnotations checks enabled.
470*0a6a1f1dSLionel Sambucvoid test() {
471*0a6a1f1dSLionel Sambuc  int *p = malloc(12);
472*0a6a1f1dSLionel Sambuc  p[3] = 4; // warn
473*0a6a1f1dSLionel Sambuc}
474*0a6a1f1dSLionel Sambuc</pre></div><div class="separator"></div>
475*0a6a1f1dSLionel Sambuc<div class="example"><pre>
476*0a6a1f1dSLionel Sambucvoid test() {
477*0a6a1f1dSLionel Sambuc  char a[2];
478*0a6a1f1dSLionel Sambuc  int *b = (int*)a;
479*0a6a1f1dSLionel Sambuc  b[1] = 3; // warn
480*0a6a1f1dSLionel Sambuc}
481*0a6a1f1dSLionel Sambuc</pre></div></div></td></tr>
482*0a6a1f1dSLionel Sambuc
483*0a6a1f1dSLionel Sambuc
484*0a6a1f1dSLionel Sambuc<tr><td><div class="namedescr expandable"><span class="name">
485*0a6a1f1dSLionel Sambucalpha.security.ArrayBoundV2</span><span class="lang">
486*0a6a1f1dSLionel Sambuc(C)</span><div class="descr">
487*0a6a1f1dSLionel SambucWarn about buffer overflows (newer checker).</div></div></td>
488*0a6a1f1dSLionel Sambuc<td><div class="exampleContainer expandable">
489*0a6a1f1dSLionel Sambuc<div class="example"><pre>
490*0a6a1f1dSLionel Sambucvoid test() {
491*0a6a1f1dSLionel Sambuc  char *s = "";
492*0a6a1f1dSLionel Sambuc  char c = s[1]; // warn
493*0a6a1f1dSLionel Sambuc}
494*0a6a1f1dSLionel Sambuc</pre></div><div class="separator"></div>
495*0a6a1f1dSLionel Sambuc<div class="example"><pre>
496*0a6a1f1dSLionel Sambucvoid test() {
497*0a6a1f1dSLionel Sambuc  int buf[100];
498*0a6a1f1dSLionel Sambuc  int *p = buf;
499*0a6a1f1dSLionel Sambuc  p = p + 99;
500*0a6a1f1dSLionel Sambuc  p[1] = 1; // warn
501*0a6a1f1dSLionel Sambuc}
502*0a6a1f1dSLionel Sambuc</pre></div><div class="separator"></div>
503*0a6a1f1dSLionel Sambuc<div class="example"><pre>
504*0a6a1f1dSLionel Sambuc// note: compiler has internal check for this.
505*0a6a1f1dSLionel Sambuc// Use -Wno-array-bounds to suppress compiler warning.
506*0a6a1f1dSLionel Sambucvoid test() {
507*0a6a1f1dSLionel Sambuc  int buf[100][100];
508*0a6a1f1dSLionel Sambuc  buf[0][-1] = 1; // warn
509*0a6a1f1dSLionel Sambuc}
510*0a6a1f1dSLionel Sambuc</pre></div><div class="separator"></div>
511*0a6a1f1dSLionel Sambuc<div class="example"><pre>
512*0a6a1f1dSLionel Sambuc// note: requires alpha.security.taint check turned on.
513*0a6a1f1dSLionel Sambucvoid test() {
514*0a6a1f1dSLionel Sambuc  char s[] = "abc";
515*0a6a1f1dSLionel Sambuc  int x = getchar();
516*0a6a1f1dSLionel Sambuc  char c = s[x]; // warn: index is tainted
517*0a6a1f1dSLionel Sambuc}
518*0a6a1f1dSLionel Sambuc</pre></div></div></td></tr>
519*0a6a1f1dSLionel Sambuc
520*0a6a1f1dSLionel Sambuc
521*0a6a1f1dSLionel Sambuc<tr><td><div class="namedescr expandable"><span class="name">
522*0a6a1f1dSLionel Sambucalpha.security.MallocOverflow</span><span class="lang">
523*0a6a1f1dSLionel Sambuc(C)</span><div class="descr">
524*0a6a1f1dSLionel SambucCheck for overflows in the arguments to <code>malloc()</code>.</div></div></td>
525*0a6a1f1dSLionel Sambuc<td><div class="exampleContainer expandable">
526*0a6a1f1dSLionel Sambuc<div class="example"><pre>
527*0a6a1f1dSLionel Sambucvoid test(int n) {
528*0a6a1f1dSLionel Sambuc  void *p = malloc(n * sizeof(int)); // warn
529*0a6a1f1dSLionel Sambuc}
530*0a6a1f1dSLionel Sambuc</pre></div></div></td></tr>
531*0a6a1f1dSLionel Sambuc
532*0a6a1f1dSLionel Sambuc
533*0a6a1f1dSLionel Sambuc<tr><td><div class="namedescr expandable"><span class="name">
534*0a6a1f1dSLionel Sambucalpha.security.ReturnPtrRange</span><span class="lang">
535*0a6a1f1dSLionel Sambuc(C)</span><div class="descr">
536*0a6a1f1dSLionel SambucCheck for an out-of-bound pointer being returned to callers.</div></div></td>
537*0a6a1f1dSLionel Sambuc<td><div class="exampleContainer expandable">
538*0a6a1f1dSLionel Sambuc<div class="example"><pre>
539*0a6a1f1dSLionel Sambucstatic int A[10];
540*0a6a1f1dSLionel Sambuc
541*0a6a1f1dSLionel Sambucint *test() {
542*0a6a1f1dSLionel Sambuc  int *p = A + 10;
543*0a6a1f1dSLionel Sambuc  return p; // warn
544*0a6a1f1dSLionel Sambuc}
545*0a6a1f1dSLionel Sambuc</pre></div><div class="separator"></div>
546*0a6a1f1dSLionel Sambuc<div class="example"><pre>
547*0a6a1f1dSLionel Sambucint test(void) {
548*0a6a1f1dSLionel Sambuc  int x;
549*0a6a1f1dSLionel Sambuc  return x; // warn: undefined or garbage returned
550*0a6a1f1dSLionel Sambuc}
551*0a6a1f1dSLionel Sambuc</pre></div></div></td></tr>
552*0a6a1f1dSLionel Sambuc
553*0a6a1f1dSLionel Sambuc
554*0a6a1f1dSLionel Sambuc<tr><td><div class="namedescr expandable"><span class="name">
555*0a6a1f1dSLionel Sambucalpha.security.taint.TaintPropagation</span><span class="lang">
556*0a6a1f1dSLionel Sambuc(C)</span><div class="descr">
557*0a6a1f1dSLionel SambucGenerate taint information used by other checkers.</div></div></td>
558*0a6a1f1dSLionel Sambuc<td><div class="exampleContainer expandable">
559*0a6a1f1dSLionel Sambuc<div class="example"><pre>
560*0a6a1f1dSLionel Sambucvoid test() {
561*0a6a1f1dSLionel Sambuc  char x = getchar(); // 'x' marked as tainted
562*0a6a1f1dSLionel Sambuc  system(&x); // warn: untrusted data is passed to a system call
563*0a6a1f1dSLionel Sambuc}
564*0a6a1f1dSLionel Sambuc</pre></div><div class="separator"></div>
565*0a6a1f1dSLionel Sambuc<div class="example"><pre>
566*0a6a1f1dSLionel Sambuc// note: compiler internally checks if the second param to
567*0a6a1f1dSLionel Sambuc// sprintf is a string literal or not.
568*0a6a1f1dSLionel Sambuc// Use -Wno-format-security to suppress compiler warning.
569*0a6a1f1dSLionel Sambucvoid test() {
570*0a6a1f1dSLionel Sambuc  char s[10], buf[10];
571*0a6a1f1dSLionel Sambuc  fscanf(stdin, "%s", s); // 's' marked as tainted
572*0a6a1f1dSLionel Sambuc
573*0a6a1f1dSLionel Sambuc  sprintf(buf, s); // warn: untrusted data as a format string
574*0a6a1f1dSLionel Sambuc}
575*0a6a1f1dSLionel Sambuc</pre></div><div class="separator"></div>
576*0a6a1f1dSLionel Sambuc<div class="example"><pre>
577*0a6a1f1dSLionel Sambucvoid test() {
578*0a6a1f1dSLionel Sambuc  size_t ts;
579*0a6a1f1dSLionel Sambuc  scanf("%zd", &ts); // 'ts' marked as tainted
580*0a6a1f1dSLionel Sambuc  int *p = (int *)malloc(ts * sizeof(int));
581*0a6a1f1dSLionel Sambuc    // warn: untrusted data as bufer size
582*0a6a1f1dSLionel Sambuc}
583*0a6a1f1dSLionel Sambuc</pre></div></div></td></tr>
584*0a6a1f1dSLionel Sambuc
585*0a6a1f1dSLionel Sambuc</tbody></table>
586*0a6a1f1dSLionel Sambuc
587*0a6a1f1dSLionel Sambuc<!--------------------------- unix alpha -------------------------------------->
588*0a6a1f1dSLionel Sambuc<h3 id="unix_alpha_checkers">Unix Alpha Checkers</h3>
589*0a6a1f1dSLionel Sambuc<table class="checkers">
590*0a6a1f1dSLionel Sambuc<colgroup><col class="namedescr"><col class="example"></colgroup>
591*0a6a1f1dSLionel Sambuc<thead><tr><td>Name, Description</td><td>Example</td></tr></thead>
592*0a6a1f1dSLionel Sambuc
593*0a6a1f1dSLionel Sambuc<tbody>
594*0a6a1f1dSLionel Sambuc<tr><td><div class="namedescr expandable"><span class="name">
595*0a6a1f1dSLionel Sambucalpha.unix.Chroot</span><span class="lang">
596*0a6a1f1dSLionel Sambuc(C)</span><div class="descr">
597*0a6a1f1dSLionel SambucCheck improper use of <code>chroot</code>.</div></div></td>
598*0a6a1f1dSLionel Sambuc<td><div class="exampleContainer expandable">
599*0a6a1f1dSLionel Sambuc<div class="example"><pre>
600*0a6a1f1dSLionel Sambucvoid f();
601*0a6a1f1dSLionel Sambuc
602*0a6a1f1dSLionel Sambucvoid test() {
603*0a6a1f1dSLionel Sambuc  chroot("/usr/local");
604*0a6a1f1dSLionel Sambuc  f(); // warn: no call of chdir("/") immediately after chroot
605*0a6a1f1dSLionel Sambuc}
606*0a6a1f1dSLionel Sambuc</pre></div></div></td></tr>
607*0a6a1f1dSLionel Sambuc
608*0a6a1f1dSLionel Sambuc
609*0a6a1f1dSLionel Sambuc<tr><td><div class="namedescr expandable"><span class="name">
610*0a6a1f1dSLionel Sambucalpha.unix.MallocWithAnnotations</span><span class="lang">
611*0a6a1f1dSLionel Sambuc(C)</span><div class="descr">
612*0a6a1f1dSLionel SambucCheck for memory leaks, double free, and use-after-free problems. Assumes that
613*0a6a1f1dSLionel Sambucall user-defined functions which might free a pointer are
614*0a6a1f1dSLionel Sambucannotated.</div></div></td>
615*0a6a1f1dSLionel Sambuc<td><div class="exampleContainer expandable">
616*0a6a1f1dSLionel Sambuc<div class="example"><pre>
617*0a6a1f1dSLionel Sambucvoid __attribute((ownership_returns(malloc))) *my_malloc(size_t);
618*0a6a1f1dSLionel Sambuc
619*0a6a1f1dSLionel Sambucvoid test() {
620*0a6a1f1dSLionel Sambuc  int *p = my_malloc(1);
621*0a6a1f1dSLionel Sambuc} // warn: potential leak
622*0a6a1f1dSLionel Sambuc</pre></div><div class="separator"></div>
623*0a6a1f1dSLionel Sambuc<div class="example"><pre>
624*0a6a1f1dSLionel Sambucvoid __attribute((ownership_returns(malloc))) *my_malloc(size_t);
625*0a6a1f1dSLionel Sambucvoid __attribute((ownership_takes(malloc, 1))) my_free(void *);
626*0a6a1f1dSLionel Sambuc
627*0a6a1f1dSLionel Sambucvoid test() {
628*0a6a1f1dSLionel Sambuc  int *p = my_malloc(1);
629*0a6a1f1dSLionel Sambuc  my_free(p);
630*0a6a1f1dSLionel Sambuc  my_free(p); // warn: attempt to free released
631*0a6a1f1dSLionel Sambuc}
632*0a6a1f1dSLionel Sambuc</pre></div><div class="separator"></div>
633*0a6a1f1dSLionel Sambuc<div class="example"><pre>
634*0a6a1f1dSLionel Sambucvoid __attribute((ownership_returns(malloc))) *my_malloc(size_t);
635*0a6a1f1dSLionel Sambucvoid __attribute((ownership_holds(malloc, 1))) my_hold(void *);
636*0a6a1f1dSLionel Sambuc
637*0a6a1f1dSLionel Sambucvoid test() {
638*0a6a1f1dSLionel Sambuc  int *p = my_malloc(1);
639*0a6a1f1dSLionel Sambuc  my_hold(p);
640*0a6a1f1dSLionel Sambuc  free(p); // warn: attempt to free non-owned memory
641*0a6a1f1dSLionel Sambuc}
642*0a6a1f1dSLionel Sambuc</pre></div><div class="separator"></div>
643*0a6a1f1dSLionel Sambuc<div class="example"><pre>
644*0a6a1f1dSLionel Sambucvoid __attribute((ownership_takes(malloc, 1))) my_free(void *);
645*0a6a1f1dSLionel Sambuc
646*0a6a1f1dSLionel Sambucvoid test() {
647*0a6a1f1dSLionel Sambuc  int *p = malloc(1);
648*0a6a1f1dSLionel Sambuc  my_free(p);
649*0a6a1f1dSLionel Sambuc  *p = 1; // warn: use after free
650*0a6a1f1dSLionel Sambuc}
651*0a6a1f1dSLionel Sambuc</pre></div></div></td></tr>
652*0a6a1f1dSLionel Sambuc
653*0a6a1f1dSLionel Sambuc
654*0a6a1f1dSLionel Sambuc<tr><td><div class="namedescr expandable"><span class="name">
655*0a6a1f1dSLionel Sambucalpha.unix.PthreadLock</span><span class="lang">
656*0a6a1f1dSLionel Sambuc(C)</span><div class="descr">
657*0a6a1f1dSLionel SambucSimple lock -> unlock checker; applies to:<div class=functions>
658*0a6a1f1dSLionel Sambucpthread_mutex_lock<br>
659*0a6a1f1dSLionel Sambucpthread_rwlock_rdlock<br>
660*0a6a1f1dSLionel Sambucpthread_rwlock_wrlock<br>
661*0a6a1f1dSLionel Sambuclck_mtx_lock<br>
662*0a6a1f1dSLionel Sambuclck_rw_lock_exclusive<br>
663*0a6a1f1dSLionel Sambuclck_rw_lock_shared<br>
664*0a6a1f1dSLionel Sambucpthread_mutex_trylock<br>
665*0a6a1f1dSLionel Sambucpthread_rwlock_tryrdlock<br>
666*0a6a1f1dSLionel Sambucpthread_rwlock_tryrwlock<br>
667*0a6a1f1dSLionel Sambuclck_mtx_try_lock<br>
668*0a6a1f1dSLionel Sambuclck_rw_try_lock_exclusive<br>
669*0a6a1f1dSLionel Sambuclck_rw_try_lock_shared<br>
670*0a6a1f1dSLionel Sambucpthread_mutex_unlock<br>
671*0a6a1f1dSLionel Sambucpthread_rwlock_unlock<br>
672*0a6a1f1dSLionel Sambuclck_mtx_unlock<br>
673*0a6a1f1dSLionel Sambuclck_rw_done</div></div></div></td>
674*0a6a1f1dSLionel Sambuc<td><div class="exampleContainer expandable">
675*0a6a1f1dSLionel Sambuc<div class="example"><pre>
676*0a6a1f1dSLionel Sambucpthread_mutex_t mtx;
677*0a6a1f1dSLionel Sambuc
678*0a6a1f1dSLionel Sambucvoid test() {
679*0a6a1f1dSLionel Sambuc  pthread_mutex_lock(&mtx);
680*0a6a1f1dSLionel Sambuc  pthread_mutex_lock(&mtx);
681*0a6a1f1dSLionel Sambuc    // warn: this lock has already been acquired
682*0a6a1f1dSLionel Sambuc}
683*0a6a1f1dSLionel Sambuc</pre></div><div class="separator"></div>
684*0a6a1f1dSLionel Sambuc<div class="example"><pre>
685*0a6a1f1dSLionel Sambuclck_mtx_t lck1, lck2;
686*0a6a1f1dSLionel Sambuc
687*0a6a1f1dSLionel Sambucvoid test() {
688*0a6a1f1dSLionel Sambuc  lck_mtx_lock(&lck1);
689*0a6a1f1dSLionel Sambuc  lck_mtx_lock(&lck2);
690*0a6a1f1dSLionel Sambuc  lck_mtx_unlock(&lck1);
691*0a6a1f1dSLionel Sambuc    // warn: this was not the most recently acquired lock
692*0a6a1f1dSLionel Sambuc}
693*0a6a1f1dSLionel Sambuc</pre></div><div class="separator"></div>
694*0a6a1f1dSLionel Sambuc<div class="example"><pre>
695*0a6a1f1dSLionel Sambuclck_mtx_t lck1, lck2;
696*0a6a1f1dSLionel Sambuc
697*0a6a1f1dSLionel Sambucvoid test() {
698*0a6a1f1dSLionel Sambuc  if (lck_mtx_try_lock(&lck1) == 0)
699*0a6a1f1dSLionel Sambuc    return;
700*0a6a1f1dSLionel Sambuc
701*0a6a1f1dSLionel Sambuc  lck_mtx_lock(&lck2);
702*0a6a1f1dSLionel Sambuc  lck_mtx_unlock(&lck1);
703*0a6a1f1dSLionel Sambuc    // warn: this was not the most recently acquired lock
704*0a6a1f1dSLionel Sambuc}
705*0a6a1f1dSLionel Sambuc</pre></div></div></td></tr>
706*0a6a1f1dSLionel Sambuc
707*0a6a1f1dSLionel Sambuc
708*0a6a1f1dSLionel Sambuc<tr><td><div class="namedescr expandable"><span class="name">
709*0a6a1f1dSLionel Sambucalpha.unix.SimpleStream</span><span class="lang">
710*0a6a1f1dSLionel Sambuc(C)</span><div class="descr">
711*0a6a1f1dSLionel SambucCheck for misuses of stream APIs:<div class=functions>
712*0a6a1f1dSLionel Sambucfopen<br>
713*0a6a1f1dSLionel Sambucfclose</div>(demo checker, the subject of the demo
714*0a6a1f1dSLionel Sambuc(<a href="http://llvm.org/devmtg/2012-11/Zaks-Rose-Checker24Hours.pdf">Slides</a>
715*0a6a1f1dSLionel Sambuc,<a href="http://llvm.org/devmtg/2012-11/videos/Zaks-Rose-Checker24Hours.mp4">Video</a>)
716*0a6a1f1dSLionel Sambucby Anna Zaks and Jordan Rose presented at the <a href="http://llvm.org/devmtg/2012-11/">
717*0a6a1f1dSLionel Sambuc2012 LLVM Developers' Meeting).</a></div></div></td>
718*0a6a1f1dSLionel Sambuc<td><div class="exampleContainer expandable">
719*0a6a1f1dSLionel Sambuc<div class="example"><pre>
720*0a6a1f1dSLionel Sambucvoid test() {
721*0a6a1f1dSLionel Sambuc  FILE *F = fopen("myfile.txt", "w");
722*0a6a1f1dSLionel Sambuc} // warn: opened file is never closed
723*0a6a1f1dSLionel Sambuc</pre></div><div class="separator"></div>
724*0a6a1f1dSLionel Sambuc<div class="example"><pre>
725*0a6a1f1dSLionel Sambucvoid test() {
726*0a6a1f1dSLionel Sambuc  FILE *F = fopen("myfile.txt", "w");
727*0a6a1f1dSLionel Sambuc
728*0a6a1f1dSLionel Sambuc  if (F)
729*0a6a1f1dSLionel Sambuc    fclose(F);
730*0a6a1f1dSLionel Sambuc
731*0a6a1f1dSLionel Sambuc  fclose(F); // warn: closing a previously closed file stream
732*0a6a1f1dSLionel Sambuc}
733*0a6a1f1dSLionel Sambuc</pre></div></div></td></tr>
734*0a6a1f1dSLionel Sambuc
735*0a6a1f1dSLionel Sambuc
736*0a6a1f1dSLionel Sambuc<tr><td><div class="namedescr expandable"><span class="name">
737*0a6a1f1dSLionel Sambucalpha.unix.Stream</span><span class="lang">
738*0a6a1f1dSLionel Sambuc(C)</span><div class="descr">
739*0a6a1f1dSLionel SambucCheck stream handling functions:<div class=functions>fopen<br>
740*0a6a1f1dSLionel Sambuctmpfile<br>
741*0a6a1f1dSLionel Sambucfclose<br>
742*0a6a1f1dSLionel Sambucfread<br>
743*0a6a1f1dSLionel Sambucfwrite<br>
744*0a6a1f1dSLionel Sambucfseek<br>
745*0a6a1f1dSLionel Sambucftell<br>
746*0a6a1f1dSLionel Sambucrewind<br>
747*0a6a1f1dSLionel Sambucfgetpos<br>
748*0a6a1f1dSLionel Sambucfsetpos<br>
749*0a6a1f1dSLionel Sambucclearerr<br>
750*0a6a1f1dSLionel Sambucfeof<br>
751*0a6a1f1dSLionel Sambucferror<br>
752*0a6a1f1dSLionel Sambucfileno</div></div></div></td>
753*0a6a1f1dSLionel Sambuc<td><div class="exampleContainer expandable">
754*0a6a1f1dSLionel Sambuc<div class="example"><pre>
755*0a6a1f1dSLionel Sambucvoid test() {
756*0a6a1f1dSLionel Sambuc  FILE *p = fopen("foo", "r");
757*0a6a1f1dSLionel Sambuc} // warn: opened file is never closed
758*0a6a1f1dSLionel Sambuc</pre></div><div class="separator"></div>
759*0a6a1f1dSLionel Sambuc<div class="example"><pre>
760*0a6a1f1dSLionel Sambucvoid test() {
761*0a6a1f1dSLionel Sambuc  FILE *p = fopen("foo", "r");
762*0a6a1f1dSLionel Sambuc  fseek(p, 1, SEEK_SET); // warn: stream pointer might be NULL
763*0a6a1f1dSLionel Sambuc  fclose(p);
764*0a6a1f1dSLionel Sambuc}
765*0a6a1f1dSLionel Sambuc</pre></div><div class="separator"></div>
766*0a6a1f1dSLionel Sambuc<div class="example"><pre>
767*0a6a1f1dSLionel Sambucvoid test() {
768*0a6a1f1dSLionel Sambuc  FILE *p = fopen("foo", "r");
769*0a6a1f1dSLionel Sambuc
770*0a6a1f1dSLionel Sambuc  if (p)
771*0a6a1f1dSLionel Sambuc    fseek(p, 1, 3);
772*0a6a1f1dSLionel Sambuc     // warn: third arg should be SEEK_SET, SEEK_END, or SEEK_CUR
773*0a6a1f1dSLionel Sambuc
774*0a6a1f1dSLionel Sambuc  fclose(p);
775*0a6a1f1dSLionel Sambuc}
776*0a6a1f1dSLionel Sambuc</pre></div><div class="separator"></div>
777*0a6a1f1dSLionel Sambuc<div class="example"><pre>
778*0a6a1f1dSLionel Sambucvoid test() {
779*0a6a1f1dSLionel Sambuc  FILE *p = fopen("foo", "r");
780*0a6a1f1dSLionel Sambuc  fclose(p);
781*0a6a1f1dSLionel Sambuc  fclose(p); // warn: already closed
782*0a6a1f1dSLionel Sambuc}
783*0a6a1f1dSLionel Sambuc</pre></div><div class="separator"></div>
784*0a6a1f1dSLionel Sambuc<div class="example"><pre>
785*0a6a1f1dSLionel Sambucvoid test() {
786*0a6a1f1dSLionel Sambuc  FILE *p = tmpfile();
787*0a6a1f1dSLionel Sambuc  ftell(p); // warn: stream pointer might be NULL
788*0a6a1f1dSLionel Sambuc  fclose(p);
789*0a6a1f1dSLionel Sambuc}
790*0a6a1f1dSLionel Sambuc</pre></div></div></td></tr>
791*0a6a1f1dSLionel Sambuc
792*0a6a1f1dSLionel Sambuc
793*0a6a1f1dSLionel Sambuc<tr><td><div class="namedescr expandable"><span class="name">
794*0a6a1f1dSLionel Sambucalpha.unix.cstring.BufferOverlap</span><span class="lang">
795*0a6a1f1dSLionel Sambuc(C)</span><div class="descr">
796*0a6a1f1dSLionel SambucChecks for overlap in two buffer arguments; applies to:<div class=functions>
797*0a6a1f1dSLionel Sambucmemcpy<br>
798*0a6a1f1dSLionel Sambucmempcpy</div></div></div></td>
799*0a6a1f1dSLionel Sambuc<td><div class="exampleContainer expandable">
800*0a6a1f1dSLionel Sambuc<div class="example"><pre>
801*0a6a1f1dSLionel Sambucvoid test() {
802*0a6a1f1dSLionel Sambuc  int a[4] = {0};
803*0a6a1f1dSLionel Sambuc  memcpy(a + 2, a + 1, 8); // warn
804*0a6a1f1dSLionel Sambuc}
805*0a6a1f1dSLionel Sambuc</pre></div></div></td></tr>
806*0a6a1f1dSLionel Sambuc
807*0a6a1f1dSLionel Sambuc
808*0a6a1f1dSLionel Sambuc<tr><td><div class="namedescr expandable"><span class="name">
809*0a6a1f1dSLionel Sambucalpha.unix.cstring.NotNullTerminated</span><span class="lang">
810*0a6a1f1dSLionel Sambuc(C)</span><div class="descr">
811*0a6a1f1dSLionel SambucCheck for arguments which are not null-terminated strings; applies
812*0a6a1f1dSLionel Sambucto:<div class=functions>
813*0a6a1f1dSLionel Sambucstrlen<br>
814*0a6a1f1dSLionel Sambucstrnlen<br>
815*0a6a1f1dSLionel Sambucstrcpy<br>
816*0a6a1f1dSLionel Sambucstrncpy<br>
817*0a6a1f1dSLionel Sambucstrcat<br>
818*0a6a1f1dSLionel Sambucstrncat</div></div></div></td>
819*0a6a1f1dSLionel Sambuc<td><div class="exampleContainer expandable">
820*0a6a1f1dSLionel Sambuc<div class="example"><pre>
821*0a6a1f1dSLionel Sambucvoid test() {
822*0a6a1f1dSLionel Sambuc  int y = strlen((char *)&test); // warn
823*0a6a1f1dSLionel Sambuc}
824*0a6a1f1dSLionel Sambuc</pre></div></div></td></tr>
825*0a6a1f1dSLionel Sambuc
826*0a6a1f1dSLionel Sambuc
827*0a6a1f1dSLionel Sambuc<tr><td><div class="namedescr expandable"><span class="name">
828*0a6a1f1dSLionel Sambucalpha.unix.cstring.OutOfBounds</span><span class="lang">
829*0a6a1f1dSLionel Sambuc(C)</span><div class="descr">
830*0a6a1f1dSLionel SambucCheck for out-of-bounds access in string functions; applies
831*0a6a1f1dSLionel Sambucto:<div class=functions>
832*0a6a1f1dSLionel Sambucstrncopy<br>
833*0a6a1f1dSLionel Sambucstrncat</div></div></div></td>
834*0a6a1f1dSLionel Sambuc<td><div class="exampleContainer expandable">
835*0a6a1f1dSLionel Sambuc<div class="example"><pre>
836*0a6a1f1dSLionel Sambucvoid test(char *y) {
837*0a6a1f1dSLionel Sambuc  char x[4];
838*0a6a1f1dSLionel Sambuc  if (strlen(y) == 4)
839*0a6a1f1dSLionel Sambuc    strncpy(x, y, 5); // warn
840*0a6a1f1dSLionel Sambuc}
841*0a6a1f1dSLionel Sambuc</pre></div></div></td></tr>
842*0a6a1f1dSLionel Sambuc
843*0a6a1f1dSLionel Sambuc</tbody></table>
844*0a6a1f1dSLionel Sambuc
845*0a6a1f1dSLionel Sambuc</div> <!-- page -->
846*0a6a1f1dSLionel Sambuc</div> <!-- content -->
847*0a6a1f1dSLionel Sambuc</body>
848*0a6a1f1dSLionel Sambuc</html>
849