stepcompress: Fix compress_bisect_add() infinite loop

At high step speeds, it is possible to exit the inner scan due to
integer truncation.  Always update minadd or maxadd so that the outer
loop always terminates.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2016-07-06 13:19:21 -04:00
parent b0b2e9c4aa
commit ae8d57e650
1 changed files with 6 additions and 2 deletions

View File

@ -174,11 +174,15 @@ compress_bisect_add(struct stepcompress *sc)
// Check if a greater or lesser add could extend the sequence // Check if a greater or lesser add could extend the sequence
int32_t maxreach = add*addfactor + maxinterval*(count+1); int32_t maxreach = add*addfactor + maxinterval*(count+1);
if (maxreach < point.minp) if (maxreach < point.minp) {
minadd = add;
origmaxinterval = maxinterval; origmaxinterval = maxinterval;
else } else {
maxadd = add;
origmininterval = mininterval; origmininterval = mininterval;
}
// See if next point would further limit the add range
if ((minadd+1)*addfactor + origmaxinterval*(count+1) < point.minp) if ((minadd+1)*addfactor + origmaxinterval*(count+1) < point.minp)
minadd = idiv_up(point.minp - origmaxinterval*(count+1) minadd = idiv_up(point.minp - origmaxinterval*(count+1)
, addfactor) - 1; , addfactor) - 1;