Skip to content

Commit f0f7528

Browse files
committed
Merge remote-tracking branch 'upstream/master' into dbartol/Indirections
Conflicts: cpp/ql/src/semmle/code/cpp/ir/implementation/aliased_ssa/internal/AliasedSSA.qll csharp/ql/src/semmle/code/csharp/ir/implementation/unaliased_ssa/internal/AliasAnalysis.qll
2 parents 790cbf0 + c4d2163 commit f0f7528

File tree

365 files changed

+2195
-1531
lines changed

Some content is hidden

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

365 files changed

+2195
-1531
lines changed

cpp/ql/src/Architecture/FeatureEnvy.ql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ predicate functionUsesFunction(Function source, Function f, File target) {
2525
}
2626

2727
predicate dependencyCount(Function source, File target, int res) {
28-
res = strictcount(Declaration d |
28+
res =
29+
strictcount(Declaration d |
2930
functionUsesVariable(source, d, target) or
3031
functionUsesFunction(source, d, target)
3132
)

cpp/ql/src/Architecture/General Top-Level Information/GeneralStatistics.ql

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,16 @@ where
3838
n = count(Function f | f.fromSource()).toString()
3939
or
4040
l = "Number of Lines Of Code" and
41-
n = sum(File f, int toSum |
41+
n =
42+
sum(File f, int toSum |
4243
f.fromSource() and toSum = f.getMetrics().getNumberOfLinesOfCode()
4344
|
4445
toSum
4546
).toString()
4647
or
4748
l = "Self-Containedness" and
48-
n = (
49+
n =
50+
(
4951
100 * sum(Class c | c.fromSource() | c.getMetrics().getEfferentSourceCoupling()) /
5052
sum(Class c | c.fromSource() | c.getMetrics().getEfferentCoupling())
5153
).toString() + "%"

cpp/ql/src/Architecture/Refactoring Opportunities/ClassesWithManyFields.ql

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,8 @@ class VariableDeclarationLine extends TVariableDeclarationInfo {
8080
* (that is, the first is 0, the second is 1 and so on).
8181
*/
8282
private int getRank() {
83-
line = rank[result](VariableDeclarationLine vdl, int l |
84-
vdl = TVariableDeclarationLine(c, f, l)
85-
|
86-
l
87-
)
83+
line =
84+
rank[result](VariableDeclarationLine vdl, int l | vdl = TVariableDeclarationLine(c, f, l) | l)
8885
}
8986

9087
/**
@@ -133,7 +130,8 @@ class VariableDeclarationGroup extends VariableDeclarationLine {
133130
* Gets the number of uniquely named `VariableDeclarationEntry`s in this group.
134131
*/
135132
int getCount() {
136-
result = count(VariableDeclarationLine l |
133+
result =
134+
count(VariableDeclarationLine l |
137135
l = getProximateNext*()
138136
|
139137
l.getAVDE().getVariable().getName()
@@ -166,7 +164,8 @@ class ExtClass extends Class {
166164

167165
from ExtClass c, int n, VariableDeclarationGroup vdg, string suffix
168166
where
169-
n = strictcount(string fieldName |
167+
n =
168+
strictcount(string fieldName |
170169
exists(Field f |
171170
f.getDeclaringType() = c and
172171
fieldName = f.getName() and

cpp/ql/src/Best Practices/Likely Errors/EmptyBlock.ql

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,21 +50,24 @@ class BlockOrNonChild extends Element {
5050

5151
private int getNonContiguousStartRankIn(AffectedFile file) {
5252
// When using `rank` with `order by`, the ranks may not be contiguous.
53-
this = rank[result](BlockOrNonChild boc, int startLine, int startCol |
53+
this =
54+
rank[result](BlockOrNonChild boc, int startLine, int startCol |
5455
boc.getLocation().hasLocationInfo(file.getAbsolutePath(), startLine, startCol, _, _)
5556
|
5657
boc order by startLine, startCol
5758
)
5859
}
5960

6061
int getStartRankIn(AffectedFile file) {
61-
this.getNonContiguousStartRankIn(file) = rank[result](int rnk |
62+
this.getNonContiguousStartRankIn(file) =
63+
rank[result](int rnk |
6264
exists(BlockOrNonChild boc | boc.getNonContiguousStartRankIn(file) = rnk)
6365
)
6466
}
6567

6668
int getNonContiguousEndRankIn(AffectedFile file) {
67-
this = rank[result](BlockOrNonChild boc, int endLine, int endCol |
69+
this =
70+
rank[result](BlockOrNonChild boc, int endLine, int endCol |
6871
boc.getLocation().hasLocationInfo(file.getAbsolutePath(), _, _, endLine, endCol)
6972
|
7073
boc order by endLine, endCol
@@ -79,9 +82,8 @@ predicate emptyBlockContainsNonchild(Block b) {
7982
emptyBlock(_, b) and
8083
exists(BlockOrNonChild c, AffectedFile file |
8184
c.(BlockOrNonChild).getStartRankIn(file) = 1 + b.(BlockOrNonChild).getStartRankIn(file) and
82-
c.(BlockOrNonChild).getNonContiguousEndRankIn(file) < b
83-
.(BlockOrNonChild)
84-
.getNonContiguousEndRankIn(file)
85+
c.(BlockOrNonChild).getNonContiguousEndRankIn(file) <
86+
b.(BlockOrNonChild).getNonContiguousEndRankIn(file)
8587
)
8688
}
8789

cpp/ql/src/Best Practices/Magic Constants/MagicConstants.qll

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,8 @@ predicate nonTrivialValue(string value, Literal literal) {
307307
}
308308

309309
predicate valueOccurrenceCount(string value, int n) {
310-
n = strictcount(Location loc |
310+
n =
311+
strictcount(Location loc |
311312
exists(Literal lit | lit.getLocation() = loc | nonTrivialValue(value, lit)) and
312313
// Exclude generated files (they do not have the same maintainability
313314
// concerns as ordinary source files)
@@ -338,7 +339,8 @@ predicate check(Literal lit, string value, int n, File f) {
338339
}
339340

340341
predicate checkWithFileCount(string value, int overallCount, int fileCount, File f) {
341-
fileCount = strictcount(Location loc |
342+
fileCount =
343+
strictcount(Location loc |
342344
exists(Literal lit | lit.getLocation() = loc | check(lit, value, overallCount, f))
343345
)
344346
}
@@ -364,7 +366,8 @@ predicate firstOccurrence(Literal lit, string value, int n) {
364366
predicate magicConstant(Literal e, string msg) {
365367
exists(string value, int n |
366368
firstOccurrence(e, value, n) and
367-
msg = "Magic constant: literal '" + value + "' is repeated " + n.toString() +
369+
msg =
370+
"Magic constant: literal '" + value + "' is repeated " + n.toString() +
368371
" times and should be encapsulated in a constant."
369372
)
370373
}

cpp/ql/src/Best Practices/RuleOfTwo.ql

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,15 @@ import cpp
2828
// design question and carries has no safety risk.
2929
predicate generatedCopyAssignment(CopyConstructor cc, string msg) {
3030
cc.getDeclaringType().hasImplicitCopyAssignmentOperator() and
31-
msg = "No matching copy assignment operator in class " + cc.getDeclaringType().getName() +
31+
msg =
32+
"No matching copy assignment operator in class " + cc.getDeclaringType().getName() +
3233
". It is good practice to match a copy constructor with a " + "copy assignment operator."
3334
}
3435

3536
predicate generatedCopyConstructor(CopyAssignmentOperator ca, string msg) {
3637
ca.getDeclaringType().hasImplicitCopyConstructor() and
37-
msg = "No matching copy constructor in class " + ca.getDeclaringType().getName() +
38+
msg =
39+
"No matching copy constructor in class " + ca.getDeclaringType().getName() +
3840
". It is good practice to match a copy assignment operator with a " + "copy constructor."
3941
}
4042

cpp/ql/src/Critical/OverflowCalculated.ql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ predicate spaceProblem(FunctionCall append, string msg) {
3333
malloc.getASuccessor+() = insert and
3434
insert.getArgument(1) = buffer.getAnAccess() and
3535
insert.getASuccessor+() = append and
36-
msg = "This buffer only contains enough room for '" + buffer.getName() + "' (copied on line " +
36+
msg =
37+
"This buffer only contains enough room for '" + buffer.getName() + "' (copied on line " +
3738
insert.getLocation().getStartLine().toString() + ")"
3839
)
3940
}

cpp/ql/src/Critical/OverflowStatic.ql

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ predicate overflowOffsetInLoop(BufferAccess bufaccess, string msg) {
5151
loop.getStmt().getAChild*() = bufaccess.getEnclosingStmt() and
5252
loop.limit() >= bufaccess.bufferSize() and
5353
loop.counter().getAnAccess() = bufaccess.getArrayOffset() and
54-
msg = "Potential buffer-overflow: counter '" + loop.counter().toString() + "' <= " +
54+
msg =
55+
"Potential buffer-overflow: counter '" + loop.counter().toString() + "' <= " +
5556
loop.limit().toString() + " but '" + bufaccess.buffer().getName() + "' has " +
5657
bufaccess.bufferSize().toString() + " elements."
5758
)
@@ -106,8 +107,9 @@ predicate wrongBufferSize(Expr error, string msg) {
106107
statedSize = min(call.statedSizeValue()) and
107108
statedSize > bufsize and
108109
error = call.statedSizeExpr() and
109-
msg = "Potential buffer-overflow: '" + buf.getName() + "' has size " + bufsize.toString() +
110-
" not " + statedSize + "."
110+
msg =
111+
"Potential buffer-overflow: '" + buf.getName() + "' has size " + bufsize.toString() + " not " +
112+
statedSize + "."
111113
)
112114
}
113115

@@ -121,8 +123,9 @@ predicate outOfBounds(BufferAccess bufaccess, string msg) {
121123
or
122124
access = size and not exists(AddressOfExpr addof | bufaccess = addof.getOperand())
123125
) and
124-
msg = "Potential buffer-overflow: '" + buf + "' has size " + size.toString() + " but '" + buf +
125-
"[" + access.toString() + "]' is accessed here."
126+
msg =
127+
"Potential buffer-overflow: '" + buf + "' has size " + size.toString() + " but '" + buf + "[" +
128+
access.toString() + "]' is accessed here."
126129
)
127130
}
128131

cpp/ql/src/Critical/ReturnValueIgnored.ql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ predicate important(Function f, string message) {
2323
predicate dubious(Function f, string message) {
2424
not important(f, _) and
2525
exists(Options opts, int used, int total, int percentage |
26-
used = count(FunctionCall fc |
26+
used =
27+
count(FunctionCall fc |
2728
fc.getTarget() = f and not opts.okToIgnoreReturnValue(fc) and not unused(fc)
2829
) and
2930
total = count(FunctionCall fc | fc.getTarget() = f and not opts.okToIgnoreReturnValue(fc)) and

cpp/ql/src/Documentation/CaptionedComments.qll

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,13 @@ string getCommentTextCaptioned(Comment c, string caption) {
1818
dontCare = commentBody.regexpFind("\\n[/* \\t\\x0B\\f\\r]*" + caption, _, offset) and
1919
interestingSuffix = commentBody.suffix(offset) and
2020
endOfLine = interestingSuffix.indexOf("\n", 1, 0) and
21-
captionedLine = interestingSuffix
21+
captionedLine =
22+
interestingSuffix
2223
.prefix(endOfLine)
2324
.regexpReplaceAll("^[/*\\s]*" + caption + "\\s*:?", "")
2425
.trim() and
25-
followingLine = interestingSuffix
26-
.prefix(interestingSuffix.indexOf("\n", 2, 0))
27-
.suffix(endOfLine)
28-
.trim() and
26+
followingLine =
27+
interestingSuffix.prefix(interestingSuffix.indexOf("\n", 2, 0)).suffix(endOfLine).trim() and
2928
if captionedLine = ""
3029
then result = caption + " comment"
3130
else

0 commit comments

Comments
 (0)