Skip to content

Commit 44cdbeb

Browse files
author
Nikita Kraiouchkine
committed
Add documentation to DoNotAddOrSubtractAScaledIntegerToAPointer.ql
Add
1 parent 5d79dd5 commit 44cdbeb

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

c/cert/src/rules/ARR39-C/DoNotAddOrSubtractAScaledIntegerToAPointer.ql

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,18 @@ abstract class PointerArithmeticExpr extends Expr {
2525
abstract Expr getOperand();
2626
}
2727

28+
/**
29+
* A pointer arithmetic binary operation expression.
30+
*/
2831
class SimplePointerArithmeticExpr extends PointerArithmeticExpr, PointerArithmeticOperation {
2932
override Expr getPointer() { result = this.getLeftOperand() }
3033

3134
override Expr getOperand() { result = this.getRightOperand() }
3235
}
3336

37+
/**
38+
* A pointer arithmetic assignment expression.
39+
*/
3440
class AssignPointerArithmeticExpr extends PointerArithmeticExpr, AssignOperation {
3541
AssignPointerArithmeticExpr() {
3642
this instanceof AssignPointerAddExpr or
@@ -42,12 +48,18 @@ class AssignPointerArithmeticExpr extends PointerArithmeticExpr, AssignOperation
4248
override Expr getOperand() { result = this.getRValue() }
4349
}
4450

51+
/**
52+
* A pointer arithmetic array access expression.
53+
*/
4554
class ArrayPointerArithmeticExpr extends PointerArithmeticExpr, ArrayExpr {
4655
override Expr getPointer() { result = this.getArrayBase() }
4756

4857
override Expr getOperand() { result = this.getArrayOffset() }
4958
}
5059

60+
/**
61+
* An expression which invokes the `offsetof` macro or `__builtin_offsetof` operation.
62+
*/
5163
class OffsetOfExpr extends Expr {
5264
OffsetOfExpr() {
5365
this instanceof BuiltInOperationBuiltInOffsetOf
@@ -57,7 +69,7 @@ class OffsetOfExpr extends Expr {
5769
}
5870

5971
/**
60-
* An array expression conforming to the "arr[ sizeof(arr)/sizeof(arr[ 0 ]) ]" idiom
72+
* An array expression conforming to the `arr[sizeof(arr)/sizeof(arr[0])]` idiom.
6173
*/
6274
class ArrayCountOfExpr extends ArrayExpr {
6375
ArrayCountOfExpr() {
@@ -77,6 +89,9 @@ class ArrayCountOfExpr extends ArrayExpr {
7789
}
7890
}
7991

92+
/**
93+
* An `offsetof` expression or a `sizeof` expression with an operand of a size greater than 1.
94+
*/
8095
class ScaledIntegerExpr extends Expr {
8196
ScaledIntegerExpr() {
8297
not this.getParent*() instanceof ArrayCountOfExpr and
@@ -90,6 +105,10 @@ class ScaledIntegerExpr extends Expr {
90105
}
91106
}
92107

108+
/**
109+
* A data-flow configuration modeling data-flow from a `ScaledIntegerExpr` to a
110+
* `PointerArithmeticExpr` where the pointer does not point to a 1-byte type.
111+
*/
93112
class ScaledIntegerPointerArithmeticConfig extends DataFlow::Configuration {
94113
ScaledIntegerPointerArithmeticConfig() { this = "ScaledIntegerPointerArithmeticConfig" }
95114

0 commit comments

Comments
 (0)