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"> |
Ted Kremenek | dea37f2 | 2012-06-09 20:10:45 +0000 | [diff] [blame^] | 10 | tr:first-child { width:20%; } |
Anna Zaks | 568bdee | 2012-06-09 01:04:54 +0000 | [diff] [blame] | 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 | dea37f2 | 2012-06-09 20:10:45 +0000 | [diff] [blame^] | 22 | <h4 class="faq">Q: How do I tell the analyzer that I do not want the bug being |
| 23 | reported here since my custom error handler will safely end the execution before |
| 24 | the bug is reached?</h4> |
Anna Zaks | 568bdee | 2012-06-09 01:04:54 +0000 | [diff] [blame] | 25 | |
| 26 | <img src="images/example_custom_assert.png" alt="example custom assert"> |
| 27 | |
| 28 | <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> |
| 29 | |
Ted Kremenek | dea37f2 | 2012-06-09 20:10:45 +0000 | [diff] [blame^] | 30 | <h4 class="faq">Q: The analyzer reports a null dereference, but I know that the |
| 31 | pointer is never null. How can I tell the analyzer that a pointer can never be |
| 32 | null?</h4> |
Anna Zaks | 568bdee | 2012-06-09 01:04:54 +0000 | [diff] [blame] | 33 | |
| 34 | <img src="images/example_null_pointer.png" alt="example null pointer"> |
| 35 | |
Ted Kremenek | dea37f2 | 2012-06-09 20:10:45 +0000 | [diff] [blame^] | 36 | <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 assertion as well. For example, in the code segment above, it will be sufficient to remove the <tt>if (!b)</tt> check. </p> |
Anna Zaks | 568bdee | 2012-06-09 01:04:54 +0000 | [diff] [blame] | 37 | |
Ted Kremenek | dea37f2 | 2012-06-09 20:10:45 +0000 | [diff] [blame^] | 38 | <h4 class="faq">Q: The analyzer assumes that a loop body is never entered. How can I tell it that the loop body will be entered at least once?</h4> |
Anna Zaks | 568bdee | 2012-06-09 01:04:54 +0000 | [diff] [blame] | 39 | |
| 40 | <img src="images/example_use_assert.png" alt="example use assert"> |
| 41 | |
Ted Kremenek | dea37f2 | 2012-06-09 20:10:45 +0000 | [diff] [blame^] | 42 | <p>You can teach the analyzer facts about your code as well as document it by |
| 43 | using assertions. In the contrived example above, the analyzer reports an error |
| 44 | on the path which assumes that the loop is never entered. However, the owner of |
| 45 | the code might know that the loop is always entered because the input parameter |
| 46 | <tt>length</tt> is always greater than <tt>0</tt>. The false positive can be |
| 47 | suppressed by asserting this knowledge, adding <tt>assert(length > 0)</tt> in |
| 48 | the beginning of the function.</p> |
Anna Zaks | 568bdee | 2012-06-09 01:04:54 +0000 | [diff] [blame] | 49 | |
Ted Kremenek | dea37f2 | 2012-06-09 20:10:45 +0000 | [diff] [blame^] | 50 | <h4 class="faq">Q: How can I suppress a specific analyzer warning?</h4> |
Anna Zaks | 568bdee | 2012-06-09 01:04:54 +0000 | [diff] [blame] | 51 | |
| 52 | <img src="images/example_null_pointer.png" alt="example null pointer"> |
| 53 | |
Ted Kremenek | c1cb12b | 2012-06-09 20:10:42 +0000 | [diff] [blame] | 54 | <p>There is currently no mechanism for suppressing the analyzer warning, |
| 55 | although this is currently being investigated. If you encounter an analyzer |
| 56 | 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] | 57 | |
| 58 | </div> |
| 59 | </div> |
| 60 | </body> |
| 61 | </html> |
| 62 | |