Skip to content

Commit 6f598c0

Browse files
committed
Fix cppcheck warnings in color lerp
1 parent ded57ba commit 6f598c0

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src_c/color.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,16 @@
4747

4848
#include <ctype.h>
4949

50+
static inline double
51+
pg_round(double d)
52+
{
5053
#if (!defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L) && \
5154
!defined(round)
52-
#define pg_round(d) (((d < 0) ? (ceil((d) - 0.5)) : (floor((d) + 0.5))))
55+
return (((d < 0) ? (ceil((d)-0.5)) : (floor((d) + 0.5))));
5356
#else
54-
#define pg_round(d) round(d)
57+
return round(d);
5558
#endif
59+
}
5660

5761
typedef enum { TRISTATE_SUCCESS, TRISTATE_FAIL, TRISTATE_ERROR } tristate;
5862

@@ -813,10 +817,10 @@ _color_lerp(pgColorObject *self, PyObject *args, PyObject *kw)
813817
return RAISE(PyExc_ValueError, "Argument 2 must be in range [0, 1]");
814818
}
815819

816-
new_rgba[0] = (Uint8)pg_round(self->data[0] * (1 - amt) + rgba[0] * amt);
817-
new_rgba[1] = (Uint8)pg_round(self->data[1] * (1 - amt) + rgba[1] * amt);
818-
new_rgba[2] = (Uint8)pg_round(self->data[2] * (1 - amt) + rgba[2] * amt);
819-
new_rgba[3] = (Uint8)pg_round(self->data[3] * (1 - amt) + rgba[3] * amt);
820+
for (int i = 0; i < 4; i++) {
821+
new_rgba[i] =
822+
(Uint8)pg_round(self->data[i] * (1 - amt) + rgba[i] * amt);
823+
}
820824

821825
return (PyObject *)_color_new_internal(Py_TYPE(self), new_rgba);
822826
}

0 commit comments

Comments
 (0)