Skip to content

Commit

Permalink
Share PointerOrArrayType
Browse files Browse the repository at this point in the history
  • Loading branch information
lcartey committed Oct 22, 2024
1 parent 8e830bc commit 4b9d813
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
20 changes: 3 additions & 17 deletions c/common/src/codingstandards/c/UndefinedBehavior.qll
Original file line number Diff line number Diff line change
@@ -1,26 +1,12 @@
import cpp
import codingstandards.cpp.Pointers
import codingstandards.cpp.UndefinedBehavior

/**
* Library for modeling undefined behavior.
*/
abstract class CUndefinedBehavior extends UndefinedBehavior { }

class PointerOrArrayType extends DerivedType {
PointerOrArrayType() {
this instanceof PointerType or
this instanceof ArrayType
}
}

Type get(Function main) {
main.getName() = "main" and
main.getNumberOfParameters() = 2 and
main.getType().getUnderlyingType() instanceof IntType and
main.getParameter(0).getType().getUnderlyingType() instanceof IntType and
result = main.getParameter(1).getType().getUnderlyingType().(PointerOrArrayType).getBaseType()
}

/**
* A function which has the signature - but not the name - of a main function.
*/
Expand All @@ -32,9 +18,9 @@ class C99MainFunction extends Function {
this.getParameter(1)
.getType()
.getUnderlyingType()
.(PointerOrArrayType)
.(UnspecifiedPointerOrArrayType)
.getBaseType()
.(PointerOrArrayType)
.(UnspecifiedPointerOrArrayType)
.getBaseType() instanceof CharType
or
this.getNumberOfParameters() = 0 and
Expand Down
12 changes: 11 additions & 1 deletion cpp/common/src/codingstandards/cpp/Pointers.qll
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import cpp
import codingstandards.cpp.Type

/**
* A type that is a pointer or array type.
* A type that is a pointer or array type after stripping top-level specifiers.
*/
class PointerOrArrayType extends DerivedType {
PointerOrArrayType() {
Expand All @@ -15,6 +15,16 @@ class PointerOrArrayType extends DerivedType {
}
}

/**
* A type that is a pointer or array type.
*/
class UnspecifiedPointerOrArrayType extends DerivedType {
UnspecifiedPointerOrArrayType() {
this instanceof PointerType or
this instanceof ArrayType
}
}

/**
* An expression which performs pointer arithmetic
*/
Expand Down

0 comments on commit 4b9d813

Please sign in to comment.