Skip to content

Commit bdc4b02

Browse files
committed
cast negative numbers to size_t before shifting them (python#20929)
1 parent 21b391c commit bdc4b02

2 files changed

Lines changed: 3 additions & 1 deletion

File tree

Include/objimpl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ extern PyGC_Head *_PyGC_generation0;
265265
#define _PyGCHead_REFS(g) ((g)->gc.gc_refs >> _PyGC_REFS_SHIFT)
266266
#define _PyGCHead_SET_REFS(g, v) do { \
267267
(g)->gc.gc_refs = ((g)->gc.gc_refs & ~_PyGC_REFS_MASK) \
268-
| (v << _PyGC_REFS_SHIFT); \
268+
| (((size_t)(v)) << _PyGC_REFS_SHIFT); \
269269
} while (0)
270270
#define _PyGCHead_DECREF(g) ((g)->gc.gc_refs -= 1 << _PyGC_REFS_SHIFT)
271271

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ What's New in Python 3.4.1?
88
Core and Builtins
99
-----------------
1010

11+
- Issue #20929: Add a type cast to avoid shifting a negative number.
12+
1113
- Issue #20731: Properly position in source code files even if they
1214
are opened in text mode. Patch by Serhiy Storchaka.
1315

0 commit comments

Comments
 (0)