From 9fa0a62c8a0990178aa2f0485d48ee7aaf975e7a Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Sat, 8 Oct 2016 20:28:43 -0400 Subject: [PATCH] stepcompress: Eliminate possible infinite loop in compress_bisect_add() Commit 47f30331 converted compress_bisect_add() to use "best reach" instead of "best add". However, that change caused compress_bisect_add() to behave poorly when passed in invalid data (negative times). Change the code to better handle invalid data. Signed-off-by: Kevin O'Connor --- klippy/stepcompress.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/klippy/stepcompress.c b/klippy/stepcompress.c index 584bde04..55cb09e8 100644 --- a/klippy/stepcompress.c +++ b/klippy/stepcompress.c @@ -142,7 +142,7 @@ compress_bisect_add(struct stepcompress *sc) struct points point = minmax_point(sc, sc->queue_pos); int32_t outer_mininterval = point.minp, outer_maxinterval = point.maxp; int32_t add = 0, minadd = -0x8001, maxadd = 0x8000; - int32_t bestinterval = 0, bestcount = 0, bestadd = 0, bestreach = 0; + int32_t bestinterval = 0, bestcount = 1, bestadd = 0, bestreach = INT32_MIN; for (;;) { // Find longest valid sequence with the given 'add'