FAQ and How to Deal with Common False Positives
- How do I tell the analyzer that I do not want the bug being reported here since my custom error handler will safely end the execution before the bug is reached?
- The analyzer reports a null dereference, but I know that the pointer is never null. How can I tell the analyzer that a pointer can never be null?
- 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?
- How can I suppress a specific analyzer warning?
Q: How do I tell the analyzer that I do not want the bug being reported here since my custom error handler will safely end the execution before the bug is reached?

You can tell the analyzer that this path is unreachable by teaching it about your custom assertion handlers. For example, you can modify the code segment as following.
void customAssert() __attribute__((analyzer_noreturn));
int foo(int *b) {
if (!b)
customAssert();
return *b;
}
Q: The analyzer reports a null dereference, but I know that the pointer is never null. How can I tell the analyzer that a pointer can never be null?

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 if (!b) check.
void usePointer(int *b); int foo(int *b) { usePointer(b); return *b; }
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?

You can teach the analyzer facts about your code as well as document it by using assertions. 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 length is always greater than 0. The false positive can be suppressed by asserting this knowledge, adding assert(length > 0) in the beginning of the function.
int foo(int length) {
int x = 0;
assert(length > 0);
for (int i = 0; i < length; i++)
x += 1;
return length/x;
}
Q: How can I suppress a specific analyzer warning?
There is currently no mechanism for suppressing the analyzer warning, although this is currently being investigated. If you encounter an analyzer bug/false positive, please report it.