Skip to content

Commit 0ee7eb4

Browse files
committed
Modules/_ctypes/cfield.c: protect macros expansion via do { ... } while (0) constructions
1 parent e84d689 commit 0ee7eb4

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

Modules/_ctypes/cfield.c

+7-5
Original file line numberDiff line numberDiff line change
@@ -425,11 +425,13 @@ Py_ssize_t BUILD_SIZE(Py_ssize_t bitsize, Py_ssize_t offset) {
425425
/* This macro CHANGES the first parameter IN PLACE. For proper sign handling,
426426
we must first shift left, then right.
427427
*/
428-
#define GET_BITFIELD(v, size) \
429-
if (NUM_BITS(size)) { \
430-
v <<= (sizeof(v)*8 - LOW_BIT(size) - NUM_BITS(size)); \
431-
v >>= (sizeof(v)*8 - NUM_BITS(size)); \
432-
}
428+
#define GET_BITFIELD(v, size) \
429+
do { \
430+
if (NUM_BITS(size)) { \
431+
v <<= (sizeof(v)*8 - LOW_BIT(size) - NUM_BITS(size)); \
432+
v >>= (sizeof(v)*8 - NUM_BITS(size)); \
433+
} \
434+
} while (0)
433435

434436
/* This macro RETURNS the first parameter with the bit field CHANGED. */
435437
#define SET(type, x, v, size) \

0 commit comments

Comments
 (0)