Skip to content

Commit 6a1fa99

Browse files
Code format & package description fixes
1 parent 503830a commit 6a1fa99

File tree

10 files changed

+49
-77
lines changed

10 files changed

+49
-77
lines changed

c/common/test/library/identifierlinkage/identifierlinkage.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,4 @@ struct s {
2525
};
2626

2727
// Enums and enum constants are not variables and have no linkage.
28-
enum e {
29-
E1
30-
};
28+
enum e { E1 };

c/misra/src/rules/RULE-22-14/MutexInitializedInsideThread.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @id c/misra/mutex-initialized-inside-thread
33
* @name RULE-22-14: Thread synchronization objects shall be initialized deterministically
44
* @description Mutex and condition objects initialized inside of threads may result in
5-
* indeterministic state
5+
* indeterministic state.
66
* @kind problem
77
* @precision high
88
* @problem.severity recommendation

c/misra/test/rules/RULE-22-13/test.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ void f1(void) {
4747
has_ptr_mtx_t l12; // COMPLIANT
4848
has_mtx_t l13[10]; // NON-COMPLIANT
4949

50-
l10 = &g1; // COMPLIANT
51-
l10 = malloc(sizeof(mtx_t)); // NON-COMPLIANT
50+
l10 = &g1; // COMPLIANT
51+
l10 = malloc(sizeof(mtx_t)); // NON-COMPLIANT
5252
l10 = malloc(sizeof(mtx_t) * 4); // NON-COMPLIANT
5353
}

c/misra/test/rules/RULE-22-16/test.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ void f6(int p) {
4141
goto skipped;
4242
}
4343
mtx_unlock(&m);
44-
skipped:
44+
skipped:
4545
}
4646

4747
void f7(int p) {
@@ -84,24 +84,24 @@ void f13() {
8484
mtx_t m;
8585
} s;
8686
mtx_lock(&s.m); // COMPLIANT
87-
mtx_unlock(&s.m);
87+
mtx_unlock(&s.m);
8888
}
8989

