blob: 1859e78926278067b056470b1829349be75f7e89 [file] [log] [blame]
Anna Zaks568bdee2012-06-09 01:04:54 +00001<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
2 "http://www.w3.org/TR/html4/strict.dtd">
3<html>
4<head>
Anna Zaks70186fc2012-06-09 01:05:01 +00005 <title>FAQ and How to Deal with Common False Positives</title>
Anna Zaks568bdee2012-06-09 01:04:54 +00006 <link type="text/css" rel="stylesheet" href="menu.css">
7 <link type="text/css" rel="stylesheet" href="content.css">
8 <script type="text/javascript" src="scripts/menu.js"></script>
9 <style type="text/css">
10 tr:first-child { width:20%; }
11 </style>
12</head>
13<body>
14
15<div id="page">
16<!--#include virtual="menu.html.incl"-->
17
18<div id="content">
19
Ted Kremenekc1cb12b2012-06-09 20:10:42 +000020<h1>FAQ and How to Deal with Common False Positives</h1>
Anna Zaks568bdee2012-06-09 01:04:54 +000021
Ted Kremenekc1cb12b2012-06-09 20:10:42 +000022<h4>Q: The analyzer reports a bug on an error path. I do not want the bug being reported here since my custom error handler will safely end the execution before the bug is reached.</h4>
Anna Zaks568bdee2012-06-09 01:04:54 +000023
24<img src="images/example_custom_assert.png" alt="example custom assert">
25
26<p>You can tell the analyzer that this path is unreachable by teaching it about your <a href = "annotations.html#custom_assertions" >custom assertion handlers</a>.</p>
27
Ted Kremenekc1cb12b2012-06-09 20:10:42 +000028<h4>Q: The analyzer reports "Dereference of null pointer", but I know that the pointer is never null.</h4>
Anna Zaks568bdee2012-06-09 01:04:54 +000029
30<img src="images/example_null_pointer.png" alt="example null pointer">
31
32<p>The reason the analyzer often thinks that a pointer can be null is because the preceding code checked compared it against null. So if you are absolutely sure that it cannot be null, remove the preceding check and, preferably, add an assert as well. For example, in the code segment above, it will be sufficient to remove the <tt>if (!b)</tt> check. </p>
33
Ted Kremenekc1cb12b2012-06-09 20:10:42 +000034<h4>Q: The analyzer assumes that the loop body is never entered, which can never happen in this code.</h4>
Anna Zaks568bdee2012-06-09 01:04:54 +000035
36<img src="images/example_use_assert.png" alt="example use assert">
37
38<p>You can teach the analyzer facts about your code as well as document it by using asserts. In the contrived example above, the analyzer reports an error on the path which assumes that the loop is never entered. However, the owner of the code might know that the loop is always entered because the input parameter <tt>length</tt> is always greater than <tt>0</tt>. The false positive can be suppressed by asserting this knowledge, adding <tt>assert(length > 0)</tt> in the beginning of the function.</p>
39
Ted Kremenekc1cb12b2012-06-09 20:10:42 +000040<h4>Q: How can I suppress the analyzer warning?</h4>
Anna Zaks568bdee2012-06-09 01:04:54 +000041
42<img src="images/example_null_pointer.png" alt="example null pointer">
43
Ted Kremenekc1cb12b2012-06-09 20:10:42 +000044<p>There is currently no mechanism for suppressing the analyzer warning,
45although this is currently being investigated. If you encounter an analyzer
46bug/false positive, please <a href = "filing_bugs.html">report it</a>.</p>
Anna Zaks568bdee2012-06-09 01:04:54 +000047
48</div>
49</div>
50</body>
51</html>
52