mirror of
https://seed.radicle.dev/rad:z2UcCU1LgMshWvXj6hXSDDrwB8q8M.git
synced 2026-11-29 14:50:37 +08:00
fix: Use loop in FindByCommit::next to avoid stack overflow
Use an iterative loop with `return` and `continue` to avoid stack overflow. A stack overflow could have occurred due to the recursion, and potentially many jobs.
This commit is contained in:
+7
-8
@@ -657,15 +657,14 @@ impl Iterator for FindByCommit<'_> {
|
||||
type Item = Result<(JobId, Job), cob::store::Error>;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
let job = self.jobs.next()?;
|
||||
job.and_then(|(id, job)| {
|
||||
if self.wanted(&job) {
|
||||
Ok(Some((JobId::from(id), job)))
|
||||
} else {
|
||||
self.next().transpose()
|
||||
loop {
|
||||
let job = self.jobs.next()?;
|
||||
match job {
|
||||
Ok((id, job)) if self.wanted(&job) => return Some(Ok((JobId::from(id), job))),
|
||||
Ok(_) => continue,
|
||||
Err(err) => return Some(Err(err)),
|
||||
}
|
||||
})
|
||||
.transpose()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user