Skip to content

Commit 4283a15

Browse files
authored
Merge pull request #1870 from jbj/autoformat-all
C++: Autoformat everything
2 parents bdba647 + 4ef5c9a commit 4283a15

File tree

1,143 files changed

+22528
-23536
lines changed

Some content is hidden

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

1,143 files changed

+22528
-23536
lines changed

cpp/ql/src/AlertSuppression.ql

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,64 +16,56 @@ class SuppressionComment extends CppStyleComment {
1616

1717
SuppressionComment() {
1818
text = getContents().suffix(2) and
19-
( // match `lgtm[...]` anywhere in the comment
19+
(
20+
// match `lgtm[...]` anywhere in the comment
2021
annotation = text.regexpFind("(?i)\\blgtm\\s*\\[[^\\]]*\\]", _, _)
2122
or
2223
// match `lgtm` at the start of the comment and after semicolon
23-
annotation = text.regexpFind("(?i)(?<=^|;)\\s*lgtm(?!\\B|\\s*\\[)", _, _)
24-
.trim()
24+
annotation = text.regexpFind("(?i)(?<=^|;)\\s*lgtm(?!\\B|\\s*\\[)", _, _).trim()
2525
)
2626
}
2727

28-
2928
/** Gets the text in this comment, excluding the leading //. */
30-
string getText() {
31-
result = text
32-
}
29+
string getText() { result = text }
3330

3431
/** Gets the suppression annotation in this comment. */
35-
string getAnnotation() {
36-
result = annotation
37-
}
32+
string getAnnotation() { result = annotation }
3833

3934
/**
40-
* Holds if this comment applies to the range from column `startcolumn` of line `startline`
41-
* to column `endcolumn` of line `endline` in file `filepath`.
42-
*/
35+
* Holds if this comment applies to the range from column `startcolumn` of line `startline`
36+
* to column `endcolumn` of line `endline` in file `filepath`.
37+
*/
4338
predicate covers(string filepath, int startline, int startcolumn, int endline, int endcolumn) {
4439
this.getLocation().hasLocationInfo(filepath, startline, _, endline, endcolumn) and
4540
startcolumn = 1
4641
}
4742

4843
/** Gets the scope of this suppression. */
49-
SuppressionScope getScope() {
50-
result = this
51-
}
44+
SuppressionScope getScope() { result = this }
5245
}
5346

5447
/**
5548
* The scope of an alert suppression comment.
5649
*/
5750
class SuppressionScope extends ElementBase {
58-
SuppressionScope() {
59-
this instanceof SuppressionComment
60-
}
51+
SuppressionScope() { this instanceof SuppressionComment }
6152

6253
/**
63-
* Holds if this element is at the specified location.
64-
* The location spans column `startcolumn` of line `startline` to
65-
* column `endcolumn` of line `endline` in file `filepath`.
66-
* For more information, see
67-
* [Locations](https://help.semmle.com/QL/learn-ql/ql/locations.html).
68-
*/
69-
predicate hasLocationInfo(string filepath, int startline, int startcolumn, int endline, int endcolumn) {
54+
* Holds if this element is at the specified location.
55+
* The location spans column `startcolumn` of line `startline` to
56+
* column `endcolumn` of line `endline` in file `filepath`.
57+
* For more information, see
58+
* [Locations](https://help.semmle.com/QL/learn-ql/ql/locations.html).
59+
*/
60+
predicate hasLocationInfo(
61+
string filepath, int startline, int startcolumn, int endline, int endcolumn
62+
) {
7063
this.(SuppressionComment).covers(filepath, startline, startcolumn, endline, endcolumn)
7164
}
7265
}
7366

7467
from SuppressionComment c
75-
select c, // suppression comment
76-
c.getText(), // text of suppression comment (excluding delimiters)
77-
c.getAnnotation(), // text of suppression annotation
78-
c.getScope() // scope of suppression
79-
68+
select c, // suppression comment
69+
c.getText(), // text of suppression comment (excluding delimiters)
70+
c.getAnnotation(), // text of suppression annotation
71+
c.getScope() // scope of suppression

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@ newtype TVariableDeclarationInfo =
4242
*/
4343
class VariableDeclarationLine extends TVariableDeclarationInfo {
4444
Class c;
45-
4645
File f;
47-
4846
int line;
4947

5048
VariableDeclarationLine() {

cpp/ql/src/Best Practices/Magic Constants/JapaneseEraDate.ql

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ predicate eraDate(int year, int month, int day) {
4242
year = 2019 and month = 5 and day = 1
4343
}
4444

45-
4645
predicate badStructInitialization(Element target, string message) {
4746
exists(
4847
StructLikeClass s, YearFieldAccess year, MonthFieldAccess month, DayFieldAccess day,

cpp/ql/src/Best Practices/Unused Entities/UnusedStaticVariables.ql

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@
1414
import cpp
1515

1616
predicate declarationHasSideEffects(Variable v) {
17-
exists(Class c | c = v.getUnspecifiedType() |
18-
c.hasConstructor() or c.hasDestructor()
19-
)
17+
exists(Class c | c = v.getUnspecifiedType() | c.hasConstructor() or c.hasDestructor())
2018
}
2119

2220
from Variable v

cpp/ql/src/Critical/FileMayNotBeClosed.ql

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,18 @@ class MinusOne extends NullValue {
2626
*/
2727
predicate mayCallFunction(Expr call, Function f) {
2828
call.(FunctionCall).getTarget() = f or
29-
call.(VariableCall).getVariable().getAnAssignedValue().
30-
getAChild*().(FunctionAccess).getTarget() = f
29+
call.(VariableCall).getVariable().getAnAssignedValue().getAChild*().(FunctionAccess).getTarget() =
30+
f
3131
}
3232

3333
predicate fopenCallOrIndirect(Expr e) {
3434
// direct fopen call
3535
fopenCall(e) and
36-
3736
// We are only interested in fopen calls that are
3837
// actually closed somehow, as FileNeverClosed
3938
// will catch those that aren't.
4039
fopenCallMayBeClosed(e)
4140
or
42-
4341
exists(ReturnStmt rtn |
4442
// indirect fopen call
4543
mayCallFunction(e, rtn.getEnclosingFunction()) and
@@ -86,7 +84,6 @@ class FOpenVariableReachability extends LocalScopeVariableReachabilityWithReassi
8684
exists(node.(AnalysedExpr).getNullSuccessor(v)) or
8785
fcloseCallOrIndirect(node, v) or
8886
assignedToFieldOrGlobal(v, node) or
89-
9087
// node may be used directly in query
9188
v.getFunction() = node.(ReturnStmt).getEnclosingFunction()
9289
}
@@ -122,12 +119,10 @@ class FOpenReachability extends LocalScopeVariableReachabilityExt {
122119
}
123120

124121
override predicate isBarrier(
125-
ControlFlowNode source, ControlFlowNode node, ControlFlowNode next,
126-
LocalScopeVariable v)
127-
{
122+
ControlFlowNode source, ControlFlowNode node, ControlFlowNode next, LocalScopeVariable v
123+
) {
128124
isSource(source, v) and
129125
next = node.getASuccessor() and
130-
131126
// the file (stored in any variable `v0`) opened at `source` is closed or
132127
// assigned to a global at node, or NULL checked on the edge node -> next.
133128
exists(LocalScopeVariable v0 | fopenVariableReaches(v0, source, node) |
@@ -172,6 +167,4 @@ where
172167
fopenVariableReaches(v, def, ret) and
173168
ret.getAChild*() = v.getAnAccess()
174169
)
175-
select
176-
def, "The file opened here may not be closed at $@.",
177-
ret, "this exit point"
170+
select def, "The file opened here may not be closed at $@.", ret, "this exit point"

cpp/ql/src/Critical/MemoryMayNotBeFreed.ql

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,18 @@ import semmle.code.cpp.controlflow.LocalScopeVariableReachability
1818
*/
1919
predicate mayCallFunction(Expr call, Function f) {
2020
call.(FunctionCall).getTarget() = f or
21-
call.(VariableCall).getVariable().getAnAssignedValue().
22-
getAChild*().(FunctionAccess).getTarget() = f
21+
call.(VariableCall).getVariable().getAnAssignedValue().getAChild*().(FunctionAccess).getTarget() =
22+
f
2323
}
2424

2525
predicate allocCallOrIndirect(Expr e) {
2626
// direct alloc call
2727
isAllocationExpr(e) and
28-
2928
// We are only interested in alloc calls that are
3029
// actually freed somehow, as MemoryNeverFreed
3130
// will catch those that aren't.
3231
allocMayBeFreed(e)
3332
or
34-
3533
exists(ReturnStmt rtn |
3634
// indirect alloc call
3735
mayCallFunction(e, rtn.getEnclosingFunction()) and
@@ -64,7 +62,6 @@ predicate verifiedRealloc(FunctionCall reallocCall, Variable v, ControlFlowNode
6462
newV.getAnAssignedValue() = reallocCall and
6563
node.(AnalysedExpr).getNonNullSuccessor(newV) = verified and
6664
// note: this case uses naive flow logic (getAnAssignedValue).
67-
6865
// special case: if the result of the 'realloc' is assigned to the
6966
// same variable, we don't descriminate properly between the old
7067
// and the new allocation; better to not consider this a free at
@@ -116,7 +113,6 @@ class AllocVariableReachability extends LocalScopeVariableReachabilityWithReassi
116113
exists(node.(AnalysedExpr).getNullSuccessor(v)) or
117114
freeCallOrIndirect(node, v) or
118115
assignedToFieldOrGlobal(v, node) or
119-
120116
// node may be used directly in query
121117
v.getFunction() = node.(ReturnStmt).getEnclosingFunction()
122118
}
@@ -152,12 +148,10 @@ class AllocReachability extends LocalScopeVariableReachabilityExt {
152148
}
153149

154150
override predicate isBarrier(
155-
ControlFlowNode source, ControlFlowNode node, ControlFlowNode next,
156-
LocalScopeVariable v)
157-
{
151+
ControlFlowNode source, ControlFlowNode node, ControlFlowNode next, LocalScopeVariable v
152+
) {
158153
isSource(source, v) and
159154
next = node.getASuccessor() and
160-
161155
// the memory (stored in any variable `v0`) allocated at `source` is freed or
162156
// assigned to a global at node, or NULL checked on the edge node -> next.
163157
exists(LocalScopeVariable v0 | allocatedVariableReaches(v0, source, node) |
@@ -202,6 +196,4 @@ where
202196
allocatedVariableReaches(v, def, ret) and
203197
ret.getAChild*() = v.getAnAccess()
204198
)
205-
select
206-
def, "The memory allocated here may not be released at $@.",
207-
ret, "this exit point"
199+
select def, "The memory allocated here may not be released at $@.", ret, "this exit point"

cpp/ql/src/Critical/NotInitialised.ql

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
* external/cwe/cwe-457
99
*/
1010

11-
import cpp
11+
/*
12+
* See also InitialisationNotRun.ql and GlobalUseBeforeInit.ql
13+
*/
1214

13-
// See also InitialisationNotRun.ql and GlobalUseBeforeInit.ql
15+
import cpp
1416

1517
/**
1618
* Holds if `s` defines variable `v` (conservative).

cpp/ql/src/Critical/OverflowDestination.ql

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,10 @@ predicate sourceSized(FunctionCall fc, Expr src) {
3333
fc.getArgument(2) = size and
3434
src = v.getAnAccess() and
3535
size.getAChild+() = v.getAnAccess() and
36-
3736
// exception: `dest` is also referenced in the size argument
3837
not exists(Variable other |
3938
dest = other.getAnAccess() and size.getAChild+() = other.getAnAccess()
4039
) and
41-
4240
// exception: `src` and `dest` are both arrays of the same type and size
4341
not exists(ArrayType srctype, ArrayType desttype |
4442
dest.getType().getUnderlyingType() = desttype and

cpp/ql/src/Critical/OverflowStatic.ql

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ class BufferAccess extends ArrayExpr {
3333
staticBuffer(this.getArrayBase(), _, size) and
3434
size != 0
3535
) and
36-
3736
// exclude accesses in macro implementation of `strcmp`,
3837
// which are carefully controlled but can look dangerous.
3938
not exists(Macro m |

cpp/ql/src/DefaultOptions.qll

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,11 @@ private import Options as CustomOptions
1313

1414
/**
1515
* Default predicates that specify information about the behavior of
16-
* the program being analyzed.
16+
* the program being analyzed.
1717
*/
18-
class Options extends string
19-
{
20-
Options() {
21-
this = "Options"
22-
}
23-
18+
class Options extends string {
19+
Options() { this = "Options" }
20+
2421
/**
2522
* Holds if we wish to override the "may return NULL" inference for this
2623
* call. If this holds, then rather than trying to infer whether this
@@ -60,15 +57,17 @@ class Options extends string
6057
* `noreturn` attribute.
6158
*/
6259
predicate exits(Function f) {
63-
f.getAnAttribute().hasName("noreturn") or
60+
f.getAnAttribute().hasName("noreturn")
61+
or
6462
exists(string name | f.hasGlobalName(name) |
6563
name = "exit" or
6664
name = "_exit" or
6765
name = "abort" or
6866
name = "__assert_fail" or
6967
name = "longjmp" or
7068
name = "__builtin_unreachable"
71-
) or
69+
)
70+
or
7271
CustomOptions::exits(f) // old Options.qll
7372
}
7473

@@ -108,14 +107,11 @@ class Options extends string
108107
fc.isInMacroExpansion()
109108
or
110109
// common way of sleeping using select:
111-
(fc.getTarget().hasGlobalName("select") and
112-
fc.getArgument(0).getValue() = "0")
110+
fc.getTarget().hasGlobalName("select") and
111+
fc.getArgument(0).getValue() = "0"
113112
or
114113
CustomOptions::okToIgnoreReturnValue(fc) // old Options.qll
115114
}
116115
}
117116

118-
Options getOptions()
119-
{
120-
any()
121-
}
117+
Options getOptions() { any() }

0 commit comments

Comments
 (0)