Repository navigation
Expand file tree
/
Copy pathInconsistentCheckReturnNull.qhelp
More file actions
48 lines (38 loc) · 1.85 KB
/
Copy pathInconsistentCheckReturnNull.qhelp
File metadata and controls
48 lines (38 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<!DOCTYPE qhelp PUBLIC
"-//Semmle//qhelp//EN"
"qhelp.dtd">
<qhelp>
<overview>
<p>A common source of defects is to forget to check if the result of a function
call was NULL. This rules detects calls to a function where most other calls
check the result for NULL but this particular call does not. This is
inconsistent with the rest of the code and may be a defect or at least
confusing for other developers.</p>
<p>The flagged calls will not necessarily result in run-time errors, but all of
them benefit from being audited. It is important not to mechanically add
nullness checks at every flagged location, because an unnecessary nullness
check is very confusing to other developers. A developer that is familiar with
the code will most likely immediately know what the right action is on a null
result, and if that is not the case there is most likely something confusing
about the API of the called function.</p>
</overview>
<recommendation>
<p>Diagnose if the called function can actually return NULL with the context at
this particular call. If that is the case the code should be updated to cater
for that situation. If the call can not return null in this location, it may be
good to add an assert to document that the code does not handle NULL. This
documentation is important since most calls expect to receive a NULL
value.</p>
</recommendation>
<example><sample src="InconsistentCheckReturnNull.cpp" />
</example>
<references>
<li>
Tutorialspoint - The C++ Programming Language: <a href="http://www.tutorialspoint.com/cplusplus/cpp_dynamic_memory.htm">C++ Dynamic Memory</a>,
<a href="http://www.tutorialspoint.com/cplusplus/cpp_null_pointers.htm">C++ NULL pointers</a>.
</li>
<li>
Code project: <a href="https://www.codeproject.com/Articles/109026/Chained-null-checks-and-the-Maybe-monad">Chained null checks and the Maybe monad</a>.
</li>
</references>
</qhelp>