Skip to content

Commit a1f9acc

Browse files
committed
pythongh-133703: dict: fix calculate_log2_keysize()
1 parent 6d5a8c2 commit a1f9acc

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

Objects/dictobject.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -547,13 +547,13 @@ static inline uint8_t
547547
calculate_log2_keysize(Py_ssize_t minsize)
548548
{
549549
#if SIZEOF_LONG == SIZEOF_SIZE_T
550-
minsize = (minsize | PyDict_MINSIZE) - 1;
551-
return _Py_bit_length(minsize | (PyDict_MINSIZE-1));
550+
minsize = Py_MAX(minsize, PyDict_MINSIZE);
551+
return _Py_bit_length(minsize - 1);
552552
#elif defined(_MSC_VER)
553-
// On 64bit Windows, sizeof(long) == 4.
554-
minsize = (minsize | PyDict_MINSIZE) - 1;
553+
// On 64bit Windows, sizeof(long) == 4. We cannot use _Py_bit_length.
554+
minsize = Py_MAX(minsize, PyDict_MINSIZE);
555555
unsigned long msb;
556-
_BitScanReverse64(&msb, (uint64_t)minsize);
556+
_BitScanReverse64(&msb, (uint64_t)minsize - 1);
557557
return (uint8_t)(msb + 1);
558558
#else
559559
uint8_t log2_size;

0 commit comments

Comments
 (0)