Skip to content

Commit b155414

Browse files
authored
gh-140868: Don't rely on undefined left shift behavior in assert (#140869)
Don't rely on undefined left shift behavior in assert
1 parent f701f98 commit b155414

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

Include/internal/pycore_stackref.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,8 @@ PyStackRef_IsTaggedInt(_PyStackRef i)
403403
static inline _PyStackRef
404404
PyStackRef_TagInt(intptr_t i)
405405
{
406-
assert(Py_ARITHMETIC_RIGHT_SHIFT(intptr_t, (i << Py_TAGGED_SHIFT), Py_TAGGED_SHIFT) == i);
406+
assert(Py_ARITHMETIC_RIGHT_SHIFT(intptr_t, (intptr_t)(((uintptr_t)i) << Py_TAGGED_SHIFT),
407+
Py_TAGGED_SHIFT) == i);
407408
return (_PyStackRef){ .bits = ((((uintptr_t)i) << Py_TAGGED_SHIFT) | Py_INT_TAG) };
408409
}
409410

0 commit comments

Comments
 (0)