[Python-checkins] cpython: cast negative numbers to size_t before shifting them (#20929)

benjamin.peterson python-checkins at python.org
Sat Mar 15 02:15:37 CET 2014


http://hg.python.org/cpython/rev/e68f156ea0e6
changeset:   89657:e68f156ea0e6
user:        Benjamin Peterson <benjamin at python.org>
date:        Fri Mar 14 20:15:29 2014 -0500
summary:
  cast negative numbers to size_t before shifting them (#20929)

files:
  Include/objimpl.h |  2 +-
  Misc/NEWS         |  2 ++
  2 files changed, 3 insertions(+), 1 deletions(-)


diff --git a/Include/objimpl.h b/Include/objimpl.h
--- a/Include/objimpl.h
+++ b/Include/objimpl.h
@@ -265,7 +265,7 @@
 #define _PyGCHead_REFS(g) ((g)->gc.gc_refs >> _PyGC_REFS_SHIFT)
 #define _PyGCHead_SET_REFS(g, v) do { \
     (g)->gc.gc_refs = ((g)->gc.gc_refs & ~_PyGC_REFS_MASK) \
-        | (v << _PyGC_REFS_SHIFT); \
+        | (((size_t)(v)) << _PyGC_REFS_SHIFT);             \
     } while (0)
 #define _PyGCHead_DECREF(g) ((g)->gc.gc_refs -= 1 << _PyGC_REFS_SHIFT)
 
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -8,6 +8,8 @@
 Core and Builtins
 -----------------
 
+- Issue #20929: Add a type cast to avoid shifting a negative number.
+
 - Issue #20731: Properly position in source code files even if they
   are opened in text mode. Patch by Serhiy Storchaka.
 

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list