Anna Zaks | 568bdee | 2012-06-09 01:04:54 +0000 | [diff] [blame] | 1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" |
| 2 | "http://www.w3.org/TR/html4/strict.dtd"> |
| 3 | <html> |
| 4 | <head> |
Anna Zaks | 70186fc | 2012-06-09 01:05:01 +0000 | [diff] [blame] | 5 | <title>FAQ and How to Deal with Common False Positives</title> |
Anna Zaks | 568bdee | 2012-06-09 01:04:54 +0000 | [diff] [blame] | 6 | <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 Kremenek | c1cb12b | 2012-06-09 20:10:42 +0000 | [diff] [blame^] | 20 | <h1>FAQ and How to Deal with Common False Positives</h1> |
Anna Zaks | 568bdee | 2012-06-09 01:04:54 +0000 | [diff] [blame] | 21 | |
Ted Kremenek | c1cb12b | 2012-06-09 20:10:42 +0000 | [diff] [blame^] | 22 | <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 Zaks | 568bdee | 2012-06-09 01:04:54 +0000 | [diff] [blame] | 23 | |
| 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 Kremenek | c1cb12b | 2012-06-09 20:10:42 +0000 | [diff] [blame^] | 28 | <h4>Q: The analyzer reports "Dereference of null pointer", but I know that the pointer is never null.</h4> |
Anna Zaks | 568bdee | 2012-06-09 01:04:54 +0000 | [diff] [blame] | 29 | |
| 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 Kremenek | c1cb12b | 2012-06-09 20:10:42 +0000 | [diff] [blame^] | 34 | <h4>Q: The analyzer assumes that the loop body is never entered, which can never happen in this code.</h4> |
Anna Zaks | 568bdee | 2012-06-09 01:04:54 +0000 | [diff] [blame] | 35 | |
| 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 Kremenek | c1cb12b | 2012-06-09 20:10:42 +0000 | [diff] [blame^] | 40 | <h4>Q: How can I suppress the analyzer warning?</h4> |
Anna Zaks | 568bdee | 2012-06-09 01:04:54 +0000 | [diff] [blame] | 41 | |
| 42 | <img src="images/example_null_pointer.png" alt="example null pointer"> |
| 43 | |
Ted Kremenek | c1cb12b | 2012-06-09 20:10:42 +0000 | [diff] [blame^] | 44 | <p>There is currently no mechanism for suppressing the analyzer warning, |
| 45 | although this is currently being investigated. If you encounter an analyzer |
| 46 | bug/false positive, please <a href = "filing_bugs.html">report it</a>.</p> |
Anna Zaks | 568bdee | 2012-06-09 01:04:54 +0000 | [diff] [blame] | 47 | |
| 48 | </div> |
| 49 | </div> |
| 50 | </body> |
| 51 | </html> |
| 52 | |