Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 33d2a49

Browse files
committed
promote some shifts to unsigned, so as not to invoke undefined behavior
1 parent 4a75760 commit 33d2a49

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

Objects/unicodeobject.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4944,7 +4944,7 @@ PyUnicode_DecodeUTF32Stateful(const char *s,
49444944
mark is skipped, in all other modes, it is copied to the output
49454945
stream as-is (giving a ZWNBSP character). */
49464946
if (bo == 0 && size >= 4) {
4947-
Py_UCS4 bom = (q[3] << 24) | (q[2] << 16) | (q[1] << 8) | q[0];
4947+
Py_UCS4 bom = ((unsigned int)q[3] << 24) | (q[2] << 16) | (q[1] << 8) | q[0];
49484948
if (bom == 0x0000FEFF) {
49494949
bo = -1;
49504950
q += 4;
@@ -4986,7 +4986,7 @@ PyUnicode_DecodeUTF32Stateful(const char *s,
49864986
Py_ssize_t pos = writer.pos;
49874987
if (le) {
49884988
do {
4989-
ch = (q[3] << 24) | (q[2] << 16) | (q[1] << 8) | q[0];
4989+
ch = ((unsigned int)q[3] << 24) | (q[2] << 16) | (q[1] << 8) | q[0];
49904990
if (ch > maxch)
49914991
break;
49924992
if (kind != PyUnicode_1BYTE_KIND &&
@@ -4998,7 +4998,7 @@ PyUnicode_DecodeUTF32Stateful(const char *s,
49984998
}
49994999
else {
50005000
do {
5001-
ch = (q[0] << 24) | (q[1] << 16) | (q[2] << 8) | q[3];
5001+
ch = ((unsigned int)q[0] << 24) | (q[1] << 16) | (q[2] << 8) | q[3];
50025002
if (ch > maxch)
50035003
break;
50045004
if (kind != PyUnicode_1BYTE_KIND &&

0 commit comments

Comments
 (0)