Skip to content

Commit

Permalink
logic error in cups_job_completed
Browse files Browse the repository at this point in the history
The cupsFreeJobs and job_state check were inside the for loop.
Therefore when the job was found and 'break' issued, the loop would exit
and cupsFreeJob and the job_state check would never get called.
  • Loading branch information
nathanstitt committed Jul 7, 2013
1 parent a0d33f5 commit 8fd78f3
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions ext/cups.c
Original file line number Diff line number Diff line change
Expand Up @@ -336,27 +336,27 @@ static VALUE cups_job_completed(VALUE self)

if (NIL_P(job_id)) {
return Qfalse;
} else {
num_jobs = cupsGetJobs(&jobs, printer_arg, 1, -1); // Get jobs
// job_state = IPP_JOB_COMPLETED;
}

for (i = 0; i < num_jobs; i ++) {
if (jobs[i].id == NUM2INT(job_id)) {
job_state = jobs[i].state;
break;
}

// Free job array
cupsFreeJobs(num_jobs, jobs);

if (job_state == IPP_JOB_COMPLETED) {
return Qtrue;
} else {
return Qfalse;
}

num_jobs = cupsGetJobs(&jobs, printer_arg, 1, -1); // Get jobs

// find our job
for (i = 0; i < num_jobs; i ++) {
if (jobs[i].id == NUM2INT(job_id)) {
job_state = jobs[i].state;
break;
}
}
}

// Free job array
cupsFreeJobs(num_jobs, jobs);

if (job_state == IPP_JOB_COMPLETED) {
return Qtrue;
} else {
return Qfalse;
}

}

/*
Expand Down

0 comments on commit 8fd78f3

Please sign in to comment.