Skip to content

Commit 57a1559

Browse files
committed
Add a little more clarity about the heuristics and how to fix the broken example
1 parent b199be6 commit 57a1559

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

docs/code-quality/c6011.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,7 @@ The careless use of `malloc` and `free` leads to memory leaks and exceptions. To
6666
6767
## Heuristics
6868
69-
Pointers are assumed to be non-null unless there is some evidence that they might be null.
70-
In the examples we've seen so far, pointers returned by `malloc` or `new` might be null because allocation might fail.
71-
Another characteristic that the analysis engine uses as evidence of nullability is if the program explicitly checks for null.
72-
This is illustrated in the following examples:
69+
Code analysis assumes pointers are non-null unless there is some evidence that they might be null, which is a heuristic used to reduce the number of warnings in legacy code. In the examples we've seen so far, pointers returned by `malloc` or `new` might be null because allocation might fail. Another characteristic that the analysis engine uses as evidence of nullability is if the program explicitly checks for null. This is illustrated in the following examples:
7370
7471
```cpp
7572
void f(int* n)
@@ -86,6 +83,8 @@ void f(int* n)
8683
}
8784
```
8885

86+
In the second case, the user can fix the warning by moving the `*n = 1` line inside the if block.
87+
8988
## See also
9089

9190
- [Using SAL Annotations to reduce code defects](using-sal-annotations-to-reduce-c-cpp-code-defects.md)

0 commit comments

Comments
 (0)