Skip to content

Commit 260897d

Browse files
authored
Merge pull request #290 from MathiasVP/use-getanelement-and-getafield
s/`getFieldExpr`/`getAFieldExpr` and s/`getElementExpr`/`getAnElementExpr`
2 parents 281782e + 4020ec0 commit 260897d

File tree

6 files changed

+12
-12
lines changed

6 files changed

+12
-12
lines changed

c/misra/src/rules/RULE-13-1/InitializerListsContainPersistentSideEffects.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ from AggregateLiteral initList, SideEffect effect
2525
where
2626
not isExcluded(initList, SideEffects1Package::initializerListsContainPersistentSideEffectsQuery()) and
2727
(
28-
initList.(ArrayOrVectorAggregateLiteral).getElementExpr(_) = effect
28+
initList.(ArrayOrVectorAggregateLiteral).getAnElementExpr(_) = effect
2929
or
30-
initList.(ClassAggregateLiteral).getFieldExpr(_) = effect
30+
initList.(ClassAggregateLiteral).getAFieldExpr(_) = effect
3131
)
3232
select initList, "Initializer list constains persistent $@", effect, "side effect"

c/misra/src/rules/RULE-17-5/ArrayFunctionArgumentNumberOfElements.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class ArrayParameter extends Parameter {
4242
* int arr2[2] = {1, 2, 3};
4343
* ```
4444
*/
45-
int countElements(ArrayAggregateLiteral l) { result = count(l.getElementExpr(_)) }
45+
int countElements(ArrayAggregateLiteral l) { result = count(l.getAnElementExpr(_)) }
4646

4747
class SmallArrayConfig extends DataFlow::Configuration {
4848
SmallArrayConfig() { this = "SmallArrayConfig" }

c/misra/src/rules/RULE-21-14/MemcmpUsedToCompareNullTerminatedStrings.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class NullTerminatedStringToMemcmpConfiguration extends TaintTracking::Configura
3030
// The array element type is an essentially character type
3131
getEssentialTypeCategory(aal.getElementType()) = EssentiallyCharacterType() and
3232
// Includes a null terminator somewhere in the array initializer
33-
aal.getElementExpr(_).getValue().toInt() = 0
33+
aal.getAnElementExpr(_).getValue().toInt() = 0
3434
|
3535
// For local variables, use the array aggregate literal as the source
3636
aal = source.asExpr()

c/misra/src/rules/RULE-9-4/RepeatedInitializationOfAggregateObjectElement.ql

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ string getNestedArrayIndexString(Expr e) {
3838
any(int elementIndex |
3939
exists(ArrayAggregateLiteral parent |
4040
parent = getNthParent(e, pragma[only_bind_into](depth + 1)) and
41-
parent.getElementExpr(elementIndex) = getNthParent(e, pragma[only_bind_into](depth))
41+
parent.getAnElementExpr(elementIndex) = getNthParent(e, pragma[only_bind_into](depth))
4242
)
4343
|
4444
elementIndex
@@ -54,9 +54,9 @@ string getNestedArrayIndexString(Expr e) {
5454
*/
5555
language[monotonicAggregates]
5656
int getMaxDepth(ArrayAggregateLiteral al) {
57-
if not exists(al.getElementExpr(_).(ArrayAggregateLiteral))
57+
if not exists(al.getAnElementExpr(_).(ArrayAggregateLiteral))
5858
then result = 0
59-
else result = 1 + max(Expr child | child = al.getElementExpr(_) | getMaxDepth(child))
59+
else result = 1 + max(Expr child | child = al.getAnElementExpr(_) | getMaxDepth(child))
6060
}
6161

6262
// internal recursive predicate for `hasMultipleInitializerExprsForSameIndex`
@@ -66,8 +66,8 @@ predicate hasMultipleInitializerExprsForSameIndexInternal(
6666
exists(int shared_index, Expr al1_expr, Expr al2_expr |
6767
// an `Expr` initializing an element of the same index in both `al1` and `al2`
6868
shared_index = [0 .. al1.getArraySize() - 1] and
69-
al1_expr = al1.getElementExpr(shared_index) and
70-
al2_expr = al2.getElementExpr(shared_index) and
69+
al1_expr = al1.getAnElementExpr(shared_index) and
70+
al2_expr = al2.getAnElementExpr(shared_index) and
7171
// but not the same `Expr`
7272
not al1_expr = al2_expr and
7373
(
@@ -98,7 +98,7 @@ predicate hasMultipleInitializerExprsForSameIndex(ArrayAggregateLiteral root, Ex
9898
* This predicate is therefore unable to distinguish the individual duplicate expressions.
9999
*/
100100
predicate hasMultipleInitializerExprsForSameField(ClassAggregateLiteral root, Field f) {
101-
count(root.getFieldExpr(f)) > 1
101+
count(root.getAFieldExpr(f)) > 1
102102
}
103103

104104
from

cpp/autosar/src/rules/A5-1-1/LiteralValueUsedOutsideTypeInit.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ where
4343
// Macro expansions are morally excluded
4444
not l = any(MacroInvocation mi).getAnExpandedElement() and
4545
// Aggregate literal
46-
not l = any(ArrayOrVectorAggregateLiteral aal).getElementExpr(_).getAChild*() and
46+
not l = any(ArrayOrVectorAggregateLiteral aal).getAnElementExpr(_).getAChild*() and
4747
// Ignore x - 1 expressions
4848
not exists(SubExpr se | se.getRightOperand() = l and l.getValue() = "1")
4949
select l,

cpp/autosar/src/rules/A8-4-9/InOutParametersDeclaredAsTNotModified.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ where
6060
//also not having a nonconst member accessed through the param
6161
notUsedAsQualifierForNonConst(p) and
6262
not exists(ClassAggregateLiteral l, Field f |
63-
DataFlow::localExprFlow(p.getAnAccess(), l.getFieldExpr(f)) and
63+
DataFlow::localExprFlow(p.getAnAccess(), l.getAFieldExpr(f)) and
6464
not f.isConst()
6565
) and
6666
// Exclude parameters that are used to initialize member fields.

0 commit comments

Comments
 (0)