Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c872576

Browse files
committed
C++: Fixes from Geoffrey's review round 2
1 parent 64e2277 commit c872576

16 files changed

Lines changed: 98 additions & 92 deletions

File tree

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,12 @@ predicate oppositeOperators(string op1, string op2) {
1717
or oppositeOperators(op2, op1)
1818
}
1919

20-
// whether op1 is implemented as the negation of op2
21-
/* this match is very syntactic: we simply check that op1 is defined as
22-
!op2(_, _) */
20+
/**
21+
* Holds if `op1` is implemented as the negation of `op2`.
22+
*
23+
* This match is very syntactic: we simply check that `op1` is defined as
24+
* `!op2(_, _)`.
25+
*/
2326
predicate implementedAsNegationOf(Operator op1, Operator op2) {
2427
exists(Block b, ReturnStmt r, NotExpr n, Expr o |
2528
b = op1.getBlock() and

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,17 @@
1111
*/
1212
import cpp
1313

14-
/*
15-
In the context of this rule, an interface is specified by a class which has the following properties:
16-
- it is intended to be an interface,
17-
- its public methods are pure virtual functions, and
18-
- it does not hold any data, unless those data items are small and function as part of the interface (e.g. a unique object identifier).
19-
20-
An approximation of this definition is classes with pure virtual functions and less than 3 member variables.
21-
*/
14+
/**
15+
* In the context of this rule, an interface is specified by a class which has
16+
* the following properties:
17+
* - it is intended to be an interface,
18+
* - its public methods are pure virtual functions, and
19+
* - it does not hold any data, unless those data items are small and function
20+
* as part of the interface (e.g. a unique object identifier).
21+
*
22+
* An approximation of this definition is classes with pure virtual functions
23+
* and less than 3 member variables.
24+
*/
2225
class InterfaceClass extends Class {
2326
InterfaceClass() {
2427
exists(MemberFunction m | m.getDeclaringType() = this and not compgenerated(unresolveElement(m)))

cpp/ql/src/jsf/4.13 Functions/AV Rule 114.ql

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
import cpp
1414

1515
/* This is slightly subtle: The extractor adds a dummy 'return;' statement for control paths
16-
that fall off the end of a function. So we can simply look for non-void functions containing
17-
a non-value carrying return. If the predecessor is a return statement it means that
18-
the return did not return a value. (If that return was not added by the extractor but by the
19-
programmer, we can flag it anyway, since this is arguably a bug.) */
16+
* that fall off the end of a function. So we can simply look for non-void functions containing
17+
* a non-value carrying return. If the predecessor is a return statement it means that
18+
* the return did not return a value. (If that return was not added by the extractor but by the
19+
* programmer, we can flag it anyway, since this is arguably a bug.) */
2020

2121
predicate functionsMissingReturnStmt(Function f, ControlFlowNode blame) {
2222
f.fromSource() and
@@ -31,10 +31,10 @@ predicate functionsMissingReturnStmt(Function f, ControlFlowNode blame) {
3131
)
3232
}
3333

34-
/* If a function has a value-carrying return statement, but the extractor hit a snag
35-
whilst parsing the value, then the control flow graph will not include the value.
36-
As such, to avoid embarrassing false positives, we exclude any function which
37-
wasn't perfectly extracted. */
34+
/** If a function has a value-carrying return statement, but the extractor hit a snag
35+
* whilst parsing the value, then the control flow graph will not include the value.
36+
* As such, to avoid embarrassing false positives, we exclude any function which
37+
* wasn't perfectly extracted. */
3838
predicate functionImperfectlyExtracted(Function f) {
3939
exists(CompilerError e | f.getBlock().getLocation().subsumes(e.getLocation()))
4040
or

cpp/ql/src/semmle/code/cpp/Compilation.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import semmle.code.cpp.File
22

3-
/**
3+
/*
44
* These two helper predicates are used to associate a unique integer with
55
* each `@compilation`, for use in the `toString` method of `Compilation`.
66
* These integers are not stable across trap imports, but stable across

cpp/ql/src/semmle/code/cpp/Print.qll

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,12 @@ private class DumpType extends Type
7373
* This operation is very expensive, and should not be used in production queries.
7474
*/
7575
final string getTypeIdentityString() {
76-
/*
77-
The identity string of a type is just the concatenation of the four components below. To create the type
78-
identity for a derived type, insert the declarator of the derived type between the `getDeclaratorPrefix()` and
79-
`getDeclaratorSuffixBeforeQualifiers()`. To create the type identity for a `SpecifiedType`, insert the qualifiers
80-
after `getDeclaratorSuffixBeforeQualifiers()`.
81-
*/
76+
// The identity string of a type is just the concatenation of the four
77+
// components below. To create the type identity for a derived type, insert
78+
// the declarator of the derived type between the `getDeclaratorPrefix()`
79+
// and `getDeclaratorSuffixBeforeQualifiers()`. To create the type identity
80+
// for a `SpecifiedType`, insert the qualifiers after
81+
// `getDeclaratorSuffixBeforeQualifiers()`.
8282
result = getTypeSpecifier() + getDeclaratorPrefix() + getDeclaratorSuffixBeforeQualifiers() + getDeclaratorSuffix()
8383
}
8484

cpp/ql/src/semmle/code/cpp/PrintAST.qll

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,12 @@ class PrintASTNode extends TPrintASTNode {
155155
/**
156156
* Retrieves the canonical QL class(es) for entity `el`
157157
*/
158-
private string qlClass(ElementBase el) { result = "[" + concat(el.getCanonicalQLClass(), ",") + "] " }
158+
private string qlClass(ElementBase el) {
159+
result = "[" + concat(el.getCanonicalQLClass(), ",") + "] "
160+
// Alternative implementation -- do not delete. It is useful for QL class discovery.
161+
//result = "["+ concat(el.getAQlClass(), ",") + "] "
162+
}
159163

160-
// Do not delete this - it is useful for QL class discovery
161-
//private string qlClass(ElementBase el) { result = "["+ concat(el.getAQlClass(), ",") + "] " }
162164

163165
/**
164166
* A node representing an AST node.

cpp/ql/src/semmle/code/cpp/Type.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -969,9 +969,9 @@ class SpecifiedType extends DerivedType {
969969
result = this.getBaseType().getPointerIndirectionLevel()
970970
}
971971

972-
/** all the specifiers of this type as a string in a fixed order (the order
973-
only depends on the specifiers, not on the source program). This is intended
974-
for debugging queries only and is an expensive operation. */
972+
/** Gets all the specifiers of this type as a string in a fixed order (the order
973+
* only depends on the specifiers, not on the source program). This is intended
974+
* for debugging queries only and is an expensive operation. */
975975
string getSpecifierString() {
976976
internalSpecString(this, result, 1)
977977
}

cpp/ql/src/semmle/code/cpp/UserType.qll

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,11 @@ class UserType extends Type, Declaration, NameQualifyingElement, AccessHolder, @
8585
exists(getEnclosingFunction())
8686
}
8787

88-
// Dummy implementations of inherited methods. This class must not be
89-
// made abstract, because it is important that it captures the @usertype
90-
// type exactly - but this is not apparent from its subclasses
88+
/*
89+
* Dummy implementations of inherited methods. This class must not be
90+
* made abstract, because it is important that it captures the @usertype
91+
* type exactly - but this is not apparent from its subclasses
92+
*/
9193

9294
Declaration getADeclaration() { none() }
9395

cpp/ql/src/semmle/code/cpp/commons/Assertions.qll

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,3 @@ class RecoverableAssert extends MacroInvocation, Assertion {
6969
not result.(Literal).getUnspecifiedType().(ArrayType).getBaseType() instanceof CharType
7070
}
7171
}
72-
73-
/*
74-
* More assertion definitions go here.
75-
*/

cpp/ql/src/semmle/code/cpp/commons/Dependency.qll

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,9 @@ cached predicate getDeclarationEntries(Declaration decl, DeclarationEntry de)
105105
decl.(Function).isConstructedFrom(de.getDeclaration()) or
106106
decl.(Class).isConstructedFrom(de.getDeclaration())
107107
) and
108-
/*
109-
* ParameterDeclarationEntries are special, as (a) they can only be accessed
110-
* from within the definition, and (b) non-definition PDEs may be commonly
111-
* included. Thus, for PDEs, we point only to the definition.
112-
*/
108+
// ParameterDeclarationEntries are special, as (a) they can only be accessed
109+
// from within the definition, and (b) non-definition PDEs may be commonly
110+
// included. Thus, for PDEs, we point only to the definition.
113111
(de instanceof ParameterDeclarationEntry implies de.isDefinition())
114112
}
115113

0 commit comments

Comments
 (0)