From 5ca132eafaaaf2b5bffc2b696d1fa4e364ffaf0b Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Sat, 25 Jan 2020 14:15:57 -0500 Subject: [PATCH] stepcompress: Fix rounding error when interval=0 In the rare case where the step generation code finds an interval of zero, it was possible for an integer division of a negative number to cause an incorrect result. Fix that by using the idiv_up() and idiv_down() helpers. Signed-off-by: Kevin O'Connor --- klippy/chelper/stepcompress.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/klippy/chelper/stepcompress.c b/klippy/chelper/stepcompress.c index 4a386d65..7b92e3db 100644 --- a/klippy/chelper/stepcompress.c +++ b/klippy/chelper/stepcompress.c @@ -115,9 +115,9 @@ compress_bisect_add(struct stepcompress *sc) int32_t nextaddfactor = nextcount*(nextcount-1)/2; int32_t c = add*nextaddfactor; if (nextmininterval*nextcount < nextpoint.minp - c) - nextmininterval = DIV_ROUND_UP(nextpoint.minp - c, nextcount); + nextmininterval = idiv_up(nextpoint.minp - c, nextcount); if (nextmaxinterval*nextcount > nextpoint.maxp - c) - nextmaxinterval = (nextpoint.maxp - c) / nextcount; + nextmaxinterval = idiv_down(nextpoint.maxp - c, nextcount); if (nextmininterval > nextmaxinterval) break; interval = nextmaxinterval;