Skip to content

Commit 16ec9f1

Browse files
committed
Merge remote-tracking branch 'origin/next' into bump/master-next
2 parents dd4c965 + 90c75cd commit 16ec9f1

File tree

140 files changed

+6132
-6025
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

140 files changed

+6132
-6025
lines changed

cpp/ql/src/Critical/NotInitialised.ql

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99
*/
1010
import cpp
1111

12-
// This query is the JSF version
13-
//
14-
// (see also InitialisationNotRun.ql and GlobalUseBeforeInit.ql)
12+
// See also InitialisationNotRun.ql and GlobalUseBeforeInit.ql
1513

1614
// Holds if s defines variable v (conservative)
1715
predicate defines(ControlFlowNode s, Variable lv) {

cpp/ql/src/META-INF/MANIFEST.MF

Lines changed: 0 additions & 8 deletions
This file was deleted.

cpp/ql/src/jsf/4.05 Libraries/AV Rule 24.qhelp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@
55

66

77
<overview>
8+
9+
<!-- Mention that this rule may not be applicable in projects that don't follow the JSF standard. -->
10+
<include src="cpp/jsfNote.qhelp" />
11+
812
<p>
9-
This rule finds calls to the standard library functions <code>abort, exit, getenv</code> and <code>system</code>.
13+
This query highlights calls to the standard library functions <code>abort, exit, getenv</code> and <code>system</code>.
1014
The functions <code>abort</code> and <code>exit</code> should not be called as they immediately terminate the program
1115
and will bypass all the normal error and exception handling routines in the software. This is especially important in
1216
software which is run on systems without an interactive OS, as restarting the software may require a complete reboot

cpp/ql/src/jsf/4.10 Classes/AV Rule 85.qhelp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@
55

66

77
<overview>
8+
9+
<!-- Mention that this rule may not be applicable in projects that don't follow the JSF standard. -->
10+
<include src="cpp/jsfNote.qhelp" />
11+
812
<p>
9-
This rule ensures that all operators with opposites (e.g. == and !=) are both defined, and
13+
This query ensures that all operators with opposites (e.g. == and !=) are both defined, and
1014
that one of them is defined in terms of the other. This just enforces the consistency of meaning
1115
of the operators.
1216
</p>

cpp/ql/src/jsf/4.10 Classes/AV Rule 85.ql

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,50 @@ predicate oppositeOperators(string op1, string op2) {
1919
/* this match is very syntactic: we simply check that op1 is defined as
2020
!op2(_, _) */
2121
predicate implementedAsNegationOf(Operator op1, Operator op2) {
22-
exists(Block b, ReturnStmt r, NotExpr n, FunctionCall c |
22+
exists(Block b, ReturnStmt r, NotExpr n, Expr o |
2323
b = op1.getBlock() and
2424
b.getNumStmt() = 1 and
2525
r = b.getStmt(0) and
2626
n = r.getExpr() and
27-
c = n.getOperand() and
28-
c.getTarget() = op2)
27+
o = n.getOperand() and
28+
(
29+
o instanceof LTExpr and op2.hasName("operator<") or
30+
o instanceof LEExpr and op2.hasName("operator<=") or
31+
o instanceof GTExpr and op2.hasName("operator>") or
32+
o instanceof GEExpr and op2.hasName("operator>=") or
33+
o instanceof EQExpr and op2.hasName("operator==") or
34+
o instanceof NEExpr and op2.hasName("operator!=") or
35+
o.(FunctionCall).getTarget() = op2
36+
)
37+
)
38+
}
39+
40+
predicate classIsCheckableFor(Class c, string op) {
41+
oppositeOperators(op, _) and
42+
// We check the template, not its instantiations
43+
not c instanceof ClassTemplateInstantiation and
44+
// Member functions of templates are not necessarily instantiated, so
45+
// if the function we want to check exists, then make sure that its
46+
// body also exists
47+
((c instanceof TemplateClass)
48+
implies
49+
forall(Function f | f = c.getAMember() and f.hasName(op)
50+
| exists(f.getEntryPoint())))
2951
}
3052

3153
from Class c, string op, string opp, Operator rator
3254
where c.fromSource() and
3355
oppositeOperators(op, opp) and
56+
classIsCheckableFor(c, op) and
57+
classIsCheckableFor(c, opp) and
3458
rator = c.getAMember() and
3559
rator.hasName(op) and
36-
not exists(Operator oprator | oprator = c.getAMember() and
37-
oprator.hasName(opp) and
38-
( implementedAsNegationOf(rator, oprator)
39-
or implementedAsNegationOf(oprator, rator)))
60+
forex(Operator aRator |
61+
aRator = c.getAMember() and aRator.hasName(op) |
62+
not exists(Operator oprator |
63+
oprator = c.getAMember() and
64+
oprator.hasName(opp) and
65+
( implementedAsNegationOf(aRator, oprator)
66+
or implementedAsNegationOf(oprator, aRator))))
4067
select c, "When two operators are opposites, both should be defined and one should be defined in terms of the other. Operator " + op +
4168
" is declared on line " + rator.getLocation().getStartLine().toString() + ", but it is not defined in terms of its opposite operator " + opp + "."

cpp/ql/src/jsf/4.13 Functions/AV Rule 111.qhelp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@
55

66

77
<overview>
8+
9+
<!-- Mention that this rule may not be applicable in projects that don't follow the JSF standard. -->
10+
<include src="cpp/jsfNote.qhelp" />
11+
812
<p>
9-
This rule finds return statements that return pointers to an object allocated on the stack. The lifetime
13+
This query highlights return statements that return pointers to an object allocated on the stack. The lifetime
1014
of a stack allocated memory location only lasts until the function returns, , and
1115
the contents of that memory become undefined after that. Clearly, using a pointer to stack
1216
memory after the function has already returned will have undefined results.

cpp/ql/src/jsf/4.15 Declarations and Definitions/AV Rule 135.qhelp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@
55

66

77
<overview>
8+
9+
<!-- Mention that this rule may not be applicable in projects that don't follow the JSF standard. -->
10+
<include src="cpp/jsfNote.qhelp" />
11+
812
<p>
9-
This rule finds identifiers in an inner scope that hide (have the same name as) an identifier in an outer scope.
13+
This query highlights identifiers in an inner scope that hide (have the same name as) an identifier in an outer scope.
1014
This should be avoided as it can cause confusion about the actual variable being used in an expression.
1115
</p>
1216

cpp/ql/src/jsf/4.15 Declarations and Definitions/AV Rule 140.qhelp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@
55

66

77
<overview>
8+
9+
<!-- Mention that this rule may not be applicable in projects that don't follow the JSF standard. -->
10+
<include src="cpp/jsfNote.qhelp" />
11+
812
<p>
9-
This rule finds variables with the <code>register</code> storage class specifier. Modern compilers are now capable of
13+
This query highlights variables with the <code>register</code> storage class specifier. Modern compilers are now capable of
1014
optimal register placement, and overriding it could lead to worse performance.
1115
</p>
1216

cpp/ql/src/jsf/4.17 Types/AV Rule 147.qhelp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@
55

66

77
<overview>
8+
9+
<!-- Mention that this rule may not be applicable in projects that don't follow the JSF standard. -->
10+
<include src="cpp/jsfNote.qhelp" />
11+
812
<p>
9-
This rule finds portions of code that can expose the floating point implementation of the underlying
13+
This query highlights portions of code that can expose the floating point implementation of the underlying
1014
machine. Manually manipulating the bits in the float is prone to mistakes and is unportable. Floating point
1115
implementations can vary across architectures, and bit-field packing can differ across compilers,
1216
making manual bit-manipulation of floats inadvisable.

cpp/ql/src/jsf/4.18 Constants/AV Rule 151.1.qhelp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@
55

66

77
<overview>
8+
9+
<!-- Mention that this rule may not be applicable in projects that don't follow the JSF standard. -->
10+
<include src="cpp/jsfNote.qhelp" />
11+
812
<p>
9-
This rule finds string literals that are assigned to a non-<code>const</code> variable. String literals
13+
This query highlights string literals that are assigned to a non-<code>const</code> variable. String literals
1014
should not be changed, since they are usually stored in the data section, and depending on the architecture,
1115
writing to the data section will cause undefined behavior, such as memory corruption or memory write error.
1216
</p>

0 commit comments

Comments
 (0)