Skip to content

Commit d87c8c7

Browse files
committed
Python: Remove omittable exists variables
1 parent 3b6dae4 commit d87c8c7

File tree

30 files changed

+190
-225
lines changed

30 files changed

+190
-225
lines changed

python/ql/lib/analysis/DefinitionTracking.qll

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -221,10 +221,8 @@ pragma[noinline]
221221
private predicate module_and_name_for_import_star(
222222
ModuleObject mod, string name, ImportStarRefinement def
223223
) {
224-
exists(ImportStarNode im_star |
225-
module_and_name_for_import_star_helper(mod, name, im_star, def) and
226-
mod.exports(name)
227-
)
224+
module_and_name_for_import_star_helper(mod, name, _, def) and
225+
mod.exports(name)
228226
}
229227

230228
pragma[noinline]
@@ -484,9 +482,9 @@ class NiceLocationExpr extends Expr {
484482
*/
485483
predicate hasLocationInfo(string f, int bl, int bc, int el, int ec) {
486484
/* Attribute location for x.y is that of 'y' so that url does not overlap with that of 'x' */
487-
exists(int abl, int abc | this.(Attribute).getLocation().hasLocationInfo(f, abl, abc, el, ec) |
488-
bl = el and bc = ec - this.(Attribute).getName().length() + 1
489-
)
485+
this.(Attribute).getLocation().hasLocationInfo(f, _, _, el, ec) and
486+
bl = el and
487+
bc = ec - this.(Attribute).getName().length() + 1
490488
or
491489
this.(Name).getLocation().hasLocationInfo(f, bl, bc, el, ec)
492490
or

python/ql/lib/semmle/python/Flow.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -385,9 +385,9 @@ class CallNode extends ControlFlowNode {
385385

386386
/** Gets the flow node corresponding to an argument of the call corresponding to this flow node */
387387
ControlFlowNode getAnArg() {
388-
exists(int n | result = this.getArg(n))
388+
result = this.getArg(_)
389389
or
390-
exists(string name | result = this.getArgByName(name))
390+
result = this.getArgByName(_)
391391
}
392392

393393
override Call getNode() { result = super.getNode() }

python/ql/lib/semmle/python/RegexTreeView.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,8 @@ module Impl implements RegexTreeViewSig {
227227
predicate hasLocationInfo(
228228
string filepath, int startline, int startcolumn, int endline, int endcolumn
229229
) {
230-
exists(int re_start, int re_end |
231-
re.getLocation().hasLocationInfo(filepath, startline, re_start, endline, re_end) and
230+
exists(int re_start |
231+
re.getLocation().hasLocationInfo(filepath, startline, re_start, endline, _) and
232232
startcolumn = re_start + start + 4 and
233233
endcolumn = re_start + end + 3
234234
)

python/ql/lib/semmle/python/SelfAttribute.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ private predicate attr_assigned_in_method_arg_n(FunctionObject method, string na
7878
attr.isStore()
7979
)
8080
or
81-
exists(CallNode call, FunctionObject callee, int m |
82-
callee.getArgumentForCall(call, m) = param.getAUse() and
81+
exists(FunctionObject callee, int m |
82+
callee.getArgumentForCall(_, m) = param.getAUse() and
8383
attr_assigned_in_method_arg_n(callee, name, m)
8484
)
8585
)

python/ql/lib/semmle/python/dataflow/new/internal/DataFlowImpl.qll

Lines changed: 30 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -876,9 +876,9 @@ private module Stage1 implements StageSig {
876876

877877
pragma[nomagic]
878878
private predicate revFlowOut(ReturnPosition pos, Configuration config) {
879-
exists(DataFlowCall call, NodeEx out |
879+
exists(NodeEx out |
880880
revFlow(out, _, config) and
881-
viableReturnPosOutNodeCandFwd1(call, pos, out, config)
881+
viableReturnPosOutNodeCandFwd1(_, pos, out, config)
882882
)
883883
}
884884

@@ -1731,8 +1731,8 @@ private module MkStage<StageSig PrevStage> {
17311731
)
17321732
or
17331733
// flow through a callable
1734-
exists(DataFlowCall call, ParamNodeEx p, ReturnPosition pos, Ap innerReturnAp |
1735-
revFlowThrough(call, returnCtx, p, state, pos, returnAp, ap, innerReturnAp, config) and
1734+
exists(DataFlowCall call, ParamNodeEx p, Ap innerReturnAp |
1735+
revFlowThrough(call, returnCtx, p, state, _, returnAp, ap, innerReturnAp, config) and
17361736
flowThroughIntoCall(call, node, p, _, ap, innerReturnAp, config)
17371737
)
17381738
or
@@ -1901,8 +1901,8 @@ private module MkStage<StageSig PrevStage> {
19011901

19021902
pragma[nomagic]
19031903
predicate parameterMayFlowThrough(ParamNodeEx p, Ap ap, Configuration config) {
1904-
exists(RetNodeEx ret, ReturnPosition pos |
1905-
returnFlowsThrough(ret, pos, _, _, p, ap, _, config) and
1904+
exists(ReturnPosition pos |
1905+
returnFlowsThrough(_, pos, _, _, p, ap, _, config) and
19061906
parameterFlowsThroughRev(p, ap, pos, _, config)
19071907
)
19081908
}
@@ -1923,8 +1923,8 @@ private module MkStage<StageSig PrevStage> {
19231923
DataFlowCall call, ArgNodeEx arg, FlowState state, ReturnCtx returnCtx, ApOption returnAp,
19241924
Ap ap, Configuration config
19251925
) {
1926-
exists(ParamNodeEx p, ReturnPosition pos, Ap innerReturnAp |
1927-
revFlowThrough(call, returnCtx, p, state, pos, returnAp, ap, innerReturnAp, config) and
1926+
exists(ParamNodeEx p, Ap innerReturnAp |
1927+
revFlowThrough(call, returnCtx, p, state, _, returnAp, ap, innerReturnAp, config) and
19281928
flowThroughIntoCall(call, arg, p, _, ap, innerReturnAp, config)
19291929
)
19301930
}
@@ -3749,8 +3749,8 @@ private predicate paramFlowsThrough(
37493749
ReturnKindExt kind, FlowState state, CallContextCall cc, SummaryCtxSome sc, AccessPath ap,
37503750
AccessPathApprox apa, Configuration config
37513751
) {
3752-
exists(PathNodeMid mid, RetNodeEx ret |
3753-
pathNode(mid, ret, state, cc, sc, ap, config, _) and
3752+
exists(RetNodeEx ret |
3753+
pathNode(_, ret, state, cc, sc, ap, config, _) and
37543754
kind = ret.getKind() and
37553755
apa = ap.getApprox() and
37563756
parameterFlowThroughAllowed(sc.getParamNode(), kind)
@@ -4212,37 +4212,33 @@ private module FlowExploration {
42124212
ap = TRevPartialNil() and
42134213
exists(config.explorationLimit())
42144214
or
4215-
exists(PartialPathNodeRev mid |
4216-
revPartialPathStep(mid, node, state, sc1, sc2, sc3, ap, config) and
4217-
not clearsContentEx(node, ap.getHead()) and
4218-
(
4219-
notExpectsContent(node) or
4220-
expectsContentEx(node, ap.getHead())
4221-
) and
4222-
not fullBarrier(node, config) and
4223-
not stateBarrier(node, state, config) and
4224-
distSink(node.getEnclosingCallable(), config) <= config.explorationLimit()
4225-
)
4215+
revPartialPathStep(_, node, state, sc1, sc2, sc3, ap, config) and
4216+
not clearsContentEx(node, ap.getHead()) and
4217+
(
4218+
notExpectsContent(node) or
4219+
expectsContentEx(node, ap.getHead())
4220+
) and
4221+
not fullBarrier(node, config) and
4222+
not stateBarrier(node, state, config) and
4223+
distSink(node.getEnclosingCallable(), config) <= config.explorationLimit()
42264224
}
42274225

42284226
pragma[nomagic]
42294227
private predicate partialPathNodeMk0(
42304228
NodeEx node, FlowState state, CallContext cc, TSummaryCtx1 sc1, TSummaryCtx2 sc2,
42314229
TSummaryCtx3 sc3, PartialAccessPath ap, Configuration config
42324230
) {
4233-
exists(PartialPathNodeFwd mid |
4234-
partialPathStep(mid, node, state, cc, sc1, sc2, sc3, ap, config) and
4235-
not fullBarrier(node, config) and
4236-
not stateBarrier(node, state, config) and
4237-
not clearsContentEx(node, ap.getHead().getContent()) and
4238-
(
4239-
notExpectsContent(node) or
4240-
expectsContentEx(node, ap.getHead().getContent())
4241-
) and
4242-
if node.asNode() instanceof CastingNode
4243-
then compatibleTypes(node.getDataFlowType(), ap.getType())
4244-
else any()
4245-
)
4231+
partialPathStep(_, node, state, cc, sc1, sc2, sc3, ap, config) and
4232+
not fullBarrier(node, config) and
4233+
not stateBarrier(node, state, config) and
4234+
not clearsContentEx(node, ap.getHead().getContent()) and
4235+
(
4236+
notExpectsContent(node) or
4237+
expectsContentEx(node, ap.getHead().getContent())
4238+
) and
4239+
if node.asNode() instanceof CastingNode
4240+
then compatibleTypes(node.getDataFlowType(), ap.getType())
4241+
else any()
42464242
}
42474243

42484244
/**

python/ql/lib/semmle/python/dataflow/new/internal/DataFlowImpl2.qll

Lines changed: 30 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -876,9 +876,9 @@ private module Stage1 implements StageSig {
876876

877877
pragma[nomagic]
878878
private predicate revFlowOut(ReturnPosition pos, Configuration config) {
879-
exists(DataFlowCall call, NodeEx out |
879+
exists(NodeEx out |
880880
revFlow(out, _, config) and
881-
viableReturnPosOutNodeCandFwd1(call, pos, out, config)
881+
viableReturnPosOutNodeCandFwd1(_, pos, out, config)
882882
)
883883
}
884884

@@ -1731,8 +1731,8 @@ private module MkStage<StageSig PrevStage> {
17311731
)
17321732
or
17331733
// flow through a callable
1734-
exists(DataFlowCall call, ParamNodeEx p, ReturnPosition pos, Ap innerReturnAp |
1735-
revFlowThrough(call, returnCtx, p, state, pos, returnAp, ap, innerReturnAp, config) and
1734+
exists(DataFlowCall call, ParamNodeEx p, Ap innerReturnAp |
1735+
revFlowThrough(call, returnCtx, p, state, _, returnAp, ap, innerReturnAp, config) and
17361736
flowThroughIntoCall(call, node, p, _, ap, innerReturnAp, config)
17371737
)
17381738
or
@@ -1901,8 +1901,8 @@ private module MkStage<StageSig PrevStage> {
19011901

19021902
pragma[nomagic]
19031903
predicate parameterMayFlowThrough(ParamNodeEx p, Ap ap, Configuration config) {
1904-
exists(RetNodeEx ret, ReturnPosition pos |
1905-
returnFlowsThrough(ret, pos, _, _, p, ap, _, config) and
1904+
exists(ReturnPosition pos |
1905+
returnFlowsThrough(_, pos, _, _, p, ap, _, config) and
19061906
parameterFlowsThroughRev(p, ap, pos, _, config)
19071907
)
19081908
}
@@ -1923,8 +1923,8 @@ private module MkStage<StageSig PrevStage> {
19231923
DataFlowCall call, ArgNodeEx arg, FlowState state, ReturnCtx returnCtx, ApOption returnAp,
19241924
Ap ap, Configuration config
19251925
) {
1926-
exists(ParamNodeEx p, ReturnPosition pos, Ap innerReturnAp |
1927-
revFlowThrough(call, returnCtx, p, state, pos, returnAp, ap, innerReturnAp, config) and
1926+
exists(ParamNodeEx p, Ap innerReturnAp |
1927+
revFlowThrough(call, returnCtx, p, state, _, returnAp, ap, innerReturnAp, config) and
19281928
flowThroughIntoCall(call, arg, p, _, ap, innerReturnAp, config)
19291929
)
19301930
}
@@ -3749,8 +3749,8 @@ private predicate paramFlowsThrough(
37493749
ReturnKindExt kind, FlowState state, CallContextCall cc, SummaryCtxSome sc, AccessPath ap,
37503750
AccessPathApprox apa, Configuration config
37513751
) {
3752-
exists(PathNodeMid mid, RetNodeEx ret |
3753-
pathNode(mid, ret, state, cc, sc, ap, config, _) and
3752+
exists(RetNodeEx ret |
3753+
pathNode(_, ret, state, cc, sc, ap, config, _) and
37543754
kind = ret.getKind() and
37553755
apa = ap.getApprox() and
37563756
parameterFlowThroughAllowed(sc.getParamNode(), kind)
@@ -4212,37 +4212,33 @@ private module FlowExploration {
42124212
ap = TRevPartialNil() and
42134213
exists(config.explorationLimit())
42144214
or
4215-
exists(PartialPathNodeRev mid |
4216-
revPartialPathStep(mid, node, state, sc1, sc2, sc3, ap, config) and
4217-
not clearsContentEx(node, ap.getHead()) and
4218-
(
4219-
notExpectsContent(node) or
4220-
expectsContentEx(node, ap.getHead())
4221-
) and
4222-
not fullBarrier(node, config) and
4223-
not stateBarrier(node, state, config) and
4224-
distSink(node.getEnclosingCallable(), config) <= config.explorationLimit()
4225-
)
4215+
revPartialPathStep(_, node, state, sc1, sc2, sc3, ap, config) and
4216+
not clearsContentEx(node, ap.getHead()) and
4217+
(
4218+
notExpectsContent(node) or
4219+
expectsContentEx(node, ap.getHead())
4220+
) and
4221+
not fullBarrier(node, config) and
4222+
not stateBarrier(node, state, config) and
4223+
distSink(node.getEnclosingCallable(), config) <= config.explorationLimit()
42264224
}
42274225

42284226
pragma[nomagic]
42294227
private predicate partialPathNodeMk0(
42304228
NodeEx node, FlowState state, CallContext cc, TSummaryCtx1 sc1, TSummaryCtx2 sc2,
42314229
TSummaryCtx3 sc3, PartialAccessPath ap, Configuration config
42324230
) {
4233-
exists(PartialPathNodeFwd mid |
4234-
partialPathStep(mid, node, state, cc, sc1, sc2, sc3, ap, config) and
4235-
not fullBarrier(node, config) and
4236-
not stateBarrier(node, state, config) and
4237-
not clearsContentEx(node, ap.getHead().getContent()) and
4238-
(
4239-
notExpectsContent(node) or
4240-
expectsContentEx(node, ap.getHead().getContent())
4241-
) and
4242-
if node.asNode() instanceof CastingNode
4243-
then compatibleTypes(node.getDataFlowType(), ap.getType())
4244-
else any()
4245-
)
4231+
partialPathStep(_, node, state, cc, sc1, sc2, sc3, ap, config) and
4232+
not fullBarrier(node, config) and
4233+
not stateBarrier(node, state, config) and
4234+
not clearsContentEx(node, ap.getHead().getContent()) and
4235+
(
4236+
notExpectsContent(node) or
4237+
expectsContentEx(node, ap.getHead().getContent())
4238+
) and
4239+
if node.asNode() instanceof CastingNode
4240+
then compatibleTypes(node.getDataFlowType(), ap.getType())
4241+
else any()
42464242
}
42474243

42484244
/**

0 commit comments

Comments
 (0)