You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: cpp/ql/src/Critical/DeadCodeCondition.qhelp
+14-11Lines changed: 14 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -5,23 +5,26 @@
5
5
6
6
7
7
<overview>
8
-
<p>This rule finds branching statements with conditions that always evaluate to the same value.
9
-
More likely than not these conditions indicate a defect in the branching condition or are an artifact left behind after debugging.</p>
8
+
<p>This query finds branching statements with conditions that always evaluate to the same value.
9
+
It is likely that these conditions indicate an error in the branching condition.
10
+
Alternatively, the conditions may have been left behind after debugging.</p>
10
11
11
12
<includesrc="aliasAnalysisWarning.qhelp" />
12
-
13
13
</overview>
14
-
<recommendation>
15
-
<p>Check the branch condition for defects, and verify that it isn't a remnant from debugging.</p>
16
14
15
+
<recommendation>
16
+
<p>Check the branch condition for logic errors. Check whether it is still required.</p>
17
17
</recommendation>
18
-
<example><samplesrc="DeadCodeCondition.cpp" />
19
-
20
-
21
-
22
-
23
-
24
18
19
+
<example>
20
+
<p>This example shows two branch conditions that always evaluate to the same value.
21
+
The two conditions and their associated branches should be deleted.
22
+
This will simplify the code and make it easier to maintain.</p>
25
23
24
+
<samplesrc="DeadCodeCondition.cpp" />
26
25
</example>
26
+
27
+
<references>
28
+
<li>SEI CERT C++ Coding Standard <ahref="https://wiki.sei.cmu.edu/confluence/display/c/MSC12-C.+Detect+and+remove+code+that+has+no+effect+or+is+never+executed">MSC12-C. Detect and remove code that has no effect or is never executed</a>.</li>
Copy file name to clipboardExpand all lines: cpp/ql/src/Critical/DeadCodeFunction.qhelp
+14-11Lines changed: 14 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -3,28 +3,31 @@
3
3
"qhelp.dtd">
4
4
<qhelp>
5
5
6
-
7
6
<overview>
8
-
<p>This rule finds functions that are non-public, non-virtual and are never called. Dead functions are often deprecated pieces of code, and should be removed
9
-
as they may increase object code size, decrease code comprehensibility, and create the possibility of misuse.</p>
7
+
<p>This query highlights functions that are non-public, non-virtual, and are never called.
8
+
Dead functions are often deprecated pieces of code, and should be removed.
9
+
If left in the code base they increase object code size, decrease code comprehensibility, and create the possibility of misuse.</p>
10
10
11
11
<p>
12
-
<code>public</code> and <code>protected</code> functions are not considered by the check, as they could be part of the program's
13
-
API and could be used by external programs.
12
+
<code>public</code> and <code>protected</code> functions are ignored by this query.
13
+
This type of function may be part of the program's API and could be used by external programs.
14
14
</p>
15
15
16
16
<includesrc="callGraphWarning.qhelp" />
17
-
18
17
</overview>
19
-
<recommendation>
20
-
<p>Consider removing the function.</p>
21
18
19
+
<recommendation>
20
+
<p>Verify that the function is genuinely unused and consider removing it.</p>
22
21
</recommendation>
23
-
<example><samplesrc="DeadCodeFunction.cpp" />
24
-
25
22
26
23
24
+
<example>
25
+
<p>The example below includes a function <code>f</code> that is no longer used and should be deleted.</p>
26
+
<samplesrc="DeadCodeFunction.cpp" />
27
+
</example>
27
28
29
+
<references>
30
+
<li>SEI CERT C++ Coding Standard: <ahref="https://wiki.sei.cmu.edu/confluence/display/c/MSC12-C.+Detect+and+remove+code+that+has+no+effect+or+is+never+executed">MSC12-C. Detect and remove code that has no effect or is never executed</a>.</li>
Copy file name to clipboardExpand all lines: cpp/ql/src/Critical/DeadCodeFunction.ql
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
/**
2
2
* @name Function is never called
3
-
* @description A function is never called, and should be considered for removal. Unused functions may increase object size, decrease readability and create the possibility of misuse.
3
+
* @description Unused functions may increase object size, decrease readability, and create the possibility of misuse.
Copy file name to clipboardExpand all lines: cpp/ql/src/Critical/GlobalUseBeforeInit.qhelp
+9-9Lines changed: 9 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -5,26 +5,26 @@
5
5
6
6
7
7
<overview>
8
-
<p>This rule finds calls to functions that use a global variable which happen before the variable was initialized.
8
+
<p>This rule finds calls to functions that use a global variable before the variable has been initialized.
9
9
Not all compilers generate code that zero-out memory, especially when optimizations are enabled or the compiler
10
10
is not compliant with the latest language standards. Accessing uninitialized memory will lead to undefined results.
11
11
</p>
12
12
13
13
<includesrc="dataFlowWarning.qhelp" />
14
-
15
14
</overview>
15
+
16
16
<recommendation>
17
17
<p>
18
18
Initialize the global variable. If no constant can be used for initialization, ensure that all accesses to the variable occur after
19
19
the initialization code is executed.
20
20
</p>
21
-
22
21
</recommendation>
23
-
<example><samplesrc="GlobalUseBeforeInit.cpp" />
24
-
25
-
26
-
27
-
28
-
22
+
<example>
23
+
In the example below, <code>callCtr</code> is wrongly used before it has been initialized.
24
+
<samplesrc="GlobalUseBeforeInit.cpp" />
29
25
</example>
26
+
27
+
<references>
28
+
<li>SEI CERT C++ Coding Standard: <ahref="https://wiki.sei.cmu.edu/confluence/display/cplusplus/EXP53-CPP.+Do+not+read+uninitialized+memory">EXP53-CPP. Do not read uninitialized memory</a>.</li>
Copy file name to clipboardExpand all lines: cpp/ql/src/Critical/GlobalUseBeforeInit.ql
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
/**
2
-
* @name Global variable used before initialization
3
-
* @description A function that uses a global variable has been called before the variable has been initialized. Not all compilers zero-out memory for variables, especially when optimizations are enabled, or if the compiler is not compliant with the latest language standards. Using an uninitialized variable leads to undefined results.
2
+
* @name Global variable may be used before initialization
3
+
* @description Using an uninitialized variable leads to undefined results.
This code shows two examples where a pointer is dereferenced.
24
+
The first example checks that the pointer is not null before dereferencing it.
25
+
The second example fails to perform a nullnes check, leading to a potential vulnerability in the code.
26
+
<samplesrc="InconsistentNullnessTesting.cpp" />
26
27
</example>
28
+
29
+
<references>
30
+
<li>SEI CERT C++ Coding Standard: <ahref="https://wiki.sei.cmu.edu/confluence/display/c/MEM10-C.+Define+and+use+a+pointer+validation+function">MEM10-C. Define and use a pointer validation function</a>.</li>
Copy file name to clipboardExpand all lines: cpp/ql/src/Critical/InconsistentNullnessTesting.ql
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
/**
2
2
* @name Inconsistent null check of pointer
3
-
* @description A dereferenced pointer is not checked for nullness in the given location, but is checked in other locations. Dereferencing a NULL pointer leads to undefined results.
3
+
* @description A dereferenced pointer is not checked for nullness in this location, but it is checked in other locations. Dereferencing a null pointer leads to undefined results.
Copy file name to clipboardExpand all lines: cpp/ql/src/Critical/OverflowDestination.qhelp
+13-9Lines changed: 13 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -3,27 +3,31 @@
3
3
"qhelp.dtd">
4
4
<qhelp>
5
5
<overview>
6
-
<p>The bounded copy functions <code>memcpy</code>, <code>memmove</code>, <code>strncpy</code>, <code>strncat</code> accept a size argument. You should call these functions with a size argument that is derived from the size of the destination buffer. Using a size argument that is derived from the source buffer may cause a buffer overflow. Buffer overflows can lead to anything from a segmentation fault to a security vulnerability.</p>
0 commit comments