Skip to content

Commit

Permalink
Use some modern initialization syntax in builtin_wait
Browse files Browse the repository at this point in the history
Avoids potentially dangling pointers.
  • Loading branch information
ridiculousfish committed Nov 16, 2017
1 parent 51d34e1 commit bc28bd7
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/builtin_wait.cpp
Expand Up @@ -13,9 +13,8 @@
static int retval;

static bool all_jobs_finished() {
job_t *j;
job_iterator_t jobs;
while ((j = jobs.next())) {
while (job_t *j = jobs.next()) {
// If any job is not completed, return false.
// If there are stopped jobs, they are ignored.
if ((j->flags & JOB_CONSTRUCTED) && !job_is_completed(j) && !job_is_stopped(j)) {
Expand All @@ -26,15 +25,14 @@ static bool all_jobs_finished() {
}

static bool any_jobs_finished(size_t jobs_len) {
job_t *j;
job_iterator_t jobs;
bool no_jobs_running = true;

// If any job is removed from list, return true.
if (jobs_len != jobs.count()) {
return true;
}
while ((j = jobs.next())) {
while (job_t *j = jobs.next()) {
// If any job is completed, return true.
if ((j->flags & JOB_CONSTRUCTED) && (job_is_completed(j) || job_is_stopped(j))) {
return true;
Expand Down Expand Up @@ -64,9 +62,8 @@ static void wait_for_backgrounds(bool any_flag) {
}

static bool all_specified_jobs_finished(const std::vector<int> &wjobs_pid) {
job_t *j;
for (auto pid : wjobs_pid) {
if ((j = job_get_from_pid(pid))) {
if (job_t *j = job_get_from_pid(pid)) {
// If any specified job is not completed, return false.
// If there are stopped jobs, they are ignored.
if ((j->flags & JOB_CONSTRUCTED) && !job_is_completed(j) && !job_is_stopped(j)) {
Expand Down

0 comments on commit bc28bd7

Please sign in to comment.