Skip to content

Commit d0842fc

Browse files
committed
Java/C++/C#: Minor refactor following review comment.
1 parent 379ef1d commit d0842fc

File tree

23 files changed

+200
-188
lines changed

23 files changed

+200
-188
lines changed

cpp/ql/src/semmle/code/cpp/dataflow/internal/DataFlowImpl.qll

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ private predicate nodeCandFwd1(Node node, Configuration config) {
317317
exists(DataFlowCall call, ReturnNodeExt ret, ReturnKindExt kind |
318318
nodeCandFwd1(ret, config) and
319319
getReturnPosition(ret) = viableReturnPos(call, kind) and
320-
node = getAnOutNodeExt(call, kind)
320+
node = kind.getAnOutNode(call)
321321
)
322322
)
323323
}
@@ -409,7 +409,7 @@ private predicate nodeCand1ReturnPosition(ReturnPosition pos, Configuration conf
409409
exists(DataFlowCall call, ReturnKindExt kind, Node out |
410410
nodeCand1(out, config) and
411411
pos = viableReturnPos(call, kind) and
412-
out = getAnOutNodeExt(call, kind)
412+
out = kind.getAnOutNode(call)
413413
)
414414
}
415415

@@ -576,7 +576,7 @@ private predicate flowOutOfCallable(Node node1, Node node2, Configuration config
576576
not inBarrier(node2, config) and
577577
exists(DataFlowCall call, ReturnKindExt kind |
578578
getReturnPosition1(node1, unbind(config)) = viableReturnPos(call, kind) and
579-
node2 = getAnOutNodeExt(call, kind)
579+
node2 = kind.getAnOutNode(call)
580580
)
581581
}
582582

