Skip to content

Commit d39bdf4

Browse files
authored
Merge pull request #94 from knewbury01/knewbury01/Declarations3
Package Declarations3
2 parents 5053722 + a6f54c4 commit d39bdf4

Some content is hidden

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

43 files changed

+554
-28
lines changed

c/cert/src/rules/DCL31-C/DeclareIdentifiersBeforeUsingThem.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ Search for [vulnerabilities](https://wiki.sei.cmu.edu/confluence/display/c/BB.+D
153153

154154
## Implementation notes
155155

156-
This query does not check for implicit function declarations as this is partially compiler checked.
156+
This query does not check for implicitly typed parameters, typedefs or member declarations as this is partially compiler checked.
157157

158158
## References
159159

c/cert/src/rules/DCL31-C/DeclareIdentifiersBeforeUsingThem.ql

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,10 @@
1313

1414
import cpp
1515
import codingstandards.c.cert
16+
import codingstandards.cpp.rules.typeomitted.TypeOmitted
1617

17-
from Declaration d
18-
where
19-
not isExcluded(d, Declarations1Package::declareIdentifiersBeforeUsingThemQuery()) and
20-
d.hasSpecifier("implicit_int") and
21-
exists(Type t |
22-
(d.(Variable).getType() = t or d.(Function).getType() = t) and
23-
// Exclude "short" or "long", as opposed to "short int" or "long int".
24-
t instanceof IntType and
25-
// Exclude "signed" or "unsigned", as opposed to "signed int" or "unsigned int".
26-
not exists(IntegralType it | it = t | it.isExplicitlySigned() or it.isExplicitlyUnsigned())
27-
)
28-
select d, "Declaration " + d.getName() + " is missing a type specifier."
18+
class DeclareIdentifiersBeforeUsingThem extends TypeOmittedSharedQuery {
19+
DeclareIdentifiersBeforeUsingThem() {
20+
this = Declarations1Package::declareIdentifiersBeforeUsingThemQuery()
21+
}
22+
}

c/cert/test/rules/DCL31-C/DeclareIdentifiersBeforeUsingThem.qlref

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
c/common/test/rules/typeomitted/TypeOmitted.ql
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import cpp
2+
3+
//Identifiers that are candidates for checking uniqueness
4+
class InterestingIdentifiers extends Declaration {
5+
InterestingIdentifiers() {
6+
not this.isFromTemplateInstantiation(_) and
7+
not this.isFromUninstantiatedTemplate(_) and
8+
not this instanceof TemplateParameter and
9+
not this.hasDeclaringType() and
10+
not this instanceof Operator and
11+
not this.hasName("main") and
12+
exists(this.getADeclarationLocation())
13+
}
14+
15+
string getSignificantName() { result = this.getName().prefix(31) }
16+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
| test.c:4:7:4:9 | id1 | Variable is hiding variable $@. | test.c:1:5:1:7 | id1 | id1 |
2+
| test.c:7:13:7:15 | id1 | Variable is hiding variable $@. | test.c:1:5:1:7 | id1 | id1 |
3+
| test.c:10:12:10:14 | id1 | Variable is hiding variable $@. | test.c:1:5:1:7 | id1 | id1 |
4+
| test.c:11:14:11:16 | id1 | Variable is hiding variable $@. | test.c:10:12:10:14 | id1 | id1 |
5+
| test.c:24:24:24:26 | id2 | Variable is hiding variable $@. | test.c:22:5:22:7 | id2 | id2 |
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// GENERATED FILE - DO NOT MODIFY
2+
import codingstandards.cpp.rules.identifierhidden.IdentifierHidden
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
int id1;
2+
3+
void f1() {
4+
int id1; // NON_COMPLIANT
5+
}
6+
7+
void f2(int id1) {} // NON_COMPLIANT
8+
9+
void f3() {
10+
for (int id1; id1 < 1; id1++) { // NON_COMPLIANT
11+
for (int id1; id1 < 1; id1++) {
12+
} // NON_COMPLIANT
13+
}
14+
}
15+
16+
struct astruct {
17+
int id1;
18+
};
19+
20+
extern void g(struct astruct *p);
21+
22+
int id2 = 0;
23+
24+
void f4(struct astruct id2) { // NON_COMPLIANT
25+
g(&id2);
26+
}
27+
28+
void f5(struct astruct id3) { // COMPLIANT
29+
g(&id2);
30+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// GENERATED FILE - DO NOT MODIFY
2+
import codingstandards.cpp.rules.typeomitted.TypeOmitted

0 commit comments

Comments
 (0)