mirror of
https://seed.radicle.dev/rad:z2UcCU1LgMshWvXj6hXSDDrwB8q8M.git
synced 2026-10-18 19:30:30 +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,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
### Fixes
|
||||
|
||||
- Use an iterative loop to avoid stack overflow, through recursion, when using
|
||||
`FindByCommit` iterator.
|
||||
|
||||
## 0.5.0
|
||||
|
||||
### Highlights
|
||||
|
||||
+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