Python: UnguardedNextInGenerator.ql: Excludes next with default value

This commit is contained in:
Rebecca Valentine
2020-03-16 17:08:06 -07:00
parent 2f3967cf5e
commit ff6e0ce35c
2 changed files with 8 additions and 0 deletions

View File

@@ -28,6 +28,10 @@ predicate call_to_next(CallNode call, ControlFlowNode iter) {
iter = next().getArgumentForCall(call, 0)
}
predicate call_to_next_has_default(CallNode call) {
exists(call.getArg(1))
}
predicate guarded_not_empty_sequence(EssaVariable sequence) {
sequence.getDefinition() instanceof EssaEdgeRefinement
}
@@ -49,6 +53,7 @@ predicate stop_iteration_handled(CallNode call) {
from CallNode call
where call_to_next(call, _) and
not call_to_next_has_default(call) and
not exists(EssaVariable iterator |
call_to_next(call, iterator.getAUse()) and
iter_not_exhausted(iterator)

View File

@@ -47,3 +47,6 @@ def next_in_comp(seq, fields):
seq_iter = iter(seq)
values = [ next(seq_iter) if f.attname in NAMES else DEFAULT for f in fields ]
return values
def ok5(seq):
yield next(iter([]), 'foo')