Skip to content

Commit 4b9d813

Browse files
committed
Share PointerOrArrayType
1 parent 8e830bc commit 4b9d813

File tree

2 files changed

+14
-18
lines changed

2 files changed

+14
-18
lines changed

c/common/src/codingstandards/c/UndefinedBehavior.qll

+3-17
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,12 @@
11
import cpp
2+
import codingstandards.cpp.Pointers
23
import codingstandards.cpp.UndefinedBehavior
34

45
/**
56
* Library for modeling undefined behavior.
67
*/
78
abstract class CUndefinedBehavior extends UndefinedBehavior { }
89

9-
class PointerOrArrayType extends DerivedType {
10-
PointerOrArrayType() {
11-
this instanceof PointerType or
12-
this instanceof ArrayType
13-
}
14-
}
15-
16-
Type get(Function main) {
17-
main.getName() = "main" and
18-
main.getNumberOfParameters() = 2 and
19-
main.getType().getUnderlyingType() instanceof IntType and
20-
main.getParameter(0).getType().getUnderlyingType() instanceof IntType and
21-
result = main.getParameter(1).getType().getUnderlyingType().(PointerOrArrayType).getBaseType()
22-
}
23-
2410
/**
2511
* A function which has the signature - but not the name - of a main function.
2612
*/
@@ -32,9 +18,9 @@ class C99MainFunction extends Function {
3218
this.getParameter(1)
3319
.getType()
3420
.getUnderlyingType()
35-
.(PointerOrArrayType)
21+
.(UnspecifiedPointerOrArrayType)
3622
.getBaseType()
37-
.(PointerOrArrayType)
23+
.(UnspecifiedPointerOrArrayType)
3824
.getBaseType() instanceof CharType
3925
or
4026
this.getNumberOfParameters() = 0 and

cpp/common/src/codingstandards/cpp/Pointers.qll

+11-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import cpp
66
import codingstandards.cpp.Type
77

88
/**
9-
* A type that is a pointer or array type.
9+
* A type that is a pointer or array type after stripping top-level specifiers.
1010
*/
1111
class PointerOrArrayType extends DerivedType {
1212
PointerOrArrayType() {
@@ -15,6 +15,16 @@ class PointerOrArrayType extends DerivedType {
1515
}
1616
}
1717

18+
/**
19+
* A type that is a pointer or array type.
20+
*/
21+
class UnspecifiedPointerOrArrayType extends DerivedType {
22+
UnspecifiedPointerOrArrayType() {
23+
this instanceof PointerType or
24+
this instanceof ArrayType
25+
}
26+
}
27+
1828
/**
1929
* An expression which performs pointer arithmetic
2030
*/

0 commit comments

Comments
 (0)