From 59d67fa68a2e0574fd6bc9047e1dea36318b6117 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Fri, 31 Mar 2023 21:59:06 +1100 Subject: [PATCH] Only call PyTuple_Check once in getink --- src/_imaging.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/_imaging.c b/src/_imaging.c index d7b90b9e8..281f3a4d2 100644 --- a/src/_imaging.c +++ b/src/_imaging.c @@ -502,12 +502,9 @@ getink(PyObject *color, Imaging im, char *ink) { be cast to either UINT8 or INT32 */ int rIsInt = 0; - int tupleSize = 0; - if (PyTuple_Check(color)) { - tupleSize = PyTuple_GET_SIZE(color); - if (tupleSize == 1) { - color = PyTuple_GetItem(color, 0); - } + int tupleSize = PyTuple_Check(color) ? PyTuple_GET_SIZE(color) : -1; + if (tupleSize == 1) { + color = PyTuple_GetItem(color, 0); } if (im->type == IMAGING_TYPE_UINT8 || im->type == IMAGING_TYPE_INT32 || im->type == IMAGING_TYPE_SPECIAL) { @@ -521,7 +518,7 @@ getink(PyObject *color, Imaging im, char *ink) { PyErr_SetString( PyExc_TypeError, "color must be int or single-element tuple"); return NULL; - } else if (!PyTuple_Check(color)) { + } else if (tupleSize == -1) { PyErr_SetString(PyExc_TypeError, "color must be int or tuple"); return NULL; }