Skip to content

Commit e8cb6b5

Browse files
committed
Clean up logic in ArrayDeclaration
1 parent ebd1e58 commit e8cb6b5

1 file changed

Lines changed: 4 additions & 8 deletions

File tree

cpp/misra/src/rules/RULE-8-7-1/PointerArithmeticFormsAnInvalidPointer.ql

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,12 @@ import semmle.code.cpp.security.BufferAccess
2323
* A declaration of a variable that is of an array type.
2424
*/
2525
class ArrayDeclaration extends VariableDeclarationEntry {
26-
int length;
27-
28-
ArrayDeclaration() { this.getType().getUnderlyingType().(ArrayType).getArraySize() = length }
26+
ArrayDeclaration() { this.getType().getUnderlyingType() instanceof ArrayType }
2927

3028
/**
31-
* Gets the declared length of this array.
29+
* Gets the declared length of this array at the given level of indirection.
3230
*/
33-
int getLength() { result = length }
34-
35-
int getLength(int indirection) { result = getArrayType(indirection).getArraySize() }
31+
int getLength(int indirection) { result = this.getArrayType(indirection).getArraySize() }
3632

3733
private ArrayType getArrayType(int indirection) {
3834
indirection = 0 and result = this.getType().getUnderlyingType()
@@ -168,7 +164,7 @@ class ArrayAllocation extends TArrayAllocation {
168164
)
169165
or
170166
node.asUninitialized() = this.asStackAllocation().getVariable() and
171-
result = this.asStackAllocation().getLength()
167+
result = this.asStackAllocation().getLength(0)
172168
or
173169
node.asConvertedExpr() = this.asDynamicAllocation() and
174170
result = this.asDynamicAllocation().getMinNumElements()

0 commit comments

Comments
 (0)