9090
void f14() {
91-
for(;;) {
91+
for (;;) {
9292
mtx_t m;
9393
mtx_lock(&m); // COMPLIANT
94-
mtx_unlock(&m);
94+
mtx_unlock(&m);
9595
}
9696
}
9797

9898
void f15(int p) {
99-
for(;;) {
99+
for (;;) {
100100
mtx_t m;
101101
mtx_lock(&m); // NON-COMPLIANT
102102
if (p) {
103103
break;
104104
}
105-
mtx_unlock(&m);
105+
mtx_unlock(&m);
106106
}
107107
}

cpp/common/src/codingstandards/cpp/Concurrency.qll

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -70,27 +70,19 @@ class C11ThreadCreateCall extends ThreadCreationFunction {
7070
}
7171

7272
class C11MutexType extends TypedefType {
73-
C11MutexType() {
74-
this.hasName("mtx_t")
75-
}
73+
C11MutexType() { this.hasName("mtx_t") }
7674
}
7775

7876
class C11ThreadType extends TypedefType {
79-
C11ThreadType() {
80-
this.hasName("thrd_t")
81-
}
77+
C11ThreadType() { this.hasName("thrd_t") }
8278
}
8379

8480
class C11ConditionType extends TypedefType {
85-
C11ConditionType() {
86-
this.hasName("cnd_t")
87-
}
81+
C11ConditionType() { this.hasName("cnd_t") }
8882
}
8983

9084
class C11ThreadStorageType extends TypedefType {
91-
C11ThreadStorageType() {
92-
this.hasName("tss_t")
93-
}
85+
C11ThreadStorageType() { this.hasName("tss_t") }
9486
}
9587

9688
class C11ThreadingObjectType extends TypedefType {
@@ -100,7 +92,7 @@ class C11ThreadingObjectType extends TypedefType {
10092
this instanceof C11ThreadType
10193
or
10294
this instanceof C11ConditionType
103-
or
95+
or
10496
this instanceof C11ThreadStorageType
10597
}
10698
}
@@ -506,13 +498,9 @@ class CConditionOperation extends FunctionCall {
506498
getTarget().hasName(["cnd_broadcast", "cnd_signal", "cnd_timedwait", "cnd_wait", "cnd_init"])
507499
}
508500

509-
predicate isInit() {
510-
getTarget().hasName("cnd_init")
511-
}
501+
predicate isInit() { getTarget().hasName("cnd_init") }
512502

513-
predicate isUse() {
514-
not isInit()
515-
}
503+
predicate isUse() { not isInit() }
516504

517505
Expr getConditionExpr() { result = getArgument(0) }
518506

cpp/common/src/codingstandards/cpp/Type.qll

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,21 +64,21 @@ signature class PossiblySpecifiedBaseType extends Type;
6464

6565
/**
6666
* This module defines a class `Type` which holds for types `T` and `const/volatile T` etc.
67-
*
67+
*
6868
* Similar to `getUnspecifiedType()`, but does not resolve typedefs. Useful for matching
6969
* potentially qualified versions of standard typedef types, such as `const mtx_t`.
70-
*
70+
*
7171
* Example usage: `someType.(PossiblySpecified<PointerType>::Type).strip()`
7272
*/
7373
module PossiblySpecified<PossiblySpecifiedBaseType BaseType> {
7474
import cpp as cpp
75+
7576
final class CppType = cpp::Type;
7677

7778
class Type extends CppType {
7879
BaseType baseType;
79-
Type() {
80-
baseType = stripSpecifiers(this)
81-
}
80+
81+
Type() { baseType = stripSpecifiers(this) }
8282

8383
BaseType strip() { result = baseType }
8484
}
@@ -93,4 +93,4 @@ int getPrecision(IntegralType type) {
9393
type.isExplicitlyUnsigned() and result = type.getSize() * 8
9494
or
9595
type.isExplicitlySigned() and result = type.getSize() * 8 - 1
96-
}
96+
}

cpp/common/src/codingstandards/cpp/resources/ResourceLeakAnalysis.qll

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,32 @@ import codeql.util.Boolean
66

77
/**
88
* A library for detecting leaked resources.
9-
*
9+
*
1010
* To use this library, implement `ResourceLeakConfigSig`:
11-
*
11+
*
1212
* ```
1313
* class UnjoinedThreadConfig implements ResourceLeakConfigSig {
1414
* predicate isResource(DataFlow::Node node) {
1515
* node.asExpr().isThreadCreate()
1616
* }
17-
*
17+
*
1818
* predicate isFree(ControlFlowNode node, DataFlow::Node resource) {
1919
* node.asExpr().isThreadJoin(resource.asExpr())
2020
* }
2121
* }
2222
* ```
23-
*
23+
*
2424
* You can now check if a resource is leaked through the module predicate
2525
* `ResourceLeak<UnjoinedThreadConfig>::isLeaked(resource)`.
26-
*
26+
*
2727
* The leak analysis finds the exit point of the function in which the resource is is declared, and
2828
* then reverses execution from there using `getAPredecessor()`. When this backwards walk discovers
2929
* a control flow node that frees the resource, that exploration stops. If any exploration reaches
3030
* a resource, that resource may be leaked via that path.
31-
*
31+
*
3232
* Uses `DataFlow::Node` in order to track aliases of the resource to better detect when the
3333
* resource is freed.
34-
*
34+
*
3535
* This library by default assumes that resources are expression nodes. To use it with other kinds
3636
* of nodes requires overriding `resourceInitPoint`.
3737
*/
@@ -41,7 +41,8 @@ signature module ResourceLeakConfigSig {
4141
predicate isFree(ControlFlowNode node, DataFlow::Node resource);
4242

4343
default DataFlow::Node getAnAlias(DataFlow::Node node) {
44-
DataFlow::localFlow(node, result) or
44+
DataFlow::localFlow(node, result)
45+
or
4546
exists(Expr current, Expr after |
4647
current in [node.asExpr(), node.asDefiningArgument()] and
4748
after in [result.asExpr(), result.asDefiningArgument()] and
@@ -57,9 +58,10 @@ signature module ResourceLeakConfigSig {
5758
}
5859

5960
module ResourceLeak<ResourceLeakConfigSig Config> {
60-
private newtype TResource = TJustResource(DataFlow::Node resource, ControlFlowNode cfgNode) {
61-
Config::isAllocate(cfgNode, resource)
62-
}
61+
private newtype TResource =
62+
TJustResource(DataFlow::Node resource, ControlFlowNode cfgNode) {
63+
Config::isAllocate(cfgNode, resource)
64+
}
6365

6466
/**
6567
* Get an alias of a resource, and aliases of nodes that are aliased by a resource.
@@ -98,4 +100,4 @@ module ResourceLeak<ResourceLeakConfigSig Config> {
98100
isLeakedAtControlPoint(resourceWrapper, result)
99101
)
100102
}
101-
}
103+
}

cpp/common/src/codingstandards/cpp/resources/ResourceManagement.qll

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ module ResourceLeakConfig implements ResourceLeakConfigSig {
1111
)
1212
or
1313
exists(FunctionCall f |
14-
f.getTarget().hasQualifiedName("std", "basic_fstream", "open")
15-
and allocPoint = f
16-
and node.asDefiningArgument() = f.getQualifier()
14+
f.getTarget().hasQualifiedName("std", "basic_fstream", "open") and
15+
allocPoint = f and
16+
node.asDefiningArgument() = f.getQualifier()
1717
)
1818
or
1919
exists(FunctionCall f |
@@ -24,22 +24,22 @@ module ResourceLeakConfig implements ResourceLeakConfigSig {
2424
}
2525

2626
predicate isFree(ControlFlowNode node, DataFlow::Node resource) {
27-
exists(DeallocationExpr d, Expr freedExpr|
27+
exists(DeallocationExpr d, Expr freedExpr |
2828
freedExpr = d.getFreedExpr() and
2929
node = d and
3030
resource.asExpr() = freedExpr
3131
)
3232
or
3333
exists(FunctionCall f |
34-
f.getTarget().hasQualifiedName("std", "basic_fstream", "close")
35-
and node = f and
34+
f.getTarget().hasQualifiedName("std", "basic_fstream", "close") and
35+
node = f and
3636
resource.asExpr() = f.getQualifier()
3737
)
3838
or
3939
exists(FunctionCall f |
40-
f.getTarget().hasQualifiedName("std", "mutex", "unlock")
41-
and node = f and
40+
f.getTarget().hasQualifiedName("std", "mutex", "unlock") and
41+
node = f and
4242
resource.asExpr() = f.getQualifier()
4343
)
4444
}
45-
}
45+
}

cpp/common/src/codingstandards/cpp/rules/exceptionsafetyvalidstate/ExceptionSafetyValidState.qll

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ abstract class ExceptionSafetyValidStateSharedQuery extends Query { }
1515

1616
Query getQuery() { result instanceof ExceptionSafetyValidStateSharedQuery }
1717

18-
1918
/**
2019
* `UncaughtThrowExpr` models a `throw` expression that is not handled
2120
*/
@@ -24,38 +23,23 @@ class UncaughtThrowExpr extends ThrowExpr {
2423
}
2524

2625
module ThrowLeakConfig implements ResourceLeakConfigSig {
27-
2826
predicate isAllocate(ControlFlowNode node, DataFlow::Node resource) {
29-
//exists(ResourceAcquisitionExpr rae |
30-
// node = rae and resource.asExpr() = rae
31-
//)
3227
ResourceLeakConfig::isAllocate(node, resource)
3328
}
3429

3530
predicate isFree(ControlFlowNode node, DataFlow::Node resource) {
36-
//exists(ResourceAcquisitionExpr rae |
37-
// node = rae.getReleaseExpr() and resource.asExpr() = rae
38-
//)
3931
ResourceLeakConfig::isFree(node, resource)
4032
}
4133

4234
ControlFlowNode outOfScope(ControlFlowNode allocPoint) {
4335
result.(UncaughtThrowExpr).getEnclosingFunction() = allocPoint.(Expr).getEnclosingFunction()
4436
}
4537

46-
DataFlow::Node getAnAlias(DataFlow::Node node) {
47-
DataFlow::localFlow(node, result)
48-
}
38+
DataFlow::Node getAnAlias(DataFlow::Node node) { DataFlow::localFlow(node, result) }
4939
}
5040

51-
query predicate problems(
52-
UncaughtThrowExpr te, string message, Element e, string eDescription
53-
) {
41+
query predicate problems(UncaughtThrowExpr te, string message, Element e, string eDescription) {
5442
not isExcluded(te, getQuery()) and
55-
//exists(SubBasicBlock sbb |
56-
// sbb.getANode() = e and
57-
// te = followsInitialized(sbb)
58-
//) and
5943
te = ResourceLeak<ThrowLeakConfig>::getALeak(e) and
6044
message = "The $@ is not released explicitly before throwing an exception." and
6145
eDescription = "allocated resource"

rule_packages/c/Concurrency8.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
]
6262
},
6363
{
64-
"description": "Mutex and condition objects initialized inside of threads may result in indeterministic state",
64+
"description": "Mutex and condition objects initialized inside of threads may result in indeterministic state.",
6565
"kind": "problem",
6666
"name": "Thread synchronization objects shall be initialized deterministically",
6767
"precision": "high",

0 commit comments

Comments
 (0)