Skip to content

s/getFieldExpr/getAFieldExpr and s/getElementExpr/getAnElementExpr #290

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ from AggregateLiteral initList, SideEffect effect
where
not isExcluded(initList, SideEffects1Package::initializerListsContainPersistentSideEffectsQuery()) and
(
initList.(ArrayOrVectorAggregateLiteral).getElementExpr(_) = effect
initList.(ArrayOrVectorAggregateLiteral).getAnElementExpr(_) = effect
or
initList.(ClassAggregateLiteral).getFieldExpr(_) = effect
initList.(ClassAggregateLiteral).getAFieldExpr(_) = effect
)
select initList, "Initializer list constains persistent $@", effect, "side effect"
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class ArrayParameter extends Parameter {
* int arr2[2] = {1, 2, 3};
* ```
*/
int countElements(ArrayAggregateLiteral l) { result = count(l.getElementExpr(_)) }
int countElements(ArrayAggregateLiteral l) { result = count(l.getAnElementExpr(_)) }

class SmallArrayConfig extends DataFlow::Configuration {
SmallArrayConfig() { this = "SmallArrayConfig" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class NullTerminatedStringToMemcmpConfiguration extends TaintTracking::Configura
// The array element type is an essentially character type
getEssentialTypeCategory(aal.getElementType()) = EssentiallyCharacterType() and
// Includes a null terminator somewhere in the array initializer
aal.getElementExpr(_).getValue().toInt() = 0
aal.getAnElementExpr(_).getValue().toInt() = 0
|
// For local variables, use the array aggregate literal as the source
aal = source.asExpr()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ string getNestedArrayIndexString(Expr e) {
any(int elementIndex |
exists(ArrayAggregateLiteral parent |
parent = getNthParent(e, pragma[only_bind_into](depth + 1)) and
parent.getElementExpr(elementIndex) = getNthParent(e, pragma[only_bind_into](depth))
parent.getAnElementExpr(elementIndex) = getNthParent(e, pragma[only_bind_into](depth))
)
|
elementIndex
Expand All @@ -54,9 +54,9 @@ string getNestedArrayIndexString(Expr e) {
*/
language[monotonicAggregates]
int getMaxDepth(ArrayAggregateLiteral al) {
if not exists(al.getElementExpr(_).(ArrayAggregateLiteral))
if not exists(al.getAnElementExpr(_).(ArrayAggregateLiteral))
then result = 0
else result = 1 + max(Expr child | child = al.getElementExpr(_) | getMaxDepth(child))
else result = 1 + max(Expr child | child = al.getAnElementExpr(_) | getMaxDepth(child))
}

// internal recursive predicate for `hasMultipleInitializerExprsForSameIndex`
Expand All @@ -66,8 +66,8 @@ predicate hasMultipleInitializerExprsForSameIndexInternal(
exists(int shared_index, Expr al1_expr, Expr al2_expr |
// an `Expr` initializing an element of the same index in both `al1` and `al2`
shared_index = [0 .. al1.getArraySize() - 1] and
al1_expr = al1.getElementExpr(shared_index) and
al2_expr = al2.getElementExpr(shared_index) and
al1_expr = al1.getAnElementExpr(shared_index) and
al2_expr = al2.getAnElementExpr(shared_index) and
// but not the same `Expr`
not al1_expr = al2_expr and
(
Expand Down Expand Up @@ -98,7 +98,7 @@ predicate hasMultipleInitializerExprsForSameIndex(ArrayAggregateLiteral root, Ex
* This predicate is therefore unable to distinguish the individual duplicate expressions.
*/
predicate hasMultipleInitializerExprsForSameField(ClassAggregateLiteral root, Field f) {
count(root.getFieldExpr(f)) > 1
count(root.getAFieldExpr(f)) > 1
}

from
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ where
// Macro expansions are morally excluded
not l = any(MacroInvocation mi).getAnExpandedElement() and
// Aggregate literal
not l = any(ArrayOrVectorAggregateLiteral aal).getElementExpr(_).getAChild*() and
not l = any(ArrayOrVectorAggregateLiteral aal).getAnElementExpr(_).getAChild*() and
// Ignore x - 1 expressions
not exists(SubExpr se | se.getRightOperand() = l and l.getValue() = "1")
select l,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ where
//also not having a nonconst member accessed through the param
notUsedAsQualifierForNonConst(p) and
not exists(ClassAggregateLiteral l, Field f |
DataFlow::localExprFlow(p.getAnAccess(), l.getFieldExpr(f)) and
DataFlow::localExprFlow(p.getAnAccess(), l.getAFieldExpr(f)) and
not f.isConst()
) and
// Exclude parameters that are used to initialize member fields.
Expand Down