]> granicus.if.org Git - python/commitdiff
promote some shifts to unsigned, so as not to invoke undefined behavior
authorBenjamin Peterson <benjamin@python.org>
Wed, 7 Sep 2016 03:40:04 +0000 (20:40 -0700)
committerBenjamin Peterson <benjamin@python.org>
Wed, 7 Sep 2016 03:40:04 +0000 (20:40 -0700)
Objects/unicodeobject.c

index 151ce3c5584461ecdc37ba461fd45ba718e10568..ca609a96aee1924a805a9fa03b47dd9c8a9229d0 100644 (file)
@@ -2308,7 +2308,7 @@ PyUnicode_DecodeUTF32Stateful(const char *s,
        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 @@ PyUnicode_DecodeUTF32Stateful(const char *s,
             /* 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)