Commit e1cd5891af199dc6d926a1792c9add182b39fc56
1 parent
651b51f0
Fix infinite loop on small files with progress reporting (fixes #230)
Turns out you can keep adding zero to a number over and over again and it just doesn't get any bigger. Who would have known?
Showing
4 changed files
with
21 additions
and
1 deletions
ChangeLog
libqpdf/QPDFWriter.cc
| ... | ... | @@ -3357,9 +3357,10 @@ QPDFWriter::indicateProgress(bool decrement, bool finished) |
| 3357 | 3357 | this->m->events_expected))); |
| 3358 | 3358 | this->m->progress_reporter->reportProgress(percentage); |
| 3359 | 3359 | } |
| 3360 | + int increment = std::max(1, (this->m->events_expected / 100)); | |
| 3360 | 3361 | while (this->m->events_seen >= this->m->next_progress_report) |
| 3361 | 3362 | { |
| 3362 | - this->m->next_progress_report += (this->m->events_expected / 100); | |
| 3363 | + this->m->next_progress_report += increment; | |
| 3363 | 3364 | } |
| 3364 | 3365 | } |
| 3365 | 3366 | ... | ... |
qpdf/qtest/qpdf.test
| ... | ... | @@ -927,6 +927,17 @@ $td->runtest("don't overwrite self", |
| 927 | 927 | |
| 928 | 928 | show_ntests(); |
| 929 | 929 | # ---------- |
| 930 | +$td->notify("--- Progress reporting ---"); | |
| 931 | +$n_tests += 1; | |
| 932 | + | |
| 933 | +$td->runtest("progress report on small file", | |
| 934 | + {$td->COMMAND => "qpdf --progress minimal.pdf a.pdf", | |
| 935 | + $td->FILTER => "perl filter-progress.pl"}, | |
| 936 | + {$td->FILE => "small-progress.out", $td->EXIT_STATUS => 0}, | |
| 937 | + $td->NORMALIZE_NEWLINES); | |
| 938 | + | |
| 939 | +show_ntests(); | |
| 940 | +# ---------- | |
| 930 | 941 | $td->notify("--- Type checks ---"); |
| 931 | 942 | $n_tests += 4; |
| 932 | 943 | # Whenever object-types.pdf is edited, object-types-os.pdf should be | ... | ... |
qpdf/qtest/qpdf/small-progress.out
0 → 100644