From 2b91a48d72071e195b691156a5755cb7e76fdc37 Mon Sep 17 00:00:00 2001 From: "Carsten Haitzler (Rasterman)" Date: Sat, 29 Jul 2017 13:49:33 +0900 Subject: [PATCH] ector software - fix min/max int range for fixedpoint math min value bitshifts are negative and thus not portable. just tax max (as its 1 more than min it if we do -max) as the limit as its within range. this should fix it @fix found by PVS studio --- src/lib/ector/software/ector_software_gradient.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/lib/ector/software/ector_software_gradient.c b/src/lib/ector/software/ector_software_gradient.c index 55636b4237..bdbf70380c 100644 --- a/src/lib/ector/software/ector_software_gradient.c +++ b/src/lib/ector/software/ector_software_gradient.c @@ -408,8 +408,11 @@ fetch_linear_gradient(uint32_t *buffer, Span_Data *data, int y, int x, int lengt } else { - if (t + inc*length < (float)(INT_MAX >> (FIXPT_BITS + 1)) && - t+inc*length > (float)(INT_MIN >> (FIXPT_BITS + 1))) + const int vmax = INT_MAX >> (FIXPT_BITS + 1); + const int vmin = -vmin; + float v = t + (inc *length); + + if ((v < (float)vmax) && (v > (float)(vmin))) { // we can use fixed point math t_fixed = (int)(t * FIXPT_SIZE);