From 06151bcab53264a1f3918508e98310e014f03556 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filipe=20La=C3=ADns?= Date: Wed, 27 May 2020 18:52:30 +0100 Subject: [PATCH] ctypes: cauclate bitfield size in a single arithmetic expression MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Filipe LaĆ­ns --- Modules/_ctypes/cfield.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/Modules/_ctypes/cfield.c b/Modules/_ctypes/cfield.c index 4280d886769..d4bfa17bb41 100644 --- a/Modules/_ctypes/cfield.c +++ b/Modules/_ctypes/cfield.c @@ -74,9 +74,7 @@ PyCField_FromDesc(PyObject *desc, Py_ssize_t index, #ifndef MS_WIN32 if (pack && bitsize) { /* packed bitfield */ - size = 1; - while(size * 8 < bitsize) - size += 1; + size = (bitsize - 1) / 8 + 1; } else #endif size = dict->size; @@ -182,8 +180,7 @@ PyCField_FromDesc(PyObject *desc, Py_ssize_t index, case EXPAND_BITFIELD: if (pack) - while(size * 8 < (*pbitofs + bitsize)) - size += 1; + size = (*pbitofs + bitsize - 1) / 8 + 1; *poffset += size - *pfield_size/8; *psize += size - *pfield_size/8;