[Python-checkins] cpython (2.7): promote some shifts to unsigned, so as not to invoke undefined behavior

benjamin.peterson python-checkins at python.org
Tue Sep 6 23:42:29 EDT 2016


https://hg.python.org/cpython/rev/923a27028cec
changeset:   103207:923a27028cec
branch:      2.7
parent:      103193:75dae0b2ccb3
user:        Benjamin Peterson <benjamin at python.org>
date:        Tue Sep 06 20:40:04 2016 -0700
summary:
  promote some shifts to unsigned, so as not to invoke undefined behavior

files:
  Objects/unicodeobject.c |  4 ++--
  1 files changed, 2 insertions(+), 2 deletions(-)


diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -2308,7 +2308,7 @@
        stream as-is (giving a ZWNBSP character). */
     if (bo == 0) {
         if (size >= 4) {
-            const Py_UCS4 bom = (q[iorder[3]] << 24) | (q[iorder[2]] << 16) |
+            const Py_UCS4 bom = ((unsigned int)q[iorder[3]] << 24) | (q[iorder[2]] << 16) |
                 (q[iorder[1]] << 8) | q[iorder[0]];
 #ifdef BYTEORDER_IS_LITTLE_ENDIAN
             if (bom == 0x0000FEFF) {
@@ -2378,7 +2378,7 @@
             /* The remaining input chars are ignored if the callback
                chooses to skip the input */
         }
-        ch = (q[iorder[3]] << 24) | (q[iorder[2]] << 16) |
+        ch = ((unsigned int)q[iorder[3]] << 24) | (q[iorder[2]] << 16) |
             (q[iorder[1]] << 8) | q[iorder[0]];
 
         if (ch >= 0x110000)

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


More information about the Python-checkins mailing list