@@ -1806,7 +1806,7 @@ private predicate pathOutOfCallable1(
18061806
pragma[noinline]
18071807
private predicate pathOutOfCallable(PathNodeMid mid, Node out, CallContext cc) {
18081808
exists(ReturnKindExt kind, DataFlowCall call | pathOutOfCallable1(mid, call, kind, cc) |
1809-
out = getAnOutNodeExt(call, kind)
1809+
out = kind.getAnOutNode(call)
18101810
)
18111811
}
18121812

@@ -1905,7 +1905,7 @@ pragma[noinline]
19051905
private predicate pathThroughCallable(PathNodeMid mid, Node out, CallContext cc, AccessPathNil apnil) {
19061906
exists(DataFlowCall call, ReturnKindExt kind |
19071907
pathThroughCallable0(call, mid, kind, cc, apnil) and
1908-
out = getAnOutNodeExt(call, kind)
1908+
out = kind.getAnOutNode(call)
19091909
)
19101910
}
19111911

@@ -1965,7 +1965,7 @@ private module FlowExploration {
19651965
// flow out of a callable
19661966
exists(DataFlowCall call, ReturnKindExt kind |
19671967
getReturnPosition(node1) = viableReturnPos(call, kind) and
1968-
node2 = getAnOutNodeExt(call, kind)
1968+
node2 = kind.getAnOutNode(call)
19691969
)
19701970
|
19711971
c1 = node1.getEnclosingCallable() and
@@ -2287,7 +2287,7 @@ private module FlowExploration {
22872287
exists(ReturnKindExt kind, DataFlowCall call |
22882288
partialPathOutOfCallable1(mid, call, kind, cc, ap, config)
22892289
|
2290-
out = getAnOutNodeExt(call, kind)
2290+
out = kind.getAnOutNode(call)
22912291
)
22922292
}
22932293

@@ -2370,7 +2370,7 @@ private module FlowExploration {
23702370
) {
23712371
exists(DataFlowCall call, ReturnKindExt kind |
23722372
partialPathThroughCallable0(call, mid, kind, cc, apnil, config) and
2373-
out = getAnOutNodeExt(call, kind)
2373+
out = kind.getAnOutNode(call)
23742374
)
23752375
}
23762376

cpp/ql/src/semmle/code/cpp/dataflow/internal/DataFlowImpl2.qll

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ private predicate nodeCandFwd1(Node node, Configuration config) {
317317
exists(DataFlowCall call, ReturnNodeExt ret, ReturnKindExt kind |
318318
nodeCandFwd1(ret, config) and
319319
getReturnPosition(ret) = viableReturnPos(call, kind) and
320-
node = getAnOutNodeExt(call, kind)
320+
node = kind.getAnOutNode(call)
321321
)
322322
)
323323
}
@@ -409,7 +409,7 @@ private predicate nodeCand1ReturnPosition(ReturnPosition pos, Configuration conf
409409
exists(DataFlowCall call, ReturnKindExt kind, Node out |
410410
nodeCand1(out, config) and
411411
pos = viableReturnPos(call, kind) and
412-
out = getAnOutNodeExt(call, kind)
412+
out = kind.getAnOutNode(call)
413413
)
414414
}
415415

@@ -576,7 +576,7 @@ private predicate flowOutOfCallable(Node node1, Node node2, Configuration config
576576
not inBarrier(node2, config) and
577577
exists(DataFlowCall call, ReturnKindExt kind |
578578
getReturnPosition1(node1, unbind(config)) = viableReturnPos(call, kind) and
579-
node2 = getAnOutNodeExt(call, kind)
579+
node2 = kind.getAnOutNode(call)
580580
)
581581
}
582582

@@ -1806,7 +1806,7 @@ private predicate pathOutOfCallable1(
18061806
pragma[noinline]
18071807
private predicate pathOutOfCallable(PathNodeMid mid, Node out, CallContext cc) {
18081808
exists(ReturnKindExt kind, DataFlowCall call | pathOutOfCallable1(mid, call, kind, cc) |
1809-
out = getAnOutNodeExt(call, kind)
1809+
out = kind.getAnOutNode(call)
18101810
)
18111811
}
18121812

@@ -1905,7 +1905,7 @@ pragma[noinline]
19051905
private predicate pathThroughCallable(PathNodeMid mid, Node out, CallContext cc, AccessPathNil apnil) {
19061906
exists(DataFlowCall call, ReturnKindExt kind |
19071907
pathThroughCallable0(call, mid, kind, cc, apnil) and
1908-
out = getAnOutNodeExt(call, kind)
1908+
out = kind.getAnOutNode(call)
19091909
)
19101910
}
19111911

@@ -1965,7 +1965,7 @@ private module FlowExploration {
19651965
// flow out of a callable
19661966
exists(DataFlowCall call, ReturnKindExt kind |
19671967
getReturnPosition(node1) = viableReturnPos(call, kind) and
1968-
node2 = getAnOutNodeExt(call, kind)
1968+
node2 = kind.getAnOutNode(call)
19691969
)
19701970
|
19711971
c1 = node1.getEnclosingCallable() and
@@ -2287,7 +2287,7 @@ private module FlowExploration {
22872287
exists(ReturnKindExt kind, DataFlowCall call |
22882288
partialPathOutOfCallable1(mid, call, kind, cc, ap, config)
22892289
|
2290-
out = getAnOutNodeExt(call, kind)
2290+
out = kind.getAnOutNode(call)
22912291
)
22922292
}
22932293

@@ -2370,7 +2370,7 @@ private module FlowExploration {
23702370
) {
23712371
exists(DataFlowCall call, ReturnKindExt kind |
23722372
partialPathThroughCallable0(call, mid, kind, cc, apnil, config) and
2373-
out = getAnOutNodeExt(call, kind)
2373+
out = kind.getAnOutNode(call)
23742374
)
23752375
}
23762376

cpp/ql/src/semmle/code/cpp/dataflow/internal/DataFlowImpl3.qll

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ private predicate nodeCandFwd1(Node node, Configuration config) {
317317
exists(DataFlowCall call, ReturnNodeExt ret, ReturnKindExt kind |
318318
nodeCandFwd1(ret, config) and
319319
getReturnPosition(ret) = viableReturnPos(call, kind) and
320-
node = getAnOutNodeExt(call, kind)
320+
node = kind.getAnOutNode(call)
321321
)
322322
)
323323
}
@@ -409,7 +409,7 @@ private predicate nodeCand1ReturnPosition(ReturnPosition pos, Configuration conf
409409
exists(DataFlowCall call, ReturnKindExt kind, Node out |
410410
nodeCand1(out, config) and
411411
pos = viableReturnPos(call, kind) and
412-
out = getAnOutNodeExt(call, kind)
412+
out = kind.getAnOutNode(call)
413413
)
414414
}
415415

@@ -576,7 +576,7 @@ private predicate flowOutOfCallable(Node node1, Node node2, Configuration config
576576
not inBarrier(node2, config) and
577577
exists(DataFlowCall call, ReturnKindExt kind |
578578
getReturnPosition1(node1, unbind(config)) = viableReturnPos(call, kind) and
579-
node2 = getAnOutNodeExt(call, kind)
579+
node2 = kind.getAnOutNode(call)
580580
)
581581
}
582582

@@ -1806,7 +1806,7 @@ private predicate pathOutOfCallable1(
18061806
pragma[noinline]
18071807
private predicate pathOutOfCallable(PathNodeMid mid, Node out, CallContext cc) {
18081808
exists(ReturnKindExt kind, DataFlowCall call | pathOutOfCallable1(mid, call, kind, cc) |
1809-
out = getAnOutNodeExt(call, kind)
1809+
out = kind.getAnOutNode(call)
18101810
)
18111811
}
18121812

@@ -1905,7 +1905,7 @@ pragma[noinline]
19051905
private predicate pathThroughCallable(PathNodeMid mid, Node out, CallContext cc, AccessPathNil apnil) {
19061906
exists(DataFlowCall call, ReturnKindExt kind |
19071907
pathThroughCallable0(call, mid, kind, cc, apnil) and
1908-
out = getAnOutNodeExt(call, kind)
1908+
out = kind.getAnOutNode(call)
19091909
)
19101910
}
19111911

@@ -1965,7 +1965,7 @@ private module FlowExploration {
19651965
// flow out of a callable
19661966
exists(DataFlowCall call, ReturnKindExt kind |
19671967
getReturnPosition(node1) = viableReturnPos(call, kind) and
1968-
node2 = getAnOutNodeExt(call, kind)
1968+
node2 = kind.getAnOutNode(call)
19691969
)
19701970
|
19711971
c1 = node1.getEnclosingCallable() and
@@ -2287,7 +2287,7 @@ private module FlowExploration {
22872287
exists(ReturnKindExt kind, DataFlowCall call |
22882288
partialPathOutOfCallable1(mid, call, kind, cc, ap, config)
22892289
|
2290-
out = getAnOutNodeExt(call, kind)
2290+
out = kind.getAnOutNode(call)
22912291
)
22922292
}
22932293

@@ -2370,7 +2370,7 @@ private module FlowExploration {
23702370
) {
23712371
exists(DataFlowCall call, ReturnKindExt kind |
23722372
partialPathThroughCallable0(call, mid, kind, cc, apnil, config) and
2373-
out = getAnOutNodeExt(call, kind)
2373+
out = kind.getAnOutNode(call)
23742374
)
23752375
}
23762376

cpp/ql/src/semmle/code/cpp/dataflow/internal/DataFlowImpl4.qll

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ private predicate nodeCandFwd1(Node node, Configuration config) {
317317
exists(DataFlowCall call, ReturnNodeExt ret, ReturnKindExt kind |
318318
nodeCandFwd1(ret, config) and
319319
getReturnPosition(ret) = viableReturnPos(call, kind) and
320-
node = getAnOutNodeExt(call, kind)
320+
node = kind.getAnOutNode(call)
321321
)
322322
)
323323
}
@@ -409,7 +409,7 @@ private predicate nodeCand1ReturnPosition(ReturnPosition pos, Configuration conf
409409
exists(DataFlowCall call, ReturnKindExt kind, Node out |
410410
nodeCand1(out, config) and
411411
pos = viableReturnPos(call, kind) and
412-
out = getAnOutNodeExt(call, kind)
412+
out = kind.getAnOutNode(call)
413413
)
414414
}
415415

@@ -576,7 +576,7 @@ private predicate flowOutOfCallable(Node node1, Node node2, Configuration config
576576
not inBarrier(node2, config) and
577577
exists(DataFlowCall call, ReturnKindExt kind |
578578
getReturnPosition1(node1, unbind(config)) = viableReturnPos(call, kind) and
579-
node2 = getAnOutNodeExt(call, kind)
579+
node2 = kind.getAnOutNode(call)
580580
)
581581
}
582582

@@ -1806,7 +1806,7 @@ private predicate pathOutOfCallable1(
18061806
pragma[noinline]
18071807
private predicate pathOutOfCallable(PathNodeMid mid, Node out, CallContext cc) {
18081808
exists(ReturnKindExt kind, DataFlowCall call | pathOutOfCallable1(mid, call, kind, cc) |
1809-
out = getAnOutNodeExt(call, kind)
1809+
out = kind.getAnOutNode(call)
18101810
)
18111811
}
18121812

@@ -1905,7 +1905,7 @@ pragma[noinline]
19051905
private predicate pathThroughCallable(PathNodeMid mid, Node out, CallContext cc, AccessPathNil apnil) {
19061906
exists(DataFlowCall call, ReturnKindExt kind |
19071907
pathThroughCallable0(call, mid, kind, cc, apnil) and
1908-
out = getAnOutNodeExt(call, kind)
1908+
out = kind.getAnOutNode(call)
19091909
)
19101910
}
19111911

@@ -1965,7 +1965,7 @@ private module FlowExploration {
19651965
// flow out of a callable
19661966
exists(DataFlowCall call, ReturnKindExt kind |
19671967
getReturnPosition(node1) = viableReturnPos(call, kind) and
1968-
node2 = getAnOutNodeExt(call, kind)
1968+
node2 = kind.getAnOutNode(call)
19691969
)
19701970
|
19711971
c1 = node1.getEnclosingCallable() and
@@ -2287,7 +2287,7 @@ private module FlowExploration {
22872287
exists(ReturnKindExt kind, DataFlowCall call |
22882288
partialPathOutOfCallable1(mid, call, kind, cc, ap, config)
22892289
|
2290-
out = getAnOutNodeExt(call, kind)
2290+
out = kind.getAnOutNode(call)
22912291
)
22922292
}
22932293

@@ -2370,7 +2370,7 @@ private module FlowExploration {
23702370
) {
23712371
exists(DataFlowCall call, ReturnKindExt kind |
23722372
partialPathThroughCallable0(call, mid, kind, cc, apnil, config) and
2373-
out = getAnOutNodeExt(call, kind)
2373+
out = kind.getAnOutNode(call)
23742374
)
23752375
}
23762376

cpp/ql/src/semmle/code/cpp/dataflow/internal/DataFlowImplCommon.qll

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,9 @@ private module ImplCommon {
772772
abstract class ReturnKindExt extends TReturnKindExt {
773773
/** Gets a textual representation of this return kind. */
774774
abstract string toString();
775+
776+
/** Gets a node corresponding to data flow out of `call`. */
777+
abstract Node getAnOutNode(DataFlowCall call);
775778
}
776779

777780
class ValueReturnKind extends ReturnKindExt, TValueReturn {
@@ -782,6 +785,8 @@ private module ImplCommon {
782785
ReturnKind getKind() { result = kind }
783786

784787
override string toString() { result = kind.toString() }
788+
789+
override Node getAnOutNode(DataFlowCall call) { result = getAnOutNode(call, this.getKind()) }
785790
}
786791

787792
class ParamUpdateReturnKind extends ReturnKindExt, TParamUpdate {
@@ -792,6 +797,13 @@ private module ImplCommon {
792797
int getPosition() { result = pos }
793798

794799
override string toString() { result = "param update " + pos }
800+
801+
override Node getAnOutNode(DataFlowCall call) {
802+
exists(ArgumentNode arg |
803+
result.(PostUpdateNode).getPreUpdateNode() = arg and
804+
arg.argumentOf(call, this.getPosition())
805+
)
806+
}
795807
}
796808

797809
/** A callable tagged with a relevant return kind. */
@@ -823,15 +835,6 @@ private module ImplCommon {
823835
)
824836
}
825837

826-
Node getAnOutNodeExt(DataFlowCall call, ReturnKindExt kind) {
827-
result = getAnOutNode(call, kind.(ValueReturnKind).getKind())
828-
or
829-
exists(ArgumentNode arg |
830-
result.(PostUpdateNode).getPreUpdateNode() = arg and
831-
arg.argumentOf(call, kind.(ParamUpdateReturnKind).getPosition())
832-
)
833-
}
834-
835838
bindingset[cc, callable]
836839
predicate resolveReturn(CallContext cc, DataFlowCallable callable, DataFlowCall call) {
837840
cc instanceof CallContextAny and callable = viableCallable(call)

0 commit comments

Comments
 (0)